SDUT 2021 summer team contest 11th

https://vjudge.net/contest/454997#problem/B

B

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>
using namespace std;
#define int long long
typedef long long ll;
int n;
const int N = 5e3 + 7;
int a[N];
int dp[N][N];
signed main() {
scanf("%lld",&n);
for ( int i = 1; i <= n; i ++) scanf("%lld", a + i);
sort(a + 1,a + 1 + n);
int ans = 0;
for (int i = 2; i < n; i ++ ) {
for (int j = 1 ; j < i;j ++ ) {
int po = lower_bound(a + 1,a + 1 + n,2*a[i] - a[j]) - a;
if (a[po] + a[j] == 2*a[i])
dp[po][i] = max(dp[i][j] + 1,dp[po][i]);
}
}
for (int i = 1; i <= n; i ++ )
for (int j = 1; j <= n; j ++ ) ans = max(ans, dp[i][j]);
cout << ans + 2 << endl;
}

D 待补

G

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>
using namespace std;
#define int long long
typedef long long ll;
int n;
const int N = 1e5 + 7;
int tr[N],a[N],tr2[N];
ll L[N],R[N],R2[N],L2[N];
ll ask(int x) {
ll ans = 0;
for (; x ;x -= x &-x) ans += tr[x];
return ans;
}
void add(int x,int v) {
for (; x <= N; x += x &-x) tr[x] += v;
}
signed main() {
int maxc = 0,minc = 0x3f3f3f3f;
cin >> n;for (int i = 1; i <= n ; i ++ ) {
int x;
scanf("%lld", &x);
a[i] = x;
maxc = max(maxc,x);
minc = min(minc,x);
}
for (int i = n ; i >= 1 ;i -- ) {
int x = a[i];
ll res = ask(x - 1);
R[i] = res;
R2[i] = max(0ll,ask(100000) - ask(x));
add(x,1);
}
memset(tr,0,sizeof tr);
for (int i = 1; i <= n; i ++ ) {
int x = a[i];
ll res = ask(x - 1);
L[i] = res;
L2[i] = max(ask(100000) - ask(x),0ll);
add(x,1);
}
int mincc = 0x3f3f3f3f, sum= 0;
int ans = 0;
for (int i = 1; i <= n; i ++ ) {
//cout << a[i] << ' ' << L2[i] << ' ' << R2[i] << endl;
ans += min(L2[i],R2[i]);
}
cout << ans << endl;
}