# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
730494 |
2023-04-26T03:39:22 Z |
huutuan |
Izbori (COCI22_izbori) |
C++14 |
|
2588 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;
}
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
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 |
3 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
9 ms |
364 KB |
Output is correct |
10 |
Correct |
7 ms |
340 KB |
Output is correct |
11 |
Correct |
8 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
340 KB |
Output is correct |
13 |
Correct |
9 ms |
360 KB |
Output is correct |
14 |
Correct |
9 ms |
356 KB |
Output is correct |
15 |
Correct |
8 ms |
360 KB |
Output is correct |
16 |
Correct |
9 ms |
340 KB |
Output is correct |
17 |
Correct |
6 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
250 ms |
3676 KB |
Output is correct |
2 |
Correct |
301 ms |
3996 KB |
Output is correct |
3 |
Correct |
188 ms |
3404 KB |
Output is correct |
4 |
Correct |
417 ms |
4056 KB |
Output is correct |
5 |
Correct |
328 ms |
4112 KB |
Output is correct |
6 |
Correct |
359 ms |
4200 KB |
Output is correct |
7 |
Correct |
357 ms |
4196 KB |
Output is correct |
8 |
Correct |
342 ms |
4200 KB |
Output is correct |
9 |
Correct |
348 ms |
4172 KB |
Output is correct |
10 |
Correct |
345 ms |
4192 KB |
Output is correct |
11 |
Correct |
368 ms |
4192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
3 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
9 ms |
364 KB |
Output is correct |
10 |
Correct |
7 ms |
340 KB |
Output is correct |
11 |
Correct |
8 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
340 KB |
Output is correct |
13 |
Correct |
9 ms |
360 KB |
Output is correct |
14 |
Correct |
9 ms |
356 KB |
Output is correct |
15 |
Correct |
8 ms |
360 KB |
Output is correct |
16 |
Correct |
9 ms |
340 KB |
Output is correct |
17 |
Correct |
6 ms |
2644 KB |
Output is correct |
18 |
Correct |
250 ms |
3676 KB |
Output is correct |
19 |
Correct |
301 ms |
3996 KB |
Output is correct |
20 |
Correct |
188 ms |
3404 KB |
Output is correct |
21 |
Correct |
417 ms |
4056 KB |
Output is correct |
22 |
Correct |
328 ms |
4112 KB |
Output is correct |
23 |
Correct |
359 ms |
4200 KB |
Output is correct |
24 |
Correct |
357 ms |
4196 KB |
Output is correct |
25 |
Correct |
342 ms |
4200 KB |
Output is correct |
26 |
Correct |
348 ms |
4172 KB |
Output is correct |
27 |
Correct |
345 ms |
4192 KB |
Output is correct |
28 |
Correct |
368 ms |
4192 KB |
Output is correct |
29 |
Correct |
372 ms |
4196 KB |
Output is correct |
30 |
Correct |
230 ms |
820 KB |
Output is correct |
31 |
Correct |
492 ms |
1320 KB |
Output is correct |
32 |
Correct |
1222 ms |
2700 KB |
Output is correct |
33 |
Correct |
525 ms |
1492 KB |
Output is correct |
34 |
Correct |
535 ms |
1528 KB |
Output is correct |
35 |
Correct |
350 ms |
1108 KB |
Output is correct |
36 |
Correct |
212 ms |
852 KB |
Output is correct |
37 |
Correct |
245 ms |
852 KB |
Output is correct |
38 |
Correct |
374 ms |
4196 KB |
Output is correct |
39 |
Correct |
369 ms |
4192 KB |
Output is correct |
40 |
Correct |
366 ms |
4216 KB |
Output is correct |
41 |
Correct |
376 ms |
4196 KB |
Output is correct |
42 |
Correct |
356 ms |
4208 KB |
Output is correct |
43 |
Correct |
409 ms |
4192 KB |
Output is correct |
44 |
Correct |
399 ms |
4196 KB |
Output is correct |
45 |
Correct |
396 ms |
4196 KB |
Output is correct |
46 |
Correct |
393 ms |
4192 KB |
Output is correct |
47 |
Correct |
407 ms |
4236 KB |
Output is correct |
48 |
Correct |
1488 ms |
4300 KB |
Output is correct |
49 |
Correct |
1494 ms |
4192 KB |
Output is correct |
50 |
Correct |
795 ms |
4204 KB |
Output is correct |
51 |
Correct |
784 ms |
4196 KB |
Output is correct |
52 |
Correct |
2588 ms |
4172 KB |
Output is correct |
53 |
Correct |
2407 ms |
4192 KB |
Output is correct |
54 |
Correct |
1447 ms |
4200 KB |
Output is correct |