Submission #880599

# Submission time Handle Problem Language Result Execution time Memory
880599 2023-11-29T17:17:56 Z tsumondai Izbori (COCI22_izbori) C++14
10 / 110
229 ms 20052 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 N = 1e6 + 5, BLOCK_SIZE=450;
 
const int oo = 1e9, mod = 1e9 + 7;
 
int n, m, k, a[N], cnt[N], mp[N], s[N], t[N], ans=0;
vector<int> arr;

void update(int pos, int val){
    for (int i=pos; i<BLOCK_SIZE; 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> tmp_a(a+1, a+n+1);
    sort(tmp_a.begin(),tmp_a.end()); tmp_a.resize(unique(tmp_a.begin(),tmp_a.end())-tmp_a.begin());
    foru(i,1,n)  a[i]=lower_bound(tmp_a.begin(),tmp_a.end(), a[i])-tmp_a.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*BLOCK_SIZE; ++r){
            if (mp[a[r]]<=BLOCK_SIZE){
                ++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*BLOCK_SIZE; ++r){
            if (mp[a[r]]<=BLOCK_SIZE) --cnt[a[r]];
        }
    }
    foru(i,1,n) {
        if (mp[i]<=BLOCK_SIZE) 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;
    return;
}

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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 3 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 4 ms 4440 KB Output is correct
10 Correct 4 ms 4440 KB Output is correct
11 Correct 4 ms 4444 KB Output is correct
12 Correct 4 ms 4444 KB Output is correct
13 Correct 4 ms 4444 KB Output is correct
14 Correct 4 ms 4440 KB Output is correct
15 Correct 4 ms 4444 KB Output is correct
16 Correct 5 ms 4692 KB Output is correct
17 Incorrect 6 ms 18924 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 229 ms 20052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 3 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 4 ms 4440 KB Output is correct
10 Correct 4 ms 4440 KB Output is correct
11 Correct 4 ms 4444 KB Output is correct
12 Correct 4 ms 4444 KB Output is correct
13 Correct 4 ms 4444 KB Output is correct
14 Correct 4 ms 4440 KB Output is correct
15 Correct 4 ms 4444 KB Output is correct
16 Correct 5 ms 4692 KB Output is correct
17 Incorrect 6 ms 18924 KB Output isn't correct
18 Halted 0 ms 0 KB -