답안 #730495

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730495 2023-04-26T03:40:00 Z vjudge1 Izbori (COCI22_izbori) C++14
110 / 110
2548 ms 4300 KB
#include<bits/stdc++.h>

using namespace std;

// #define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define sumof(x) accumulate(all(x), 0ll)

const int S=450, N=2e5+1, M=N*2+10;
int n, a[N], s[N], t[M];
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 solve(){
    cin >> n;
    long long ans=0;
    for (int i=1; i<=n; ++i) cin >> a[i];
    vector<int> sus(a+1, a+n+1);
    sort(all(sus)); sus.resize(unique(all(sus))-sus.begin());
    for (int i=1; i<=n; ++i) a[i]=lower_bound(all(sus), a[i])-sus.begin()+1;
    for (int i=1; i<=n; ++i) ++mp[a[i]];
    for (int l=1; l<=n; ++l){
        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]];
        }
    }
    for (int i=1; i<=n; ++i){
        if (mp[i]<=S) continue;
        memset(s, 0, sizeof s);
        memset(t, 0, sizeof t);
        for (int j=1; j<=n; ++j) if (a[j]==i) ++s[j]; else --s[j];
        partial_sum(s, s+n+1, s);
        update(0+n+1, 1);
        for (int j=1; j<=n; ++j){
            ans+=get(s[j]-1+n+1);
            update(s[j]+n+1, 1);
        }
    }
    cout << ans;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int ntests=1;
    // cin >> ntests;
    while (ntests--) solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 9 ms 364 KB Output is correct
10 Correct 9 ms 360 KB Output is correct
11 Correct 9 ms 340 KB Output is correct
12 Correct 9 ms 340 KB Output is correct
13 Correct 9 ms 340 KB Output is correct
14 Correct 9 ms 360 KB Output is correct
15 Correct 9 ms 340 KB Output is correct
16 Correct 9 ms 356 KB Output is correct
17 Correct 4 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 225 ms 3676 KB Output is correct
2 Correct 302 ms 3916 KB Output is correct
3 Correct 168 ms 3424 KB Output is correct
4 Correct 320 ms 4056 KB Output is correct
5 Correct 315 ms 4044 KB Output is correct
6 Correct 342 ms 4212 KB Output is correct
7 Correct 344 ms 4204 KB Output is correct
8 Correct 349 ms 4208 KB Output is correct
9 Correct 348 ms 4192 KB Output is correct
10 Correct 353 ms 4208 KB Output is correct
11 Correct 355 ms 4200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 9 ms 364 KB Output is correct
10 Correct 9 ms 360 KB Output is correct
11 Correct 9 ms 340 KB Output is correct
12 Correct 9 ms 340 KB Output is correct
13 Correct 9 ms 340 KB Output is correct
14 Correct 9 ms 360 KB Output is correct
15 Correct 9 ms 340 KB Output is correct
16 Correct 9 ms 356 KB Output is correct
17 Correct 4 ms 2644 KB Output is correct
18 Correct 225 ms 3676 KB Output is correct
19 Correct 302 ms 3916 KB Output is correct
20 Correct 168 ms 3424 KB Output is correct
21 Correct 320 ms 4056 KB Output is correct
22 Correct 315 ms 4044 KB Output is correct
23 Correct 342 ms 4212 KB Output is correct
24 Correct 344 ms 4204 KB Output is correct
25 Correct 349 ms 4208 KB Output is correct
26 Correct 348 ms 4192 KB Output is correct
27 Correct 353 ms 4208 KB Output is correct
28 Correct 355 ms 4200 KB Output is correct
29 Correct 350 ms 4200 KB Output is correct
30 Correct 228 ms 904 KB Output is correct
31 Correct 469 ms 1364 KB Output is correct
32 Correct 1182 ms 2636 KB Output is correct
33 Correct 513 ms 1492 KB Output is correct
34 Correct 526 ms 1492 KB Output is correct
35 Correct 335 ms 1108 KB Output is correct
36 Correct 196 ms 852 KB Output is correct
37 Correct 240 ms 844 KB Output is correct
38 Correct 356 ms 4200 KB Output is correct
39 Correct 348 ms 4300 KB Output is correct
40 Correct 349 ms 4192 KB Output is correct
41 Correct 349 ms 4200 KB Output is correct
42 Correct 356 ms 4192 KB Output is correct
43 Correct 403 ms 4208 KB Output is correct
44 Correct 399 ms 4180 KB Output is correct
45 Correct 422 ms 4200 KB Output is correct
46 Correct 415 ms 4200 KB Output is correct
47 Correct 398 ms 4300 KB Output is correct
48 Correct 1472 ms 4196 KB Output is correct
49 Correct 1456 ms 4196 KB Output is correct
50 Correct 787 ms 4196 KB Output is correct
51 Correct 805 ms 4208 KB Output is correct
52 Correct 2548 ms 4200 KB Output is correct
53 Correct 2295 ms 4196 KB Output is correct
54 Correct 1452 ms 4300 KB Output is correct