# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
895778 |
2023-12-30T20:04:52 Z |
Isam |
Izbori (COCI22_izbori) |
C++17 |
|
3000 ms |
3160 KB |
#include<bits/stdc++.h>
using namespace std;
constexpr int sz = 200005;
int tree[sz << 2];
inline void update(int l, int r, int node, int x, int val){
if(l > x || r < x) return;
if(l == r){
tree[node] += val;
return;
}
int mid = l + ((r - l) >> 1);
update(l, mid, node << 1, x, val);
update(mid + 1, r, node << 1 | 1, x, val);
tree[node] = tree[node << 1] + tree[node << 1 | 1];
return;
}
int get_ans(int l, int r, int node, int L, int R){
if(l > R || r < L) return 0;
if(l >= L && r <= R) return tree[node];
int mid = l + ((r - l) >> 1);
return get_ans(l, mid, node << 1, L, R) + get_ans(mid + 1, r, node << 1 | 1, L, R);
}
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int N;
cin >> N;
vector<int> A(N);
bool it{false};
for(register int i = 0; i < N; ++i){
cin >> A[i];
it |= (A[i] > 2);
if(A[i] == 2) update(1, N, 1, i + 1, 1);
}
auto sol = [&](){
auto chk = [&](int l, int r){
map<int, int> mp;
for(register int i = l; i <= r; ++i) mp[A[i]]++;
int that(0);
for(auto &toto : mp) that = max(that, toto.second);
return (that << 1) > (r - l + 1);
};
int ans(0);
for(register int i = 0; i < N; ++i){
for(register int j = i; j < N; ++j){
ans += chk(i, j);
}
}
cout << ans << '\n';
exit(0);
};
int ans(0);
if(it) sol();
for(register int i = 0; i < N; ++i){
for(register int j = i; j < N; ++j){
int that = get_ans(1, N, 1, i + 1, j + 1);
that = max(that, (j - i + 1) - that);
ans += ((that << 1) > (j - i + 1));
}
}
cout << ans << '\n';
/*
2 2 1 2 3
2;
2;
1;
2;
3;
2 2;
2 2 1;
2 1 2;
2 2 1 2;
2 2 1 2 3;
*/
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:33:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
33 | for(register int i = 0; i < N; ++i){
| ^
Main.cpp: In lambda function:
Main.cpp:42:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
42 | for(register int i = l; i <= r; ++i) mp[A[i]]++;
| ^
Main.cpp: In lambda function:
Main.cpp:48:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
48 | for(register int i = 0; i < N; ++i){
| ^
Main.cpp:49:24: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
49 | for(register int j = i; j < N; ++j){
| ^
Main.cpp: In function 'int main()':
Main.cpp:60:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
60 | for(register int i = 0; i < N; ++i){
| ^
Main.cpp:61:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
61 | for(register int j = i; j < N; ++j){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
32 ms |
464 KB |
Output is correct |
4 |
Correct |
32 ms |
436 KB |
Output is correct |
5 |
Correct |
32 ms |
348 KB |
Output is correct |
6 |
Correct |
11 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
32 ms |
464 KB |
Output is correct |
4 |
Correct |
32 ms |
436 KB |
Output is correct |
5 |
Correct |
32 ms |
348 KB |
Output is correct |
6 |
Correct |
11 ms |
468 KB |
Output is correct |
7 |
Execution timed out |
3013 ms |
348 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3044 ms |
3160 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
32 ms |
464 KB |
Output is correct |
4 |
Correct |
32 ms |
436 KB |
Output is correct |
5 |
Correct |
32 ms |
348 KB |
Output is correct |
6 |
Correct |
11 ms |
468 KB |
Output is correct |
7 |
Execution timed out |
3013 ms |
348 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |