# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
545707 |
2022-04-05T08:47:40 Z |
mat50013 |
Izbori (COCI22_izbori) |
C++11 |
|
243 ms |
16148 KB |
#include <bits/stdc++.h>
using namespace std;
/// numar elem maj pe [st, dr], atunci e sigur macar in [st, mij], sau [mij + 1, dr]
const int NMAX(200005), ADD(200005);
using ll = long long;
map<int, int> mp;
int cnt, v[NMAX], viz[NMAX], fr[NMAX], nrSum[2 * NMAX];
ll rez;
inline void solve(int st, int dr){
if(st > dr)
return;
if(st == dr){
++rez;
return;
}
int mij = (st + dr) / 2;
solve(st, mij - 1), solve(mij + 1, dr);
for(int i = st; i <= dr; ++i)
viz[v[i]] = 0, fr[v[i]] = 0;
vector<int> haveCh;
for(int i = mij; i >= st; --i){
++fr[v[i]];
if(fr[v[i]] > (mij - i + 1) / 2 && !viz[v[i]]){
viz[v[i]] = 1;
haveCh.push_back(v[i]);
}
}
for(int i = st; i <= dr; ++i)
fr[v[i]] = 0;
for(int i = mij + 1; i <= dr; ++i){
++fr[v[i]];
if(fr[v[i]] > (i - mij) / 2 && !viz[v[i]]){
viz[v[i]] = 1;
haveCh.push_back(v[i]);
}
}
int lg = dr - st + 1;
for(auto it: haveCh){
for(int i = ADD - lg - 1; i <= ADD + lg + 1; ++i)
nrSum[i] = 0;
int sum = 0;
nrSum[0 + ADD] = 1;
for(int i = st; i < mij; ++i){
if(v[i] == it)
sum ++;
else sum--;
nrSum[sum + ADD]++;
}
for(int i = ADD - lg; i <= ADD + lg; ++i)
nrSum[i] += nrSum[i - 1];
for(int i = mij; i <= dr; ++i){
if(v[i] == it)
sum++;
else sum--;
rez += nrSum[sum + ADD - 1];
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
set<int> s;
for(int i = 1; i <= n; ++i){
cin >> v[i];
s.insert(v[i]);
}
for(auto it: s)
mp[it] = ++cnt;
for(int i = 1; i <= n; ++i)
v[i] = mp[v[i]];
solve(1, n);
cout << rez << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
2148 KB |
Output is correct |
2 |
Correct |
95 ms |
2676 KB |
Output is correct |
3 |
Correct |
57 ms |
1616 KB |
Output is correct |
4 |
Correct |
105 ms |
2740 KB |
Output is correct |
5 |
Correct |
101 ms |
2904 KB |
Output is correct |
6 |
Correct |
115 ms |
3052 KB |
Output is correct |
7 |
Correct |
119 ms |
3048 KB |
Output is correct |
8 |
Correct |
116 ms |
3052 KB |
Output is correct |
9 |
Correct |
104 ms |
2996 KB |
Output is correct |
10 |
Correct |
112 ms |
3056 KB |
Output is correct |
11 |
Correct |
70 ms |
3048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
67 ms |
2148 KB |
Output is correct |
19 |
Correct |
95 ms |
2676 KB |
Output is correct |
20 |
Correct |
57 ms |
1616 KB |
Output is correct |
21 |
Correct |
105 ms |
2740 KB |
Output is correct |
22 |
Correct |
101 ms |
2904 KB |
Output is correct |
23 |
Correct |
115 ms |
3052 KB |
Output is correct |
24 |
Correct |
119 ms |
3048 KB |
Output is correct |
25 |
Correct |
116 ms |
3052 KB |
Output is correct |
26 |
Correct |
104 ms |
2996 KB |
Output is correct |
27 |
Correct |
112 ms |
3056 KB |
Output is correct |
28 |
Correct |
70 ms |
3048 KB |
Output is correct |
29 |
Correct |
84 ms |
4648 KB |
Output is correct |
30 |
Correct |
40 ms |
4448 KB |
Output is correct |
31 |
Correct |
90 ms |
8092 KB |
Output is correct |
32 |
Correct |
243 ms |
16148 KB |
Output is correct |
33 |
Correct |
111 ms |
8532 KB |
Output is correct |
34 |
Correct |
92 ms |
8892 KB |
Output is correct |
35 |
Correct |
60 ms |
6224 KB |
Output is correct |
36 |
Correct |
34 ms |
4072 KB |
Output is correct |
37 |
Correct |
52 ms |
4756 KB |
Output is correct |
38 |
Correct |
116 ms |
3052 KB |
Output is correct |
39 |
Correct |
104 ms |
3032 KB |
Output is correct |
40 |
Correct |
106 ms |
3108 KB |
Output is correct |
41 |
Correct |
103 ms |
3020 KB |
Output is correct |
42 |
Correct |
113 ms |
3020 KB |
Output is correct |
43 |
Correct |
115 ms |
4564 KB |
Output is correct |
44 |
Correct |
115 ms |
4616 KB |
Output is correct |
45 |
Correct |
118 ms |
4636 KB |
Output is correct |
46 |
Correct |
129 ms |
4632 KB |
Output is correct |
47 |
Correct |
115 ms |
4628 KB |
Output is correct |
48 |
Correct |
110 ms |
3264 KB |
Output is correct |
49 |
Correct |
111 ms |
3292 KB |
Output is correct |
50 |
Correct |
119 ms |
3232 KB |
Output is correct |
51 |
Correct |
117 ms |
3144 KB |
Output is correct |
52 |
Correct |
111 ms |
3396 KB |
Output is correct |
53 |
Correct |
105 ms |
3424 KB |
Output is correct |
54 |
Correct |
109 ms |
3260 KB |
Output is correct |