#include <bits/stdc++.h>
#include "bubblesort2.h"
using namespace std;
#define ll long long
const int base = 1<<20;
const ll INF = 1e18+7;
const ll MAXN = 1e6+7;
ll tree[base<<1];
set<int> pozycje[MAXN];
ll lazy[base<<1];
int n;
void push(ll v){
lazy[2*v] += lazy[v];
lazy[2*v+1] += lazy[v];
tree[2*v] += lazy[v];
tree[2*v+1] += lazy[v];
lazy[v] = 0;
}
ll p, k;
ll val;
void update(ll v, ll l, ll r){
if(l > k || r < p) return;
if(p <= l && r <= k){
tree[v] += val;
lazy[v] += val;
}
else{
ll mid = (l+r)/2;
push(v);
update(2*v, l, mid);
update(2*v+1, mid+1, r);
tree[v] = max(tree[2*v], tree[2*v+1]);
}
}
ll query(ll v, ll l, ll r){
if(l > k || r < p) return -INF;
if(p <= l && r <= k){
return tree[v];
}
else{
ll mid = (l+r)/2;
push(v);
auto lQ = query(2*v, l, mid);
auto rQ = query(2*v+1, mid+1, r);
return max(lQ, rQ);
}
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
n = A.size();
int Q = X.size();
vector<int> res(Q);
map<long long, int> skalowanie;
for(auto i : A){
skalowanie[i] = 0;
}
for(auto i : V){
skalowanie[i] = 0;
}
int id = 0;
for(auto &i : skalowanie) i.second = ++id, pozycje[id].insert(-1);
for(ll i = 0; i < n; ++i){
auto vi = A[i];
pozycje[skalowanie[vi]].insert(i);
}
p = 0, k = id;
val = -INF;
update(1, 1, id);
for(int i = 0; i < n; ++i){
auto vi = A[i];
p = 0, k = skalowanie[vi]-1;
val = 1;
update(1, 1, id);
auto tmp = pozycje[skalowanie[vi]].end();
--tmp;
p = k = skalowanie[vi];
val = INF + *tmp;
update(1, 1, id);
}
for(int i = 0; i < Q; ++i){
p = 0, k = skalowanie[A[X[i]]]-1;
val = -1;
update(1, 1, id);
pozycje[skalowanie[A[X[i]]]].erase(X[i]);
auto tmp = pozycje[skalowanie[A[X[i]]]].end();
--tmp;
p = k = skalowanie[A[X[i]]];
if(X[i] > *tmp){
val = max(*tmp, 0) - X[i];
if(*tmp == -1) val -= INF;
}
update(1, 1, id);
A[X[i]] = V[i];
p = 0, k = skalowanie[A[X[i]]]-1;
val = 1;
update(1, 1, id);
tmp = pozycje[skalowanie[A[X[i]]]].end();
--tmp;
p = k = skalowanie[A[X[i]]];
if(X[i] > *tmp){
val = X[i] - max(*tmp, 0);
if(*tmp == -1) val += INF;
update(1, 1, id);
}
pozycje[skalowanie[A[X[i]]]].insert(X[i]);
p = 0, k = id;
res[i] = query(1, 1, id) - n + 1;
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
49348 KB |
Output is correct |
2 |
Correct |
27 ms |
49488 KB |
Output is correct |
3 |
Correct |
31 ms |
50004 KB |
Output is correct |
4 |
Correct |
29 ms |
49828 KB |
Output is correct |
5 |
Correct |
31 ms |
50000 KB |
Output is correct |
6 |
Correct |
30 ms |
50000 KB |
Output is correct |
7 |
Correct |
34 ms |
50012 KB |
Output is correct |
8 |
Correct |
35 ms |
50016 KB |
Output is correct |
9 |
Correct |
34 ms |
49992 KB |
Output is correct |
10 |
Correct |
32 ms |
50000 KB |
Output is correct |
11 |
Correct |
35 ms |
49748 KB |
Output is correct |
12 |
Correct |
34 ms |
49848 KB |
Output is correct |
13 |
Correct |
34 ms |
49864 KB |
Output is correct |
14 |
Correct |
35 ms |
49868 KB |
Output is correct |
15 |
Correct |
34 ms |
49736 KB |
Output is correct |
16 |
Correct |
33 ms |
49744 KB |
Output is correct |
17 |
Correct |
34 ms |
49744 KB |
Output is correct |
18 |
Correct |
39 ms |
49772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
49348 KB |
Output is correct |
2 |
Correct |
27 ms |
49488 KB |
Output is correct |
3 |
Correct |
31 ms |
50004 KB |
Output is correct |
4 |
Correct |
29 ms |
49828 KB |
Output is correct |
5 |
Correct |
31 ms |
50000 KB |
Output is correct |
6 |
Correct |
30 ms |
50000 KB |
Output is correct |
7 |
Correct |
34 ms |
50012 KB |
Output is correct |
8 |
Correct |
35 ms |
50016 KB |
Output is correct |
9 |
Correct |
34 ms |
49992 KB |
Output is correct |
10 |
Correct |
32 ms |
50000 KB |
Output is correct |
11 |
Correct |
35 ms |
49748 KB |
Output is correct |
12 |
Correct |
34 ms |
49848 KB |
Output is correct |
13 |
Correct |
34 ms |
49864 KB |
Output is correct |
14 |
Correct |
35 ms |
49868 KB |
Output is correct |
15 |
Correct |
34 ms |
49736 KB |
Output is correct |
16 |
Correct |
33 ms |
49744 KB |
Output is correct |
17 |
Correct |
34 ms |
49744 KB |
Output is correct |
18 |
Correct |
39 ms |
49772 KB |
Output is correct |
19 |
Correct |
60 ms |
51868 KB |
Output is correct |
20 |
Correct |
53 ms |
52296 KB |
Output is correct |
21 |
Correct |
50 ms |
52296 KB |
Output is correct |
22 |
Correct |
52 ms |
52348 KB |
Output is correct |
23 |
Correct |
51 ms |
52040 KB |
Output is correct |
24 |
Correct |
51 ms |
52048 KB |
Output is correct |
25 |
Correct |
57 ms |
51980 KB |
Output is correct |
26 |
Correct |
51 ms |
53844 KB |
Output is correct |
27 |
Correct |
52 ms |
51776 KB |
Output is correct |
28 |
Correct |
49 ms |
51732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
50 ms |
50844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
49348 KB |
Output is correct |
2 |
Correct |
27 ms |
49488 KB |
Output is correct |
3 |
Correct |
31 ms |
50004 KB |
Output is correct |
4 |
Correct |
29 ms |
49828 KB |
Output is correct |
5 |
Correct |
31 ms |
50000 KB |
Output is correct |
6 |
Correct |
30 ms |
50000 KB |
Output is correct |
7 |
Correct |
34 ms |
50012 KB |
Output is correct |
8 |
Correct |
35 ms |
50016 KB |
Output is correct |
9 |
Correct |
34 ms |
49992 KB |
Output is correct |
10 |
Correct |
32 ms |
50000 KB |
Output is correct |
11 |
Correct |
35 ms |
49748 KB |
Output is correct |
12 |
Correct |
34 ms |
49848 KB |
Output is correct |
13 |
Correct |
34 ms |
49864 KB |
Output is correct |
14 |
Correct |
35 ms |
49868 KB |
Output is correct |
15 |
Correct |
34 ms |
49736 KB |
Output is correct |
16 |
Correct |
33 ms |
49744 KB |
Output is correct |
17 |
Correct |
34 ms |
49744 KB |
Output is correct |
18 |
Correct |
39 ms |
49772 KB |
Output is correct |
19 |
Correct |
60 ms |
51868 KB |
Output is correct |
20 |
Correct |
53 ms |
52296 KB |
Output is correct |
21 |
Correct |
50 ms |
52296 KB |
Output is correct |
22 |
Correct |
52 ms |
52348 KB |
Output is correct |
23 |
Correct |
51 ms |
52040 KB |
Output is correct |
24 |
Correct |
51 ms |
52048 KB |
Output is correct |
25 |
Correct |
57 ms |
51980 KB |
Output is correct |
26 |
Correct |
51 ms |
53844 KB |
Output is correct |
27 |
Correct |
52 ms |
51776 KB |
Output is correct |
28 |
Correct |
49 ms |
51732 KB |
Output is correct |
29 |
Incorrect |
50 ms |
50844 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |