#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);
}
for(int i = 0; i <= id; ++i){
if(pozycje[i].size() > 1){
auto tmp = pozycje[i].end();
--tmp;
p = k = i;
val = INF + *tmp;
update(1, 1, id);
}
}
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);
}
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 |
25 ms |
49488 KB |
Output is correct |
2 |
Correct |
28 ms |
49580 KB |
Output is correct |
3 |
Correct |
31 ms |
49992 KB |
Output is correct |
4 |
Correct |
31 ms |
50000 KB |
Output is correct |
5 |
Correct |
29 ms |
50000 KB |
Output is correct |
6 |
Correct |
29 ms |
50004 KB |
Output is correct |
7 |
Correct |
32 ms |
49840 KB |
Output is correct |
8 |
Correct |
32 ms |
50000 KB |
Output is correct |
9 |
Correct |
35 ms |
50000 KB |
Output is correct |
10 |
Correct |
32 ms |
49744 KB |
Output is correct |
11 |
Correct |
31 ms |
49744 KB |
Output is correct |
12 |
Correct |
32 ms |
49756 KB |
Output is correct |
13 |
Correct |
33 ms |
49744 KB |
Output is correct |
14 |
Correct |
31 ms |
49736 KB |
Output is correct |
15 |
Correct |
30 ms |
49744 KB |
Output is correct |
16 |
Correct |
30 ms |
49744 KB |
Output is correct |
17 |
Correct |
31 ms |
49744 KB |
Output is correct |
18 |
Correct |
30 ms |
49860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
49488 KB |
Output is correct |
2 |
Correct |
28 ms |
49580 KB |
Output is correct |
3 |
Correct |
31 ms |
49992 KB |
Output is correct |
4 |
Correct |
31 ms |
50000 KB |
Output is correct |
5 |
Correct |
29 ms |
50000 KB |
Output is correct |
6 |
Correct |
29 ms |
50004 KB |
Output is correct |
7 |
Correct |
32 ms |
49840 KB |
Output is correct |
8 |
Correct |
32 ms |
50000 KB |
Output is correct |
9 |
Correct |
35 ms |
50000 KB |
Output is correct |
10 |
Correct |
32 ms |
49744 KB |
Output is correct |
11 |
Correct |
31 ms |
49744 KB |
Output is correct |
12 |
Correct |
32 ms |
49756 KB |
Output is correct |
13 |
Correct |
33 ms |
49744 KB |
Output is correct |
14 |
Correct |
31 ms |
49736 KB |
Output is correct |
15 |
Correct |
30 ms |
49744 KB |
Output is correct |
16 |
Correct |
30 ms |
49744 KB |
Output is correct |
17 |
Correct |
31 ms |
49744 KB |
Output is correct |
18 |
Correct |
30 ms |
49860 KB |
Output is correct |
19 |
Correct |
47 ms |
51744 KB |
Output is correct |
20 |
Correct |
48 ms |
52048 KB |
Output is correct |
21 |
Correct |
48 ms |
52140 KB |
Output is correct |
22 |
Correct |
50 ms |
52040 KB |
Output is correct |
23 |
Correct |
49 ms |
51804 KB |
Output is correct |
24 |
Correct |
55 ms |
51804 KB |
Output is correct |
25 |
Correct |
50 ms |
51788 KB |
Output is correct |
26 |
Correct |
54 ms |
51784 KB |
Output is correct |
27 |
Correct |
54 ms |
51528 KB |
Output is correct |
28 |
Correct |
49 ms |
51708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
50672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
49488 KB |
Output is correct |
2 |
Correct |
28 ms |
49580 KB |
Output is correct |
3 |
Correct |
31 ms |
49992 KB |
Output is correct |
4 |
Correct |
31 ms |
50000 KB |
Output is correct |
5 |
Correct |
29 ms |
50000 KB |
Output is correct |
6 |
Correct |
29 ms |
50004 KB |
Output is correct |
7 |
Correct |
32 ms |
49840 KB |
Output is correct |
8 |
Correct |
32 ms |
50000 KB |
Output is correct |
9 |
Correct |
35 ms |
50000 KB |
Output is correct |
10 |
Correct |
32 ms |
49744 KB |
Output is correct |
11 |
Correct |
31 ms |
49744 KB |
Output is correct |
12 |
Correct |
32 ms |
49756 KB |
Output is correct |
13 |
Correct |
33 ms |
49744 KB |
Output is correct |
14 |
Correct |
31 ms |
49736 KB |
Output is correct |
15 |
Correct |
30 ms |
49744 KB |
Output is correct |
16 |
Correct |
30 ms |
49744 KB |
Output is correct |
17 |
Correct |
31 ms |
49744 KB |
Output is correct |
18 |
Correct |
30 ms |
49860 KB |
Output is correct |
19 |
Correct |
47 ms |
51744 KB |
Output is correct |
20 |
Correct |
48 ms |
52048 KB |
Output is correct |
21 |
Correct |
48 ms |
52140 KB |
Output is correct |
22 |
Correct |
50 ms |
52040 KB |
Output is correct |
23 |
Correct |
49 ms |
51804 KB |
Output is correct |
24 |
Correct |
55 ms |
51804 KB |
Output is correct |
25 |
Correct |
50 ms |
51788 KB |
Output is correct |
26 |
Correct |
54 ms |
51784 KB |
Output is correct |
27 |
Correct |
54 ms |
51528 KB |
Output is correct |
28 |
Correct |
49 ms |
51708 KB |
Output is correct |
29 |
Incorrect |
43 ms |
50672 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |