/*
IN THE NAME OF GOD
*/
#include <bits/stdc++.h>
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;
#define F first
#define S second
#define Mp make_pair
#define pb push_back
#define pf push_front
#define size(x) ((ll)x.size())
#define all(x) (x).begin(),(x).end()
#define kill(x) cout << x << '\n', exit(0);
#define fuck(x) cout << "(" << #x << " , " << x << ")" << endl
#define endl '\n'
const int N = 1e6+2e5+23, lg = 20;
ll Mod = 1e9+7; //998244353;
inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
ll ans = 1;
a=MOD(a, mod);
while (b) {
if (b & 1) ans = MOD(ans*a, mod);
b >>= 1;
a = MOD(a*a, mod);
}
return ans;
}
int n, q, a[N], seg[3*N], lazy[3*N];
set<int> st[N];
vector<int> comp;
int get(int x) {
int ptr = lower_bound(all(comp), x) - comp.begin() + 1;
return ptr;
}
inline void pushdown(int ind) {
seg[ind] += lazy[ind];
(ind<(1<<lg)) && (lazy[2*ind] += lazy[ind]);
(ind<(1<<lg)) && (lazy[2*ind+1] += lazy[ind]);
lazy[ind] = 0;
}
void update(int l, int r, int y, int ind=1, int lc=1, int rc=(1<<lg)+1) {
pushdown(ind);
if(l>=rc || lc>=r) return;
if(lc>=l && rc<=r) {
lazy[ind] += y;
pushdown(ind);
return;
}
int mid = (lc+rc)/2;
update(l, r, y, 2*ind, lc, mid);
update(l, r, y, 2*ind+1, mid, rc);
seg[ind] = max(seg[2*ind], seg[2*ind+1]);
}
void update2(int pos, int y, int ind=1, int lc=1, int rc=(1<<lg)+1) {
pushdown(ind);
if(ind>=(1<<lg)) {
seg[ind] = y;
return;
}
int mid = (lc+rc)/2;
if(pos<mid) update2(pos, y, 2*ind, lc, mid);
else update2(pos, y, 2*ind+1, mid, rc);
pushdown(2*ind);
pushdown(2*ind+1);
seg[ind] = max(seg[2*ind], seg[2*ind+1]);
}
int fen[N];
void ufen(int x, int val) {
while(x < N) {
fen[x] += val; x += (x&(-x));
}
}
int qfen(int pos) {
int res = 0;
while(pos > 0) {
res += fen[pos]; pos -= (pos&(-pos));
}
return res;
}
int query(int x, int ind=1, int lc=1, int rc=(1<<lg)+1) {
pushdown(ind);
if(ind >= (1<<lg)) return seg[ind];
int mid = (lc+rc)/2;
if(x < mid) return query(x, 2*ind, lc, mid);
return query(x, 2*ind+1, mid, rc);
}
vector<int> countScans (vector<int> A, vector<int> X, vector<int> V) {
n=size(A), q=size(X);
for(int i=1; i<=n; i++) comp.pb(A[i-1]);
for(int i=1; i<=q; i++) comp.pb(V[i-1]), X[i-1]++;
sort(all(comp));
comp.resize(unique(all(comp)) - comp.begin());
for(int i=1; i<=n; i++) a[i] = get(A[i-1]), ufen(a[i], 1);
for(int i=1; i<=q; i++) V[i-1] = get(V[i-1]);
vector<int> ans;
for(int i=1; i<=n+q; i++) st[i].insert(0), update2(i, -n-q);
for(int i=1; i<=n; i++) {
update2(a[i], max(i-qfen(a[i]), query(a[i])));
st[a[i]].insert(i);
}
for(int x,v,i=1; i<=q; i++) {
x=X[i-1], v=V[i-1];
st[a[x]].erase(x);
update(a[x], n+q+1, 1);
st[v].insert(x);
update(v, n+q+1, -1);
ufen(a[x], -1); ufen(v, 1);
update2(a[x], (*st[a[x]].rbegin())-qfen(a[x]));
a[x] = v;
update2(a[x], (*st[a[x]].rbegin())-qfen(a[x]));
ans.pb(seg[1]);
}
return ans;
}
/*
int main() {
vector<int> ans = countScans({1, 2, 3, 4}, {0, 2}, {3, 1});
for(auto it : ans) cout<<it<<endl;
return 0;
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
74328 KB |
Output is correct |
2 |
Correct |
19 ms |
74328 KB |
Output is correct |
3 |
Correct |
23 ms |
74732 KB |
Output is correct |
4 |
Correct |
24 ms |
74576 KB |
Output is correct |
5 |
Correct |
22 ms |
74584 KB |
Output is correct |
6 |
Correct |
22 ms |
74588 KB |
Output is correct |
7 |
Correct |
24 ms |
75044 KB |
Output is correct |
8 |
Correct |
23 ms |
74584 KB |
Output is correct |
9 |
Correct |
23 ms |
74584 KB |
Output is correct |
10 |
Correct |
22 ms |
74588 KB |
Output is correct |
11 |
Correct |
23 ms |
74588 KB |
Output is correct |
12 |
Correct |
23 ms |
74584 KB |
Output is correct |
13 |
Correct |
22 ms |
74584 KB |
Output is correct |
14 |
Correct |
23 ms |
74576 KB |
Output is correct |
15 |
Correct |
26 ms |
74548 KB |
Output is correct |
16 |
Correct |
24 ms |
74840 KB |
Output is correct |
17 |
Correct |
23 ms |
74588 KB |
Output is correct |
18 |
Correct |
23 ms |
74584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
74328 KB |
Output is correct |
2 |
Correct |
19 ms |
74328 KB |
Output is correct |
3 |
Correct |
23 ms |
74732 KB |
Output is correct |
4 |
Correct |
24 ms |
74576 KB |
Output is correct |
5 |
Correct |
22 ms |
74584 KB |
Output is correct |
6 |
Correct |
22 ms |
74588 KB |
Output is correct |
7 |
Correct |
24 ms |
75044 KB |
Output is correct |
8 |
Correct |
23 ms |
74584 KB |
Output is correct |
9 |
Correct |
23 ms |
74584 KB |
Output is correct |
10 |
Correct |
22 ms |
74588 KB |
Output is correct |
11 |
Correct |
23 ms |
74588 KB |
Output is correct |
12 |
Correct |
23 ms |
74584 KB |
Output is correct |
13 |
Correct |
22 ms |
74584 KB |
Output is correct |
14 |
Correct |
23 ms |
74576 KB |
Output is correct |
15 |
Correct |
26 ms |
74548 KB |
Output is correct |
16 |
Correct |
24 ms |
74840 KB |
Output is correct |
17 |
Correct |
23 ms |
74588 KB |
Output is correct |
18 |
Correct |
23 ms |
74584 KB |
Output is correct |
19 |
Correct |
37 ms |
75840 KB |
Output is correct |
20 |
Correct |
40 ms |
75864 KB |
Output is correct |
21 |
Correct |
39 ms |
75864 KB |
Output is correct |
22 |
Correct |
38 ms |
75856 KB |
Output is correct |
23 |
Correct |
37 ms |
75864 KB |
Output is correct |
24 |
Correct |
38 ms |
75856 KB |
Output is correct |
25 |
Correct |
43 ms |
75896 KB |
Output is correct |
26 |
Correct |
38 ms |
75856 KB |
Output is correct |
27 |
Correct |
45 ms |
76112 KB |
Output is correct |
28 |
Correct |
37 ms |
75864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
77392 KB |
Output is correct |
2 |
Correct |
99 ms |
80580 KB |
Output is correct |
3 |
Correct |
158 ms |
83400 KB |
Output is correct |
4 |
Correct |
159 ms |
83900 KB |
Output is correct |
5 |
Correct |
158 ms |
83892 KB |
Output is correct |
6 |
Correct |
153 ms |
83912 KB |
Output is correct |
7 |
Correct |
160 ms |
83972 KB |
Output is correct |
8 |
Correct |
154 ms |
83764 KB |
Output is correct |
9 |
Correct |
154 ms |
83784 KB |
Output is correct |
10 |
Correct |
149 ms |
84048 KB |
Output is correct |
11 |
Correct |
148 ms |
83912 KB |
Output is correct |
12 |
Correct |
150 ms |
83972 KB |
Output is correct |
13 |
Correct |
150 ms |
83912 KB |
Output is correct |
14 |
Correct |
157 ms |
83972 KB |
Output is correct |
15 |
Correct |
155 ms |
83832 KB |
Output is correct |
16 |
Correct |
149 ms |
84172 KB |
Output is correct |
17 |
Correct |
145 ms |
83796 KB |
Output is correct |
18 |
Correct |
145 ms |
83788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
74328 KB |
Output is correct |
2 |
Correct |
19 ms |
74328 KB |
Output is correct |
3 |
Correct |
23 ms |
74732 KB |
Output is correct |
4 |
Correct |
24 ms |
74576 KB |
Output is correct |
5 |
Correct |
22 ms |
74584 KB |
Output is correct |
6 |
Correct |
22 ms |
74588 KB |
Output is correct |
7 |
Correct |
24 ms |
75044 KB |
Output is correct |
8 |
Correct |
23 ms |
74584 KB |
Output is correct |
9 |
Correct |
23 ms |
74584 KB |
Output is correct |
10 |
Correct |
22 ms |
74588 KB |
Output is correct |
11 |
Correct |
23 ms |
74588 KB |
Output is correct |
12 |
Correct |
23 ms |
74584 KB |
Output is correct |
13 |
Correct |
22 ms |
74584 KB |
Output is correct |
14 |
Correct |
23 ms |
74576 KB |
Output is correct |
15 |
Correct |
26 ms |
74548 KB |
Output is correct |
16 |
Correct |
24 ms |
74840 KB |
Output is correct |
17 |
Correct |
23 ms |
74588 KB |
Output is correct |
18 |
Correct |
23 ms |
74584 KB |
Output is correct |
19 |
Correct |
37 ms |
75840 KB |
Output is correct |
20 |
Correct |
40 ms |
75864 KB |
Output is correct |
21 |
Correct |
39 ms |
75864 KB |
Output is correct |
22 |
Correct |
38 ms |
75856 KB |
Output is correct |
23 |
Correct |
37 ms |
75864 KB |
Output is correct |
24 |
Correct |
38 ms |
75856 KB |
Output is correct |
25 |
Correct |
43 ms |
75896 KB |
Output is correct |
26 |
Correct |
38 ms |
75856 KB |
Output is correct |
27 |
Correct |
45 ms |
76112 KB |
Output is correct |
28 |
Correct |
37 ms |
75864 KB |
Output is correct |
29 |
Correct |
43 ms |
77392 KB |
Output is correct |
30 |
Correct |
99 ms |
80580 KB |
Output is correct |
31 |
Correct |
158 ms |
83400 KB |
Output is correct |
32 |
Correct |
159 ms |
83900 KB |
Output is correct |
33 |
Correct |
158 ms |
83892 KB |
Output is correct |
34 |
Correct |
153 ms |
83912 KB |
Output is correct |
35 |
Correct |
160 ms |
83972 KB |
Output is correct |
36 |
Correct |
154 ms |
83764 KB |
Output is correct |
37 |
Correct |
154 ms |
83784 KB |
Output is correct |
38 |
Correct |
149 ms |
84048 KB |
Output is correct |
39 |
Correct |
148 ms |
83912 KB |
Output is correct |
40 |
Correct |
150 ms |
83972 KB |
Output is correct |
41 |
Correct |
150 ms |
83912 KB |
Output is correct |
42 |
Correct |
157 ms |
83972 KB |
Output is correct |
43 |
Correct |
155 ms |
83832 KB |
Output is correct |
44 |
Correct |
149 ms |
84172 KB |
Output is correct |
45 |
Correct |
145 ms |
83796 KB |
Output is correct |
46 |
Correct |
145 ms |
83788 KB |
Output is correct |
47 |
Correct |
779 ms |
109856 KB |
Output is correct |
48 |
Correct |
3022 ms |
177852 KB |
Output is correct |
49 |
Correct |
3051 ms |
187720 KB |
Output is correct |
50 |
Correct |
3191 ms |
187932 KB |
Output is correct |
51 |
Correct |
3165 ms |
187844 KB |
Output is correct |
52 |
Correct |
3043 ms |
187724 KB |
Output is correct |
53 |
Correct |
3088 ms |
187928 KB |
Output is correct |
54 |
Correct |
2739 ms |
188008 KB |
Output is correct |
55 |
Correct |
2966 ms |
187912 KB |
Output is correct |
56 |
Correct |
2646 ms |
187888 KB |
Output is correct |
57 |
Correct |
2833 ms |
188284 KB |
Output is correct |
58 |
Correct |
2684 ms |
188044 KB |
Output is correct |
59 |
Correct |
2363 ms |
186808 KB |
Output is correct |
60 |
Correct |
2386 ms |
186544 KB |
Output is correct |
61 |
Correct |
2378 ms |
186480 KB |
Output is correct |
62 |
Correct |
2194 ms |
186348 KB |
Output is correct |
63 |
Correct |
2210 ms |
186268 KB |
Output is correct |
64 |
Correct |
2185 ms |
186428 KB |
Output is correct |
65 |
Correct |
2068 ms |
186148 KB |
Output is correct |
66 |
Correct |
2040 ms |
186156 KB |
Output is correct |
67 |
Correct |
2065 ms |
186308 KB |
Output is correct |