답안 #730489

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730489 2023-04-26T03:22:08 Z vjudge1 Izbori (COCI22_izbori) C++14
40 / 110
3000 ms 6988 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;
int n, a[N], s[N];
int cnt[N], mp[N];

struct Fenwick{
    int n; vector<int> t;

    Fenwick(int _n): n(_n), t(_n+1){}

    void update(int pos, int val){
        for (int i=pos; i<=n; 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);
        for (int j=1; j<=n; ++j) if (a[j]==i) ++s[j];
        partial_sum(s, s+n+1, s);
        Fenwick f(n*3+10);
        f.update(0+n+1, 1); 
        for (int j=1; j<=n; ++j){
            ans+=f.get(2*s[j]-j-1+n+1);
            f.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 1 ms 212 KB Output is correct
2 Correct 0 ms 284 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 284 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 9 ms 340 KB Output is correct
10 Correct 9 ms 352 KB Output is correct
11 Correct 9 ms 356 KB Output is correct
12 Correct 9 ms 336 KB Output is correct
13 Correct 10 ms 372 KB Output is correct
14 Correct 10 ms 376 KB Output is correct
15 Correct 10 ms 380 KB Output is correct
16 Correct 10 ms 340 KB Output is correct
17 Correct 4 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 235 ms 3928 KB Output is correct
2 Correct 368 ms 4868 KB Output is correct
3 Correct 178 ms 3232 KB Output is correct
4 Correct 380 ms 5024 KB Output is correct
5 Correct 324 ms 5124 KB Output is correct
6 Correct 395 ms 5352 KB Output is correct
7 Correct 358 ms 5356 KB Output is correct
8 Correct 376 ms 5364 KB Output is correct
9 Correct 351 ms 5352 KB Output is correct
10 Correct 398 ms 5348 KB Output is correct
11 Correct 356 ms 5452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 284 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 9 ms 340 KB Output is correct
10 Correct 9 ms 352 KB Output is correct
11 Correct 9 ms 356 KB Output is correct
12 Correct 9 ms 336 KB Output is correct
13 Correct 10 ms 372 KB Output is correct
14 Correct 10 ms 376 KB Output is correct
15 Correct 10 ms 380 KB Output is correct
16 Correct 10 ms 340 KB Output is correct
17 Correct 4 ms 1108 KB Output is correct
18 Correct 235 ms 3928 KB Output is correct
19 Correct 368 ms 4868 KB Output is correct
20 Correct 178 ms 3232 KB Output is correct
21 Correct 380 ms 5024 KB Output is correct
22 Correct 324 ms 5124 KB Output is correct
23 Correct 395 ms 5352 KB Output is correct
24 Correct 358 ms 5356 KB Output is correct
25 Correct 376 ms 5364 KB Output is correct
26 Correct 351 ms 5352 KB Output is correct
27 Correct 398 ms 5348 KB Output is correct
28 Correct 356 ms 5452 KB Output is correct
29 Correct 373 ms 6920 KB Output is correct
30 Correct 232 ms 1044 KB Output is correct
31 Correct 500 ms 1916 KB Output is correct
32 Correct 1190 ms 3896 KB Output is correct
33 Correct 520 ms 2000 KB Output is correct
34 Correct 551 ms 2004 KB Output is correct
35 Correct 355 ms 1492 KB Output is correct
36 Correct 217 ms 980 KB Output is correct
37 Correct 243 ms 1164 KB Output is correct
38 Correct 402 ms 5356 KB Output is correct
39 Correct 377 ms 5348 KB Output is correct
40 Correct 392 ms 5356 KB Output is correct
41 Correct 394 ms 5352 KB Output is correct
42 Correct 385 ms 5352 KB Output is correct
43 Correct 449 ms 6936 KB Output is correct
44 Correct 470 ms 6988 KB Output is correct
45 Correct 449 ms 6936 KB Output is correct
46 Correct 441 ms 6940 KB Output is correct
47 Correct 468 ms 6936 KB Output is correct
48 Correct 1879 ms 5644 KB Output is correct
49 Correct 1897 ms 5652 KB Output is correct
50 Correct 961 ms 5524 KB Output is correct
51 Correct 982 ms 5528 KB Output is correct
52 Execution timed out 3054 ms 5696 KB Time limit exceeded
53 Halted 0 ms 0 KB -