#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];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, ans = 0;
cin >> n;
for(int i = 0; i < n; i++){
cin >> arr[i];
b[i] = arr[i];
}
sort(b, b + n);
int sz = unique(b, b + n) - b;
for(int i = 0; i < n; i++){
arr[i] = lower_bound(b, b + sz, arr[i]) - b;
}
segtree obj;
obj.init(sz);
for(ll i = 0; i < n; i++){
for(int j = i; j < n; j++){
obj.upd(arr[j], 1);
//cout << obj.tree[0] << " "<< j - i + 1 << endl;
if(obj.tree[0] > (j - i + 1) / 2) ans++;
}
for(int j = i; j < n; j++){
obj.upd(arr[j], -1);
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
372 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
372 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
22 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
28 ms |
348 KB |
Output is correct |
10 |
Correct |
29 ms |
344 KB |
Output is correct |
11 |
Correct |
27 ms |
344 KB |
Output is correct |
12 |
Correct |
34 ms |
476 KB |
Output is correct |
13 |
Correct |
27 ms |
344 KB |
Output is correct |
14 |
Correct |
26 ms |
500 KB |
Output is correct |
15 |
Correct |
27 ms |
344 KB |
Output is correct |
16 |
Correct |
27 ms |
472 KB |
Output is correct |
17 |
Correct |
7 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3058 ms |
1372 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
372 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
22 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
28 ms |
348 KB |
Output is correct |
10 |
Correct |
29 ms |
344 KB |
Output is correct |
11 |
Correct |
27 ms |
344 KB |
Output is correct |
12 |
Correct |
34 ms |
476 KB |
Output is correct |
13 |
Correct |
27 ms |
344 KB |
Output is correct |
14 |
Correct |
26 ms |
500 KB |
Output is correct |
15 |
Correct |
27 ms |
344 KB |
Output is correct |
16 |
Correct |
27 ms |
472 KB |
Output is correct |
17 |
Correct |
7 ms |
348 KB |
Output is correct |
18 |
Execution timed out |
3058 ms |
1372 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |