#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;
typedef long long ll;
const ll N = 500025, INF = 1e18;
struct Segtree {
ll mx[N<<1],lz[N];
void upd(int p, ll 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, ll 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);
}
ll query(int l, int r) {
ll res = -INF;
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;
}
void dbg() {
cout << "-------\n";
for(int i = 0; i < 10; i++) {
push(i+N);
cout << mx[i+N] << ' ';
}
cout << '\n';
}
} sgt;
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
int n = A.size(), q = X.size();
vector<ll> a(n), v(q);
{
for(int i = 0; i < n; i++) a[i] = A[i] * N + i;
for(int i = 0; i < q; i++) v[i] = V[i] * N + X[i];
}
{
vector<ll> 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<int> Q;
//sgt.init();
for(int i = 0; i < n; i++) {
sgt.add(a[i], a[i]+1, i);
sgt.add(a[i]+1, N, -1);
}
for(int i = 0; i < q; i++) {
int x = X[i], val = v[i];
sgt.add(a[x],a[x]+1, -x);
sgt.add(a[x]+1, N, 1);
a[x] = val;
sgt.add(a[x],a[x]+1, x);
sgt.add(a[x]+1, N, -1);
//sgt.dbg();
Q.pb(sgt.query(0,N));
}
return Q;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
504 KB |
Output is correct |
2 |
Correct |
9 ms |
504 KB |
Output is correct |
3 |
Correct |
11 ms |
760 KB |
Output is correct |
4 |
Correct |
11 ms |
800 KB |
Output is correct |
5 |
Correct |
11 ms |
760 KB |
Output is correct |
6 |
Correct |
10 ms |
764 KB |
Output is correct |
7 |
Correct |
13 ms |
760 KB |
Output is correct |
8 |
Correct |
11 ms |
836 KB |
Output is correct |
9 |
Correct |
11 ms |
760 KB |
Output is correct |
10 |
Correct |
12 ms |
760 KB |
Output is correct |
11 |
Correct |
11 ms |
632 KB |
Output is correct |
12 |
Correct |
10 ms |
632 KB |
Output is correct |
13 |
Correct |
10 ms |
632 KB |
Output is correct |
14 |
Correct |
11 ms |
788 KB |
Output is correct |
15 |
Correct |
11 ms |
760 KB |
Output is correct |
16 |
Correct |
10 ms |
760 KB |
Output is correct |
17 |
Correct |
12 ms |
888 KB |
Output is correct |
18 |
Correct |
12 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
504 KB |
Output is correct |
2 |
Correct |
9 ms |
504 KB |
Output is correct |
3 |
Correct |
11 ms |
760 KB |
Output is correct |
4 |
Correct |
11 ms |
800 KB |
Output is correct |
5 |
Correct |
11 ms |
760 KB |
Output is correct |
6 |
Correct |
10 ms |
764 KB |
Output is correct |
7 |
Correct |
13 ms |
760 KB |
Output is correct |
8 |
Correct |
11 ms |
836 KB |
Output is correct |
9 |
Correct |
11 ms |
760 KB |
Output is correct |
10 |
Correct |
12 ms |
760 KB |
Output is correct |
11 |
Correct |
11 ms |
632 KB |
Output is correct |
12 |
Correct |
10 ms |
632 KB |
Output is correct |
13 |
Correct |
10 ms |
632 KB |
Output is correct |
14 |
Correct |
11 ms |
788 KB |
Output is correct |
15 |
Correct |
11 ms |
760 KB |
Output is correct |
16 |
Correct |
10 ms |
760 KB |
Output is correct |
17 |
Correct |
12 ms |
888 KB |
Output is correct |
18 |
Correct |
12 ms |
632 KB |
Output is correct |
19 |
Correct |
23 ms |
1460 KB |
Output is correct |
20 |
Correct |
26 ms |
1556 KB |
Output is correct |
21 |
Correct |
24 ms |
1528 KB |
Output is correct |
22 |
Correct |
26 ms |
1700 KB |
Output is correct |
23 |
Correct |
25 ms |
1400 KB |
Output is correct |
24 |
Correct |
27 ms |
1400 KB |
Output is correct |
25 |
Correct |
26 ms |
1400 KB |
Output is correct |
26 |
Correct |
25 ms |
1400 KB |
Output is correct |
27 |
Correct |
26 ms |
1400 KB |
Output is correct |
28 |
Correct |
27 ms |
1272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
1808 KB |
Output is correct |
2 |
Correct |
105 ms |
3804 KB |
Output is correct |
3 |
Correct |
133 ms |
5752 KB |
Output is correct |
4 |
Correct |
131 ms |
5720 KB |
Output is correct |
5 |
Correct |
126 ms |
5820 KB |
Output is correct |
6 |
Correct |
136 ms |
5820 KB |
Output is correct |
7 |
Correct |
139 ms |
5876 KB |
Output is correct |
8 |
Correct |
145 ms |
5748 KB |
Output is correct |
9 |
Correct |
129 ms |
5864 KB |
Output is correct |
10 |
Correct |
150 ms |
4916 KB |
Output is correct |
11 |
Correct |
120 ms |
4976 KB |
Output is correct |
12 |
Correct |
126 ms |
4824 KB |
Output is correct |
13 |
Correct |
112 ms |
4896 KB |
Output is correct |
14 |
Correct |
105 ms |
4980 KB |
Output is correct |
15 |
Correct |
105 ms |
4696 KB |
Output is correct |
16 |
Correct |
103 ms |
4800 KB |
Output is correct |
17 |
Correct |
105 ms |
4796 KB |
Output is correct |
18 |
Correct |
103 ms |
4824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
504 KB |
Output is correct |
2 |
Correct |
9 ms |
504 KB |
Output is correct |
3 |
Correct |
11 ms |
760 KB |
Output is correct |
4 |
Correct |
11 ms |
800 KB |
Output is correct |
5 |
Correct |
11 ms |
760 KB |
Output is correct |
6 |
Correct |
10 ms |
764 KB |
Output is correct |
7 |
Correct |
13 ms |
760 KB |
Output is correct |
8 |
Correct |
11 ms |
836 KB |
Output is correct |
9 |
Correct |
11 ms |
760 KB |
Output is correct |
10 |
Correct |
12 ms |
760 KB |
Output is correct |
11 |
Correct |
11 ms |
632 KB |
Output is correct |
12 |
Correct |
10 ms |
632 KB |
Output is correct |
13 |
Correct |
10 ms |
632 KB |
Output is correct |
14 |
Correct |
11 ms |
788 KB |
Output is correct |
15 |
Correct |
11 ms |
760 KB |
Output is correct |
16 |
Correct |
10 ms |
760 KB |
Output is correct |
17 |
Correct |
12 ms |
888 KB |
Output is correct |
18 |
Correct |
12 ms |
632 KB |
Output is correct |
19 |
Correct |
23 ms |
1460 KB |
Output is correct |
20 |
Correct |
26 ms |
1556 KB |
Output is correct |
21 |
Correct |
24 ms |
1528 KB |
Output is correct |
22 |
Correct |
26 ms |
1700 KB |
Output is correct |
23 |
Correct |
25 ms |
1400 KB |
Output is correct |
24 |
Correct |
27 ms |
1400 KB |
Output is correct |
25 |
Correct |
26 ms |
1400 KB |
Output is correct |
26 |
Correct |
25 ms |
1400 KB |
Output is correct |
27 |
Correct |
26 ms |
1400 KB |
Output is correct |
28 |
Correct |
27 ms |
1272 KB |
Output is correct |
29 |
Correct |
30 ms |
1808 KB |
Output is correct |
30 |
Correct |
105 ms |
3804 KB |
Output is correct |
31 |
Correct |
133 ms |
5752 KB |
Output is correct |
32 |
Correct |
131 ms |
5720 KB |
Output is correct |
33 |
Correct |
126 ms |
5820 KB |
Output is correct |
34 |
Correct |
136 ms |
5820 KB |
Output is correct |
35 |
Correct |
139 ms |
5876 KB |
Output is correct |
36 |
Correct |
145 ms |
5748 KB |
Output is correct |
37 |
Correct |
129 ms |
5864 KB |
Output is correct |
38 |
Correct |
150 ms |
4916 KB |
Output is correct |
39 |
Correct |
120 ms |
4976 KB |
Output is correct |
40 |
Correct |
126 ms |
4824 KB |
Output is correct |
41 |
Correct |
112 ms |
4896 KB |
Output is correct |
42 |
Correct |
105 ms |
4980 KB |
Output is correct |
43 |
Correct |
105 ms |
4696 KB |
Output is correct |
44 |
Correct |
103 ms |
4800 KB |
Output is correct |
45 |
Correct |
105 ms |
4796 KB |
Output is correct |
46 |
Correct |
103 ms |
4824 KB |
Output is correct |
47 |
Correct |
523 ms |
18456 KB |
Output is correct |
48 |
Runtime error |
847 ms |
50048 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
49 |
Halted |
0 ms |
0 KB |
- |