#pragma GCC optimize ("Ofast")
#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 8000;
int n, seg[N*4];
pair<int, int> b[N];
void update(int x, int p=1, int l=0, int r=n-1) {
if (l == r) {
seg[p] = 1;
return;
}
int mid = (l+r) >> 1;
if (x <= mid) update(x, p*2, l, mid);
else update(x, p*2+1, mid+1, r);
seg[p] = seg[p*2] + seg[p*2+1];
}
int query(int L, int R, int p=1, int l=0, int r=n-1) {
if (L <= l && r <= R) {
return seg[p];
}
int mid = (l+r) >> 1;
int x = 0;
if (L <= mid) x += query(L, R, p*2, l, mid);
if (mid+1 <= R) x += query(L, R, p*2+1, mid+1, r);
return x;
}
int solve(vector<int> a) {
memset(seg, 0, sizeof(seg));
for (int i = 0; i < n; i++) {
b[i] = make_pair(a[i], i);
}
sort(b, b+n);
int mx = 0;
int R = n-1;
for (int i = n-1; i >= 0; i--) {
int idx = b[i].second;
update(b[i].second);
if (idx+1 <= n-1 && query(idx+1, n-1) != n-1 - idx) continue;
int x = (idx ? query(0, idx-1) : 0);
while (R >= 0 && a[R] >= a[idx]) R--;
if (idx < R) x += query(idx+1, R);
//cerr << i << " " << x << endl;
mx = max(mx, x);
}
return mx;
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
n = A.size();
int q = X.size();
vector<int> ans(q);
for (int j = 0; j < q; j++) {
A[X[j]] = V[j];
ans[j] = solve(A);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
348 KB |
Output is correct |
2 |
Correct |
53 ms |
576 KB |
Output is correct |
3 |
Correct |
542 ms |
624 KB |
Output is correct |
4 |
Correct |
534 ms |
636 KB |
Output is correct |
5 |
Correct |
522 ms |
624 KB |
Output is correct |
6 |
Correct |
540 ms |
600 KB |
Output is correct |
7 |
Correct |
597 ms |
604 KB |
Output is correct |
8 |
Correct |
577 ms |
600 KB |
Output is correct |
9 |
Correct |
529 ms |
600 KB |
Output is correct |
10 |
Correct |
455 ms |
620 KB |
Output is correct |
11 |
Correct |
498 ms |
600 KB |
Output is correct |
12 |
Correct |
486 ms |
624 KB |
Output is correct |
13 |
Correct |
479 ms |
620 KB |
Output is correct |
14 |
Correct |
491 ms |
600 KB |
Output is correct |
15 |
Correct |
475 ms |
616 KB |
Output is correct |
16 |
Correct |
482 ms |
604 KB |
Output is correct |
17 |
Correct |
491 ms |
628 KB |
Output is correct |
18 |
Correct |
463 ms |
620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
348 KB |
Output is correct |
2 |
Correct |
53 ms |
576 KB |
Output is correct |
3 |
Correct |
542 ms |
624 KB |
Output is correct |
4 |
Correct |
534 ms |
636 KB |
Output is correct |
5 |
Correct |
522 ms |
624 KB |
Output is correct |
6 |
Correct |
540 ms |
600 KB |
Output is correct |
7 |
Correct |
597 ms |
604 KB |
Output is correct |
8 |
Correct |
577 ms |
600 KB |
Output is correct |
9 |
Correct |
529 ms |
600 KB |
Output is correct |
10 |
Correct |
455 ms |
620 KB |
Output is correct |
11 |
Correct |
498 ms |
600 KB |
Output is correct |
12 |
Correct |
486 ms |
624 KB |
Output is correct |
13 |
Correct |
479 ms |
620 KB |
Output is correct |
14 |
Correct |
491 ms |
600 KB |
Output is correct |
15 |
Correct |
475 ms |
616 KB |
Output is correct |
16 |
Correct |
482 ms |
604 KB |
Output is correct |
17 |
Correct |
491 ms |
628 KB |
Output is correct |
18 |
Correct |
463 ms |
620 KB |
Output is correct |
19 |
Correct |
7987 ms |
848 KB |
Output is correct |
20 |
Execution timed out |
9042 ms |
856 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
1624 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
348 KB |
Output is correct |
2 |
Correct |
53 ms |
576 KB |
Output is correct |
3 |
Correct |
542 ms |
624 KB |
Output is correct |
4 |
Correct |
534 ms |
636 KB |
Output is correct |
5 |
Correct |
522 ms |
624 KB |
Output is correct |
6 |
Correct |
540 ms |
600 KB |
Output is correct |
7 |
Correct |
597 ms |
604 KB |
Output is correct |
8 |
Correct |
577 ms |
600 KB |
Output is correct |
9 |
Correct |
529 ms |
600 KB |
Output is correct |
10 |
Correct |
455 ms |
620 KB |
Output is correct |
11 |
Correct |
498 ms |
600 KB |
Output is correct |
12 |
Correct |
486 ms |
624 KB |
Output is correct |
13 |
Correct |
479 ms |
620 KB |
Output is correct |
14 |
Correct |
491 ms |
600 KB |
Output is correct |
15 |
Correct |
475 ms |
616 KB |
Output is correct |
16 |
Correct |
482 ms |
604 KB |
Output is correct |
17 |
Correct |
491 ms |
628 KB |
Output is correct |
18 |
Correct |
463 ms |
620 KB |
Output is correct |
19 |
Correct |
7987 ms |
848 KB |
Output is correct |
20 |
Execution timed out |
9042 ms |
856 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |