#include <bits/stdc++.h>
using namespace std;
const int BASE = 1 << 20;
int TREE[BASE << 1];
int LAZY[BASE << 1];
int actsetindex[BASE];
map<int, int> mapa;
priority_queue<int> Q[BASE];
void push(int v, int l, int r){
TREE[l] += LAZY[v];
TREE[r] += LAZY[v];
LAZY[l] += LAZY[v];
LAZY[r] += LAZY[v];
LAZY[v] = 0;
}
void update(int v, int l, int r, int a, int b, int val){
if(r < a || b < l) return;
else if(a <= l && r <= b){
TREE[v] += val;
LAZY[v] += val;
}
else{
int mid = (l+r)/2;
push(v, 2*v, 2*v+1);
update(2*v, l, mid, a, b, val);
update(2*v+1, mid+1, r, a, b, val);
TREE[v] = max(TREE[2*v], TREE[2*v+1]);
}
}
void scale(){
int x = 0;
for(auto it = mapa.begin(); it != mapa.end(); ++it)
it->second = x++;
}
void repair(int val){
if(actsetindex[Q[val].top()] == val) return;
update(1, 0, BASE-1, val, val, -Q[val].top());
while(Q[val].size() && actsetindex[Q[val].top()] != val)
Q[val].pop();
if(Q[val].size())
update(1, 0, BASE-1, val, val, Q[val].top());
}
vector<int> countScans(vector <int> A, vector<int> X, vector<int> V){
for(auto u : A)
mapa[u];
for(auto u : V)
mapa[u];
scale();
for(int i = 0; i < (int)A.size(); i++)
A[i] = mapa[A[i]];
for(int i = 0; i < (int)V.size(); i++){
V[i] = mapa[V[i]];
X[i]++;
}
for(int i = 0; i < (int)A.size(); i++){
if(Q[A[i]].size())
update(1, 0, BASE-1, A[i], A[i], -Q[A[i]].top());
update(1, 0, BASE-1, A[i], A[i], i+1);
update(1, 0, BASE-1, A[i], BASE-1, -1);
actsetindex[i+1] = A[i];
Q[A[i]].push(i+1);
}
//cout << max(TREE[1], 0) << endl;
vector<int> res;
for(int i = 0; i < (int)V.size(); i++){
int idx = X[i];
int what = actsetindex[idx];
update(1, 0, BASE-1, what, BASE-1, 1);
repair(what);
if(Q[V[i]].size())
update(1, 0, BASE-1, V[i], V[i], -Q[V[i]].top());
Q[V[i]].push(idx);
update(1, 0, BASE-1, V[i], V[i], Q[V[i]].top());
update(1, 0, BASE-1, V[i], BASE-1, -1);
actsetindex[idx] = V[i];
res.push_back(max(TREE[1], 0));
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
43612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
43612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
44324 KB |
Output is correct |
2 |
Correct |
87 ms |
45280 KB |
Output is correct |
3 |
Incorrect |
135 ms |
48328 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
43612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |