#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000500;
int G;
int a[maxn];
int t[4 * maxn];
int lz[4 * maxn];
void push(int x)
{
lz[x + x] += lz[x];
lz[x + x + 1] += lz[x];
t[x + x] += lz[x];
t[x + x + 1] += lz[x];
lz[x] = 0;
}
void upd(int x, int l, int r, int p, int val)
{
if(l == r){
t[x] += val;
return;
}
push(x);
int m = (l + r) / 2;
if(p <= m)upd(x + x, l, m, p, val);
else upd(x + x + 1, m + 1, r, p, val);
t[x] = max(t[x + x], t[x + x + 1]);
}
void upd(int x, int l, int r, int tl, int tr, int val)
{
if(tl > tr)return;
if(l == tl && r == tr){
t[x] += val;
lz[x] += val;
return;
}
int m = (l + r) / 2;
push(x);
upd(x + x, l, m, tl, min(tr, m), val);
upd(x + x + 1, m + 1, r, max(tl, m + 1), tr, val);
t[x] = max(t[x + x], t[x + x + 1]);
}
vector<int> countScans(vector<int> A,vector<int> X,vector<int> V){
int Q=X.size();
vector<int> answer;
int n = (int)A.size();
vector<pair<int, int>> g;
for(int i = 0; i < Q; i++){
g.push_back({V[i], -(i + 1)});
}
for(int i = 0; i < n; i++){
g.push_back({A[i], i});
}
map<int, int> m;
sort(g.begin(), g.end());
for(int i = 0; i < (int)g.size(); i++){
if(g[i].second >= 0){
A[g[i].second] = ++G;
}else{
V[-g[i].second - 1] = ++G;
}
}
for(int i = 0; i < n; i++){
upd(1, 1, G, A[i], G, -1);
upd(1, 1, G, A[i], i);
}
for(int i = 0; i < Q; i++){
upd(1, 1, G, A[X[i]], -X[i]);
upd(1, 1, G, A[X[i]], G, 1);
A[X[i]] = V[i];
upd(1, 1, G, A[X[i]], X[i]);
upd(1, 1, G, A[X[i]], G, -1);
answer.push_back(t[1] + 1);
}
return answer;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
460 KB |
Output is correct |
4 |
Correct |
5 ms |
460 KB |
Output is correct |
5 |
Correct |
5 ms |
492 KB |
Output is correct |
6 |
Correct |
4 ms |
460 KB |
Output is correct |
7 |
Correct |
4 ms |
444 KB |
Output is correct |
8 |
Correct |
4 ms |
460 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
4 ms |
460 KB |
Output is correct |
11 |
Correct |
4 ms |
460 KB |
Output is correct |
12 |
Correct |
5 ms |
460 KB |
Output is correct |
13 |
Correct |
4 ms |
460 KB |
Output is correct |
14 |
Correct |
4 ms |
532 KB |
Output is correct |
15 |
Correct |
4 ms |
532 KB |
Output is correct |
16 |
Correct |
4 ms |
460 KB |
Output is correct |
17 |
Correct |
4 ms |
460 KB |
Output is correct |
18 |
Correct |
4 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
460 KB |
Output is correct |
4 |
Correct |
5 ms |
460 KB |
Output is correct |
5 |
Correct |
5 ms |
492 KB |
Output is correct |
6 |
Correct |
4 ms |
460 KB |
Output is correct |
7 |
Correct |
4 ms |
444 KB |
Output is correct |
8 |
Correct |
4 ms |
460 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
4 ms |
460 KB |
Output is correct |
11 |
Correct |
4 ms |
460 KB |
Output is correct |
12 |
Correct |
5 ms |
460 KB |
Output is correct |
13 |
Correct |
4 ms |
460 KB |
Output is correct |
14 |
Correct |
4 ms |
532 KB |
Output is correct |
15 |
Correct |
4 ms |
532 KB |
Output is correct |
16 |
Correct |
4 ms |
460 KB |
Output is correct |
17 |
Correct |
4 ms |
460 KB |
Output is correct |
18 |
Correct |
4 ms |
460 KB |
Output is correct |
19 |
Correct |
16 ms |
1084 KB |
Output is correct |
20 |
Correct |
18 ms |
1216 KB |
Output is correct |
21 |
Correct |
18 ms |
1224 KB |
Output is correct |
22 |
Correct |
19 ms |
1224 KB |
Output is correct |
23 |
Correct |
17 ms |
1184 KB |
Output is correct |
24 |
Correct |
19 ms |
1100 KB |
Output is correct |
25 |
Correct |
17 ms |
1100 KB |
Output is correct |
26 |
Correct |
17 ms |
1100 KB |
Output is correct |
27 |
Correct |
17 ms |
1100 KB |
Output is correct |
28 |
Correct |
17 ms |
1088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
1464 KB |
Output is correct |
2 |
Incorrect |
73 ms |
3100 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
460 KB |
Output is correct |
4 |
Correct |
5 ms |
460 KB |
Output is correct |
5 |
Correct |
5 ms |
492 KB |
Output is correct |
6 |
Correct |
4 ms |
460 KB |
Output is correct |
7 |
Correct |
4 ms |
444 KB |
Output is correct |
8 |
Correct |
4 ms |
460 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
4 ms |
460 KB |
Output is correct |
11 |
Correct |
4 ms |
460 KB |
Output is correct |
12 |
Correct |
5 ms |
460 KB |
Output is correct |
13 |
Correct |
4 ms |
460 KB |
Output is correct |
14 |
Correct |
4 ms |
532 KB |
Output is correct |
15 |
Correct |
4 ms |
532 KB |
Output is correct |
16 |
Correct |
4 ms |
460 KB |
Output is correct |
17 |
Correct |
4 ms |
460 KB |
Output is correct |
18 |
Correct |
4 ms |
460 KB |
Output is correct |
19 |
Correct |
16 ms |
1084 KB |
Output is correct |
20 |
Correct |
18 ms |
1216 KB |
Output is correct |
21 |
Correct |
18 ms |
1224 KB |
Output is correct |
22 |
Correct |
19 ms |
1224 KB |
Output is correct |
23 |
Correct |
17 ms |
1184 KB |
Output is correct |
24 |
Correct |
19 ms |
1100 KB |
Output is correct |
25 |
Correct |
17 ms |
1100 KB |
Output is correct |
26 |
Correct |
17 ms |
1100 KB |
Output is correct |
27 |
Correct |
17 ms |
1100 KB |
Output is correct |
28 |
Correct |
17 ms |
1088 KB |
Output is correct |
29 |
Correct |
24 ms |
1464 KB |
Output is correct |
30 |
Incorrect |
73 ms |
3100 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |