답안 #880609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880609 2023-11-29T17:21:01 Z tsumondai Izbori (COCI22_izbori) C++14
110 / 110
2834 ms 8428 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME  (1.0 * clock() / CLOCKS_PER_SEC)

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int oo = 1e9, mod = 1e9 + 7;
 
const int S=450, N=2e5+1, M=N*2+10;

int n, a[N], s[N], t[M], ans=0;
int cnt[N], mp[N];
 
void update(int pos, int val){
    for (int i=pos; i<M; i+=i&(-i)) t[i]+=val;
}
 
int get(int pos){
    if (pos<0) return 0;
    int sum=0;
    for (int i=pos; i; i-=i&(-i)) sum+=t[i];
    return sum;
}
 
void process(){
    cin >> n;
    foru(i,1,n) cin >> a[i];
    vector<int> sus(a+1, a+n+1);
    sort(sus.begin(), sus.end()); sus.resize(unique(sus.begin(), sus.end())-sus.begin());
    foru(i,1,n) a[i]=lower_bound(sus.begin(), sus.end(), a[i])-sus.begin()+1;
    foru(i,1,n) ++mp[a[i]];
    foru(l,1,n) {
        int mx=0;
        for (int r=l; r<=n && r-l+1<=2*S; ++r){
            if (mp[a[r]]<=S){
                ++cnt[a[r]];
                mx=max(mx, cnt[a[r]]);
            }
            if (mx*2>r-l+1) ++ans;
        }
        for (int r=l; r<=n && r-l+1<=2*S; ++r){
            if (mp[a[r]]<=S) --cnt[a[r]];
        }
    }
    foru(i,1,n){
        if (mp[i]<=S) continue;
        memset(s, 0, sizeof s);
        memset(t, 0, sizeof t);
        foru(j,1,n) if (a[j]==i) ++s[j]; else --s[j];
        partial_sum(s, s+n+1, s);
        update(0+n+1, 1);
        foru(j,1,n){
            ans+=get(s[j]-1+n+1);
            update(s[j]+n+1, 1);
        }
    }
    cout << ans;
}

signed main() {
    cin.tie(0)->sync_with_stdio(false);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
    process();
    cerr << "Time elapsed: " << __TIME << " s.\n";
    return 0;
}

/*
Xét các trường hợp đặc biệt
Kiểm tra lại input/output
Cố gắng trâu
Lật ngược bài toán
Keep calm and get VOI 
Flow:

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 4 ms 2396 KB Output is correct
10 Correct 4 ms 2396 KB Output is correct
11 Correct 4 ms 2396 KB Output is correct
12 Correct 4 ms 2396 KB Output is correct
13 Correct 4 ms 2396 KB Output is correct
14 Correct 4 ms 2548 KB Output is correct
15 Correct 3 ms 2396 KB Output is correct
16 Correct 4 ms 2448 KB Output is correct
17 Correct 6 ms 5732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 278 ms 7100 KB Output is correct
2 Correct 368 ms 7744 KB Output is correct
3 Correct 209 ms 6612 KB Output is correct
4 Correct 394 ms 7868 KB Output is correct
5 Correct 389 ms 7976 KB Output is correct
6 Correct 423 ms 8144 KB Output is correct
7 Correct 414 ms 8272 KB Output is correct
8 Correct 415 ms 8160 KB Output is correct
9 Correct 420 ms 8276 KB Output is correct
10 Correct 415 ms 8164 KB Output is correct
11 Correct 422 ms 8148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 4 ms 2396 KB Output is correct
10 Correct 4 ms 2396 KB Output is correct
11 Correct 4 ms 2396 KB Output is correct
12 Correct 4 ms 2396 KB Output is correct
13 Correct 4 ms 2396 KB Output is correct
14 Correct 4 ms 2548 KB Output is correct
15 Correct 3 ms 2396 KB Output is correct
16 Correct 4 ms 2448 KB Output is correct
17 Correct 6 ms 5732 KB Output is correct
18 Correct 278 ms 7100 KB Output is correct
19 Correct 368 ms 7744 KB Output is correct
20 Correct 209 ms 6612 KB Output is correct
21 Correct 394 ms 7868 KB Output is correct
22 Correct 389 ms 7976 KB Output is correct
23 Correct 423 ms 8144 KB Output is correct
24 Correct 414 ms 8272 KB Output is correct
25 Correct 415 ms 8160 KB Output is correct
26 Correct 420 ms 8276 KB Output is correct
27 Correct 415 ms 8164 KB Output is correct
28 Correct 422 ms 8148 KB Output is correct
29 Correct 409 ms 8156 KB Output is correct
30 Correct 115 ms 5040 KB Output is correct
31 Correct 233 ms 5380 KB Output is correct
32 Correct 550 ms 7416 KB Output is correct
33 Correct 233 ms 5468 KB Output is correct
34 Correct 255 ms 5468 KB Output is correct
35 Correct 169 ms 5192 KB Output is correct
36 Correct 94 ms 5000 KB Output is correct
37 Correct 120 ms 4956 KB Output is correct
38 Correct 444 ms 8160 KB Output is correct
39 Correct 438 ms 8148 KB Output is correct
40 Correct 441 ms 8152 KB Output is correct
41 Correct 443 ms 8164 KB Output is correct
42 Correct 430 ms 8148 KB Output is correct
43 Correct 504 ms 8276 KB Output is correct
44 Correct 477 ms 8276 KB Output is correct
45 Correct 481 ms 8272 KB Output is correct
46 Correct 482 ms 8276 KB Output is correct
47 Correct 477 ms 8276 KB Output is correct
48 Correct 1664 ms 8408 KB Output is correct
49 Correct 1661 ms 8284 KB Output is correct
50 Correct 906 ms 8276 KB Output is correct
51 Correct 904 ms 8284 KB Output is correct
52 Correct 2834 ms 8428 KB Output is correct
53 Correct 2676 ms 8292 KB Output is correct
54 Correct 1751 ms 8284 KB Output is correct