답안 #730492

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730492 2023-04-26T03:30:47 Z vjudge1 Izbori (COCI22_izbori) C++14
40 / 110
3000 ms 5068 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*3+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];
        partial_sum(s, s+n+1, s);
        update(0+n+1, 1); 
        for (int j=1; j<=n; ++j){
            ans+=get(2*s[j]-j-1+n+1);
            update(2*s[j]-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 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 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 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 9 ms 356 KB Output is correct
10 Correct 9 ms 360 KB Output is correct
11 Correct 9 ms 468 KB Output is correct
12 Correct 9 ms 340 KB Output is correct
13 Correct 9 ms 356 KB Output is correct
14 Correct 9 ms 340 KB Output is correct
15 Correct 9 ms 356 KB Output is correct
16 Correct 8 ms 340 KB Output is correct
17 Correct 4 ms 3416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 273 ms 4432 KB Output is correct
2 Correct 321 ms 4756 KB Output is correct
3 Correct 225 ms 4188 KB Output is correct
4 Correct 319 ms 4940 KB Output is correct
5 Correct 349 ms 4872 KB Output is correct
6 Correct 358 ms 4956 KB Output is correct
7 Correct 370 ms 4956 KB Output is correct
8 Correct 350 ms 4960 KB Output is correct
9 Correct 376 ms 4964 KB Output is correct
10 Correct 349 ms 4956 KB Output is correct
11 Correct 349 ms 4968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 9 ms 356 KB Output is correct
10 Correct 9 ms 360 KB Output is correct
11 Correct 9 ms 468 KB Output is correct
12 Correct 9 ms 340 KB Output is correct
13 Correct 9 ms 356 KB Output is correct
14 Correct 9 ms 340 KB Output is correct
15 Correct 9 ms 356 KB Output is correct
16 Correct 8 ms 340 KB Output is correct
17 Correct 4 ms 3416 KB Output is correct
18 Correct 273 ms 4432 KB Output is correct
19 Correct 321 ms 4756 KB Output is correct
20 Correct 225 ms 4188 KB Output is correct
21 Correct 319 ms 4940 KB Output is correct
22 Correct 349 ms 4872 KB Output is correct
23 Correct 358 ms 4956 KB Output is correct
24 Correct 370 ms 4956 KB Output is correct
25 Correct 350 ms 4960 KB Output is correct
26 Correct 376 ms 4964 KB Output is correct
27 Correct 349 ms 4956 KB Output is correct
28 Correct 349 ms 4968 KB Output is correct
29 Correct 354 ms 4960 KB Output is correct
30 Correct 242 ms 852 KB Output is correct
31 Correct 479 ms 1356 KB Output is correct
32 Correct 1220 ms 2636 KB Output is correct
33 Correct 506 ms 1492 KB Output is correct
34 Correct 541 ms 1516 KB Output is correct
35 Correct 372 ms 1108 KB Output is correct
36 Correct 199 ms 724 KB Output is correct
37 Correct 241 ms 916 KB Output is correct
38 Correct 405 ms 4940 KB Output is correct
39 Correct 400 ms 4952 KB Output is correct
40 Correct 375 ms 4952 KB Output is correct
41 Correct 417 ms 4952 KB Output is correct
42 Correct 376 ms 4956 KB Output is correct
43 Correct 475 ms 4956 KB Output is correct
44 Correct 449 ms 4956 KB Output is correct
45 Correct 445 ms 4968 KB Output is correct
46 Correct 455 ms 4960 KB Output is correct
47 Correct 435 ms 4952 KB Output is correct
48 Correct 1808 ms 4960 KB Output is correct
49 Correct 1827 ms 4940 KB Output is correct
50 Correct 965 ms 5068 KB Output is correct
51 Correct 950 ms 4960 KB Output is correct
52 Execution timed out 3070 ms 4960 KB Time limit exceeded
53 Halted 0 ms 0 KB -