//#include "bubblesort2.h"
#include <bits/stdc++.h>
#define pb emplace_back
#define get_pos(u,x) (lower_bound(begin(u),end(u),x) - begin(u))
using namespace std;
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
int n = A.size(), q = X.size();
//vector<tuple<int,int,int>> evt;
/*for(int i = 0; i < n; i++)
evt.pb(i, i, A[i]);
for(int i = 0; i < q; i++)
evt.pb(i+n, X[i]-1, V[i]);
CDQ(evt);*/
vector<int> u;
for(int i = 0; i < n; i++) u.pb(A[i]);
for(int i = 0; i < q; i++) u.pb(V[i]);
sort(u.begin(), u.end());
u.erase(unique(u.begin(), u.end()), u.end());
for(int i = 0; i < n; i++) A[i] = get_pos(u, A[i]) + 1;
for(int i = 0; i < q; i++) V[i] = get_pos(u, V[i]) + 1;
vector<int> cnt(u.size()+1);
auto modify = [&](int p, int d) {
for(; p < int(cnt.size()); p += p&-p) cnt[p] += d;
};
auto query = [&](int p) {
int res = 0;
for(; p; p -= p&-p) res += cnt[p];
return res;
};
vector<int> Q;
for(int i = 0; i < q; i++) {
A[X[i]] = V[i];
int ans = 0;
//cout << "A: "; for(int x: A) cout << x << ' '; cout << '\n';
for(int i = 0; i < int(cnt.size()); i++) cnt[i] = 0;
for(int i = 0; i < n; i++) {
//for(int i = 1; i < int(cnt.size()); i++) cout << query(i)-query(i-1) << ' '; cout << '\n';
ans = max(ans, i - query(A[i]));
modify(A[i], 1);
}
Q.pb(ans);
}
return Q;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
376 KB |
Output is correct |
2 |
Correct |
23 ms |
376 KB |
Output is correct |
3 |
Correct |
110 ms |
504 KB |
Output is correct |
4 |
Correct |
110 ms |
492 KB |
Output is correct |
5 |
Correct |
109 ms |
504 KB |
Output is correct |
6 |
Correct |
106 ms |
504 KB |
Output is correct |
7 |
Correct |
108 ms |
380 KB |
Output is correct |
8 |
Correct |
108 ms |
504 KB |
Output is correct |
9 |
Correct |
109 ms |
504 KB |
Output is correct |
10 |
Correct |
102 ms |
504 KB |
Output is correct |
11 |
Correct |
104 ms |
504 KB |
Output is correct |
12 |
Correct |
106 ms |
488 KB |
Output is correct |
13 |
Correct |
103 ms |
504 KB |
Output is correct |
14 |
Correct |
104 ms |
504 KB |
Output is correct |
15 |
Correct |
103 ms |
504 KB |
Output is correct |
16 |
Correct |
102 ms |
504 KB |
Output is correct |
17 |
Correct |
104 ms |
504 KB |
Output is correct |
18 |
Correct |
104 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
376 KB |
Output is correct |
2 |
Correct |
23 ms |
376 KB |
Output is correct |
3 |
Correct |
110 ms |
504 KB |
Output is correct |
4 |
Correct |
110 ms |
492 KB |
Output is correct |
5 |
Correct |
109 ms |
504 KB |
Output is correct |
6 |
Correct |
106 ms |
504 KB |
Output is correct |
7 |
Correct |
108 ms |
380 KB |
Output is correct |
8 |
Correct |
108 ms |
504 KB |
Output is correct |
9 |
Correct |
109 ms |
504 KB |
Output is correct |
10 |
Correct |
102 ms |
504 KB |
Output is correct |
11 |
Correct |
104 ms |
504 KB |
Output is correct |
12 |
Correct |
106 ms |
488 KB |
Output is correct |
13 |
Correct |
103 ms |
504 KB |
Output is correct |
14 |
Correct |
104 ms |
504 KB |
Output is correct |
15 |
Correct |
103 ms |
504 KB |
Output is correct |
16 |
Correct |
102 ms |
504 KB |
Output is correct |
17 |
Correct |
104 ms |
504 KB |
Output is correct |
18 |
Correct |
104 ms |
504 KB |
Output is correct |
19 |
Correct |
1464 ms |
888 KB |
Output is correct |
20 |
Correct |
1866 ms |
888 KB |
Output is correct |
21 |
Correct |
1851 ms |
932 KB |
Output is correct |
22 |
Correct |
1838 ms |
888 KB |
Output is correct |
23 |
Correct |
1745 ms |
864 KB |
Output is correct |
24 |
Correct |
1736 ms |
888 KB |
Output is correct |
25 |
Correct |
1725 ms |
888 KB |
Output is correct |
26 |
Correct |
1721 ms |
888 KB |
Output is correct |
27 |
Correct |
1723 ms |
888 KB |
Output is correct |
28 |
Correct |
1726 ms |
888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1102 ms |
760 KB |
Output is correct |
2 |
Execution timed out |
9082 ms |
1784 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
376 KB |
Output is correct |
2 |
Correct |
23 ms |
376 KB |
Output is correct |
3 |
Correct |
110 ms |
504 KB |
Output is correct |
4 |
Correct |
110 ms |
492 KB |
Output is correct |
5 |
Correct |
109 ms |
504 KB |
Output is correct |
6 |
Correct |
106 ms |
504 KB |
Output is correct |
7 |
Correct |
108 ms |
380 KB |
Output is correct |
8 |
Correct |
108 ms |
504 KB |
Output is correct |
9 |
Correct |
109 ms |
504 KB |
Output is correct |
10 |
Correct |
102 ms |
504 KB |
Output is correct |
11 |
Correct |
104 ms |
504 KB |
Output is correct |
12 |
Correct |
106 ms |
488 KB |
Output is correct |
13 |
Correct |
103 ms |
504 KB |
Output is correct |
14 |
Correct |
104 ms |
504 KB |
Output is correct |
15 |
Correct |
103 ms |
504 KB |
Output is correct |
16 |
Correct |
102 ms |
504 KB |
Output is correct |
17 |
Correct |
104 ms |
504 KB |
Output is correct |
18 |
Correct |
104 ms |
504 KB |
Output is correct |
19 |
Correct |
1464 ms |
888 KB |
Output is correct |
20 |
Correct |
1866 ms |
888 KB |
Output is correct |
21 |
Correct |
1851 ms |
932 KB |
Output is correct |
22 |
Correct |
1838 ms |
888 KB |
Output is correct |
23 |
Correct |
1745 ms |
864 KB |
Output is correct |
24 |
Correct |
1736 ms |
888 KB |
Output is correct |
25 |
Correct |
1725 ms |
888 KB |
Output is correct |
26 |
Correct |
1721 ms |
888 KB |
Output is correct |
27 |
Correct |
1723 ms |
888 KB |
Output is correct |
28 |
Correct |
1726 ms |
888 KB |
Output is correct |
29 |
Correct |
1102 ms |
760 KB |
Output is correct |
30 |
Execution timed out |
9082 ms |
1784 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |