#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;
const int N = 500025;
struct Segtree {
int mx[N<<1], lz[N];
void init() {
for(int i = 0; i < N; i++) mx[i+N] = lz[i] = 0;
for(int i = N-1; i > 0; i--) mx[i] = max(mx[i<<1],mx[i<<1|1]);
}
void upd(int p, int d) {
mx[p] += d;
if(p < N) lz[p] += d;
}
void pull(int p) {
for(; p>1; p>>=1) mx[p>>1] = max(mx[p],mx[p^1]) + lz[p>>1];
}
void push(int p) {
for(int h = __lg(N); h >= 0; h--) {
int i = p>>h;
if(!lz[i>>1]) continue;
upd(i,lz[i>>1]);
upd(i^1,lz[i>>1]);
lz[i>>1] = 0;
}
}
void add(int l, int r, int d) {
int L = l, R = r;
for(l+=N,r+=N; l<r; l>>=1,r>>=1) {
if(l&1) upd(l++, d);
if(r&1) upd(--r, d);
}
pull(L+N), pull(R-1+N);
}
int query(int l, int r) {
int res = 0;
push(l+N), push(r-1+N);
for(l+=N,r+=N; l<r; l>>=1,r>>=1) {
if(l&1) res = max(res, mx[l++]);
if(r&1) res = max(res, mx[--r]);
}
return res;
}
} sgt;
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
int n = A.size(), q = X.size();
/*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<set<int>> idx(u.size()+1);
vector<int> Q;
sgt.init();
auto del = [&](int p, int x) {
sgt.add(x,x+1,-(*idx[x].rbegin()));
idx[x].erase(p);
sgt.add(x,x+1,idx[x].empty() ? 0 : (*idx[x].rbegin()));
sgt.add(x+1,N,1);
};
auto add = [&](int p, int x) {
sgt.add(x,x+1,idx[x].empty() ? 0 : -(*idx[x].rbegin()));
idx[x].insert(p);
sgt.add(x,x+1,(*idx[x].rbegin()));
sgt.add(x+1,N,-1);
};
for(int i = 0; i < n; i++) add(i, A[i]);
for(int i = 0; i < q; i++) {
// i - #j : v_j < v_i
del(X[i], A[X[i]]);
A[X[i]] = V[i];
add(X[i], A[X[i]]);
//for(int i = 0; i <= u.size(); i++) sgt.push(i+N), cout << sgt.mx[i+N] << ' ';cout<<'\n';
Q.pb(sgt.query(0,N));
}
return Q;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
6264 KB |
Output is correct |
2 |
Correct |
10 ms |
6392 KB |
Output is correct |
3 |
Correct |
13 ms |
6520 KB |
Output is correct |
4 |
Correct |
13 ms |
6520 KB |
Output is correct |
5 |
Correct |
13 ms |
6648 KB |
Output is correct |
6 |
Correct |
13 ms |
6520 KB |
Output is correct |
7 |
Correct |
12 ms |
6648 KB |
Output is correct |
8 |
Correct |
13 ms |
6648 KB |
Output is correct |
9 |
Correct |
13 ms |
6520 KB |
Output is correct |
10 |
Correct |
13 ms |
6520 KB |
Output is correct |
11 |
Correct |
13 ms |
6520 KB |
Output is correct |
12 |
Correct |
13 ms |
6520 KB |
Output is correct |
13 |
Correct |
13 ms |
6520 KB |
Output is correct |
14 |
Correct |
12 ms |
6520 KB |
Output is correct |
15 |
Correct |
12 ms |
6520 KB |
Output is correct |
16 |
Correct |
13 ms |
6520 KB |
Output is correct |
17 |
Correct |
12 ms |
6520 KB |
Output is correct |
18 |
Correct |
13 ms |
6520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
6264 KB |
Output is correct |
2 |
Correct |
10 ms |
6392 KB |
Output is correct |
3 |
Correct |
13 ms |
6520 KB |
Output is correct |
4 |
Correct |
13 ms |
6520 KB |
Output is correct |
5 |
Correct |
13 ms |
6648 KB |
Output is correct |
6 |
Correct |
13 ms |
6520 KB |
Output is correct |
7 |
Correct |
12 ms |
6648 KB |
Output is correct |
8 |
Correct |
13 ms |
6648 KB |
Output is correct |
9 |
Correct |
13 ms |
6520 KB |
Output is correct |
10 |
Correct |
13 ms |
6520 KB |
Output is correct |
11 |
Correct |
13 ms |
6520 KB |
Output is correct |
12 |
Correct |
13 ms |
6520 KB |
Output is correct |
13 |
Correct |
13 ms |
6520 KB |
Output is correct |
14 |
Correct |
12 ms |
6520 KB |
Output is correct |
15 |
Correct |
12 ms |
6520 KB |
Output is correct |
16 |
Correct |
13 ms |
6520 KB |
Output is correct |
17 |
Correct |
12 ms |
6520 KB |
Output is correct |
18 |
Correct |
13 ms |
6520 KB |
Output is correct |
19 |
Correct |
25 ms |
7672 KB |
Output is correct |
20 |
Correct |
28 ms |
7800 KB |
Output is correct |
21 |
Correct |
26 ms |
7800 KB |
Output is correct |
22 |
Correct |
27 ms |
7800 KB |
Output is correct |
23 |
Correct |
26 ms |
7672 KB |
Output is correct |
24 |
Correct |
26 ms |
7672 KB |
Output is correct |
25 |
Correct |
27 ms |
7672 KB |
Output is correct |
26 |
Correct |
27 ms |
7672 KB |
Output is correct |
27 |
Correct |
25 ms |
7544 KB |
Output is correct |
28 |
Correct |
25 ms |
7544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
7932 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
6264 KB |
Output is correct |
2 |
Correct |
10 ms |
6392 KB |
Output is correct |
3 |
Correct |
13 ms |
6520 KB |
Output is correct |
4 |
Correct |
13 ms |
6520 KB |
Output is correct |
5 |
Correct |
13 ms |
6648 KB |
Output is correct |
6 |
Correct |
13 ms |
6520 KB |
Output is correct |
7 |
Correct |
12 ms |
6648 KB |
Output is correct |
8 |
Correct |
13 ms |
6648 KB |
Output is correct |
9 |
Correct |
13 ms |
6520 KB |
Output is correct |
10 |
Correct |
13 ms |
6520 KB |
Output is correct |
11 |
Correct |
13 ms |
6520 KB |
Output is correct |
12 |
Correct |
13 ms |
6520 KB |
Output is correct |
13 |
Correct |
13 ms |
6520 KB |
Output is correct |
14 |
Correct |
12 ms |
6520 KB |
Output is correct |
15 |
Correct |
12 ms |
6520 KB |
Output is correct |
16 |
Correct |
13 ms |
6520 KB |
Output is correct |
17 |
Correct |
12 ms |
6520 KB |
Output is correct |
18 |
Correct |
13 ms |
6520 KB |
Output is correct |
19 |
Correct |
25 ms |
7672 KB |
Output is correct |
20 |
Correct |
28 ms |
7800 KB |
Output is correct |
21 |
Correct |
26 ms |
7800 KB |
Output is correct |
22 |
Correct |
27 ms |
7800 KB |
Output is correct |
23 |
Correct |
26 ms |
7672 KB |
Output is correct |
24 |
Correct |
26 ms |
7672 KB |
Output is correct |
25 |
Correct |
27 ms |
7672 KB |
Output is correct |
26 |
Correct |
27 ms |
7672 KB |
Output is correct |
27 |
Correct |
25 ms |
7544 KB |
Output is correct |
28 |
Correct |
25 ms |
7544 KB |
Output is correct |
29 |
Incorrect |
30 ms |
7932 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |