# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
893531 |
2023-12-27T06:26:58 Z |
vjudge1 |
Izbori (COCI22_izbori) |
C++17 |
|
33 ms |
1372 KB |
#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 2 * 1e5 + 10;
const ll mod = 1e9 + 7;
ll um(ll a, ll b){
return ((1LL * a * b) % mod + mod) % mod;
}
ll subr(ll a, ll b){
return ((1LL * a - b) % mod + mod) % mod;
}
ll binpow(ll x, ll step){
ll res = 1LL;
while(step){
if(step & 1) res = um(res, x);
x = um(x, x);
step /= 2;
}
return res;
}
struct segtree {
int sz;
vector <int> tree;
void init(int n){
sz = 1;
while(sz < n) sz *= 2;
tree.assign(2 * sz - 1, 0);
}
void upd(int i, int v, int x, int lx, int rx){
if(rx - lx == 1){
tree[x] += v;
return;
}
int mid = (rx + lx) / 2;
if(i < mid) upd(i, v, 2 * x + 1, lx, mid);
else upd(i, v, 2 * x + 2, mid, rx);
tree[x] = max(tree[2 * x + 1], tree[2 * x + 2]);
}
void upd(int i, int v){
upd(i, v, 0, 0, sz);
}
};
int arr[N], b[N], sz, n;
ll ans;
void overall(){
segtree obj;
obj.init(sz);
for(ll i = 0; i < n; i++){
for(int j = i; j < n; j++){
obj.upd(arr[j], 1);
if(obj.tree[0] > (j - i + 1) / 2) ans++;
}
for(int j = i; j < n; j++){
obj.upd(arr[j], -1);
}
}
}
void subtask3(){
map <int, int> mp;
int cur = 0, act = 0;
ans = (n * (n + 1)) / 2;
for(int i = 0; i < n; i++){
if(arr[i] == 0) cur--;
else cur++;
mp[cur]++;
}
cur = 0;
for(int i = 0; i < n; i++){
//cout << act << " "<< mp[act] << endl;
ans -= mp[act];
if(arr[i] == 0){
cur--;
act--;
}
else{
cur++;
act++;
}
mp[cur]--;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 0; i < n; i++){
cin >> arr[i];
b[i] = arr[i];
}
sort(b, b + n);
sz = unique(b, b + n) - b;
for(int i = 0; i < n; i++){
arr[i] = lower_bound(b, b + sz, arr[i]) - b;
}
if(sz == 2){
subtask3();
} else{
overall();
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
22 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
33 ms |
504 KB |
Output is correct |
10 |
Correct |
30 ms |
344 KB |
Output is correct |
11 |
Correct |
30 ms |
348 KB |
Output is correct |
12 |
Correct |
29 ms |
508 KB |
Output is correct |
13 |
Correct |
30 ms |
348 KB |
Output is correct |
14 |
Correct |
30 ms |
348 KB |
Output is correct |
15 |
Correct |
29 ms |
348 KB |
Output is correct |
16 |
Correct |
30 ms |
604 KB |
Output is correct |
17 |
Correct |
7 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
1372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
22 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
33 ms |
504 KB |
Output is correct |
10 |
Correct |
30 ms |
344 KB |
Output is correct |
11 |
Correct |
30 ms |
348 KB |
Output is correct |
12 |
Correct |
29 ms |
508 KB |
Output is correct |
13 |
Correct |
30 ms |
348 KB |
Output is correct |
14 |
Correct |
30 ms |
348 KB |
Output is correct |
15 |
Correct |
29 ms |
348 KB |
Output is correct |
16 |
Correct |
30 ms |
604 KB |
Output is correct |
17 |
Correct |
7 ms |
344 KB |
Output is correct |
18 |
Incorrect |
15 ms |
1372 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |