//Sylwia Sapkowska
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef DEBUG
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
const int oo = 1e9+7;
typedef pair<int, int> T;
struct TreeSum{
vector<int>tab, lazy;
int size = 1;
TreeSum(int n){
while (size < n) size*=2;
tab.assign(2*size, 0);
lazy.assign(2*size, 0);
}
void update(int x, int lx, int rx, int l, int r, int v){
if (lx != rx) push(x);
if (lx > r || rx < l) return;
if (lx >= l && rx <= r){
tab[x] += v;
lazy[x] += v;
return;
}
int m = (lx+rx)/2;
update(2*x, lx, m, l, r, v);
update(2*x+1, m+1, rx, l, r, v);
tab[x] = max(tab[2*x], tab[2*x+1]);
}
void push(int x){
tab[2*x] += lazy[x];
tab[2*x+1] += lazy[x];
lazy[2*x] += lazy[x];
lazy[2*x+1] += lazy[x];
lazy[x] = 0;
}
int query(int x, int lx, int rx, int l, int r){
if (lx != rx) push(x);
if (lx > r || rx < l) return -oo;
if (lx >= l && rx <= r) return tab[x];
int m = (lx+rx)/2;
return max(query(2*x, lx, m, l, r), query(2*x+1, m+1, rx, l, r));
}
};
vector<int> countScans(vector<int>a, vector<int>x, vector<int>v){
int n = (int)a.size();
int q = (int)x.size();
vector<pair<int, int>>s;
s.emplace_back(-oo, -oo);
for (int i = 0; i<n; i++) s.emplace_back(a[i], i);
for (int i = 0; i<q; i++) s.emplace_back(v[i], x[i]);
sort(s.begin(), s.end());
s.erase(unique(s.begin(), s.end()), s.end());
// debug(s);
int mx = (int)s.size()-1;
TreeSum t(mx+3);
auto get = [&](pair<int, int>now) -> int {
return lower_bound(s.begin(), s.end(), now) - s.begin();
};
for (int i = 0; i < n; i++){
auto curr = get(T{a[i], i});
t.update(1, 0, t.size-1, curr, mx, -1);
t.update(1, 0, t.size-1, curr, curr, i+1);
}
//ans = max(i-(less or equal to ai))
// t.d();
vector<int>ans;
for (int i = 0; i<q; i++){
auto nxt = get(T{v[i], x[i]});
auto curr = get(T{a[x[i]], x[i]});
a[x[i]] = v[i];
t.update(1, 0, t.size-1, curr, curr, -(x[i]+1));
t.update(1, 0, t.size-1, curr, mx, 1);
t.update(1, 0, t.size-1, nxt, nxt, x[i]+1);
t.update(1, 0, t.size-1, nxt, mx, -1);
// t.d();
ans.emplace_back(t.query(1, 0, t.size-1, 1, mx));
}
return ans;
}
/*
void solve(){
int n, q; cin >> n >> q;
vector<int>a(n);
for (int i = 0; i<n; i++) cin >> a[i];
vector<int>x(q), v(q);
for (int i = 0; i < q; i++) cin >> x[i] >> v[i];
debug(countScans(a, x, v));
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
6 ms |
472 KB |
Output is correct |
4 |
Correct |
6 ms |
468 KB |
Output is correct |
5 |
Correct |
6 ms |
468 KB |
Output is correct |
6 |
Correct |
6 ms |
468 KB |
Output is correct |
7 |
Correct |
5 ms |
468 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
6 ms |
468 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
468 KB |
Output is correct |
12 |
Correct |
6 ms |
476 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
14 |
Correct |
7 ms |
468 KB |
Output is correct |
15 |
Correct |
5 ms |
468 KB |
Output is correct |
16 |
Correct |
6 ms |
476 KB |
Output is correct |
17 |
Correct |
6 ms |
476 KB |
Output is correct |
18 |
Correct |
7 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
6 ms |
472 KB |
Output is correct |
4 |
Correct |
6 ms |
468 KB |
Output is correct |
5 |
Correct |
6 ms |
468 KB |
Output is correct |
6 |
Correct |
6 ms |
468 KB |
Output is correct |
7 |
Correct |
5 ms |
468 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
6 ms |
468 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
468 KB |
Output is correct |
12 |
Correct |
6 ms |
476 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
14 |
Correct |
7 ms |
468 KB |
Output is correct |
15 |
Correct |
5 ms |
468 KB |
Output is correct |
16 |
Correct |
6 ms |
476 KB |
Output is correct |
17 |
Correct |
6 ms |
476 KB |
Output is correct |
18 |
Correct |
7 ms |
468 KB |
Output is correct |
19 |
Correct |
21 ms |
852 KB |
Output is correct |
20 |
Correct |
27 ms |
880 KB |
Output is correct |
21 |
Correct |
25 ms |
932 KB |
Output is correct |
22 |
Correct |
27 ms |
904 KB |
Output is correct |
23 |
Correct |
26 ms |
884 KB |
Output is correct |
24 |
Correct |
26 ms |
852 KB |
Output is correct |
25 |
Correct |
27 ms |
884 KB |
Output is correct |
26 |
Correct |
23 ms |
884 KB |
Output is correct |
27 |
Correct |
25 ms |
884 KB |
Output is correct |
28 |
Correct |
24 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
1360 KB |
Output is correct |
2 |
Correct |
105 ms |
2728 KB |
Output is correct |
3 |
Correct |
204 ms |
4696 KB |
Output is correct |
4 |
Correct |
193 ms |
4916 KB |
Output is correct |
5 |
Correct |
192 ms |
4812 KB |
Output is correct |
6 |
Correct |
184 ms |
4700 KB |
Output is correct |
7 |
Correct |
200 ms |
4844 KB |
Output is correct |
8 |
Correct |
199 ms |
4764 KB |
Output is correct |
9 |
Correct |
174 ms |
4696 KB |
Output is correct |
10 |
Correct |
171 ms |
3668 KB |
Output is correct |
11 |
Correct |
177 ms |
3712 KB |
Output is correct |
12 |
Correct |
164 ms |
3620 KB |
Output is correct |
13 |
Correct |
164 ms |
3712 KB |
Output is correct |
14 |
Correct |
170 ms |
3668 KB |
Output is correct |
15 |
Correct |
159 ms |
3668 KB |
Output is correct |
16 |
Correct |
157 ms |
3668 KB |
Output is correct |
17 |
Correct |
156 ms |
3692 KB |
Output is correct |
18 |
Correct |
170 ms |
3652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
6 ms |
472 KB |
Output is correct |
4 |
Correct |
6 ms |
468 KB |
Output is correct |
5 |
Correct |
6 ms |
468 KB |
Output is correct |
6 |
Correct |
6 ms |
468 KB |
Output is correct |
7 |
Correct |
5 ms |
468 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
6 ms |
468 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
468 KB |
Output is correct |
12 |
Correct |
6 ms |
476 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
14 |
Correct |
7 ms |
468 KB |
Output is correct |
15 |
Correct |
5 ms |
468 KB |
Output is correct |
16 |
Correct |
6 ms |
476 KB |
Output is correct |
17 |
Correct |
6 ms |
476 KB |
Output is correct |
18 |
Correct |
7 ms |
468 KB |
Output is correct |
19 |
Correct |
21 ms |
852 KB |
Output is correct |
20 |
Correct |
27 ms |
880 KB |
Output is correct |
21 |
Correct |
25 ms |
932 KB |
Output is correct |
22 |
Correct |
27 ms |
904 KB |
Output is correct |
23 |
Correct |
26 ms |
884 KB |
Output is correct |
24 |
Correct |
26 ms |
852 KB |
Output is correct |
25 |
Correct |
27 ms |
884 KB |
Output is correct |
26 |
Correct |
23 ms |
884 KB |
Output is correct |
27 |
Correct |
25 ms |
884 KB |
Output is correct |
28 |
Correct |
24 ms |
852 KB |
Output is correct |
29 |
Correct |
31 ms |
1360 KB |
Output is correct |
30 |
Correct |
105 ms |
2728 KB |
Output is correct |
31 |
Correct |
204 ms |
4696 KB |
Output is correct |
32 |
Correct |
193 ms |
4916 KB |
Output is correct |
33 |
Correct |
192 ms |
4812 KB |
Output is correct |
34 |
Correct |
184 ms |
4700 KB |
Output is correct |
35 |
Correct |
200 ms |
4844 KB |
Output is correct |
36 |
Correct |
199 ms |
4764 KB |
Output is correct |
37 |
Correct |
174 ms |
4696 KB |
Output is correct |
38 |
Correct |
171 ms |
3668 KB |
Output is correct |
39 |
Correct |
177 ms |
3712 KB |
Output is correct |
40 |
Correct |
164 ms |
3620 KB |
Output is correct |
41 |
Correct |
164 ms |
3712 KB |
Output is correct |
42 |
Correct |
170 ms |
3668 KB |
Output is correct |
43 |
Correct |
159 ms |
3668 KB |
Output is correct |
44 |
Correct |
157 ms |
3668 KB |
Output is correct |
45 |
Correct |
156 ms |
3692 KB |
Output is correct |
46 |
Correct |
170 ms |
3652 KB |
Output is correct |
47 |
Correct |
689 ms |
15796 KB |
Output is correct |
48 |
Correct |
2541 ms |
38596 KB |
Output is correct |
49 |
Correct |
2699 ms |
40280 KB |
Output is correct |
50 |
Correct |
2837 ms |
40280 KB |
Output is correct |
51 |
Correct |
2994 ms |
40276 KB |
Output is correct |
52 |
Correct |
2827 ms |
40300 KB |
Output is correct |
53 |
Correct |
2697 ms |
40324 KB |
Output is correct |
54 |
Correct |
2725 ms |
40196 KB |
Output is correct |
55 |
Correct |
2707 ms |
40308 KB |
Output is correct |
56 |
Correct |
2589 ms |
40252 KB |
Output is correct |
57 |
Correct |
2703 ms |
40436 KB |
Output is correct |
58 |
Correct |
2491 ms |
40220 KB |
Output is correct |
59 |
Correct |
2425 ms |
40416 KB |
Output is correct |
60 |
Correct |
2313 ms |
40296 KB |
Output is correct |
61 |
Correct |
2361 ms |
40248 KB |
Output is correct |
62 |
Correct |
2410 ms |
40364 KB |
Output is correct |
63 |
Correct |
2332 ms |
40276 KB |
Output is correct |
64 |
Correct |
2356 ms |
40296 KB |
Output is correct |
65 |
Correct |
2296 ms |
40376 KB |
Output is correct |
66 |
Correct |
2283 ms |
40440 KB |
Output is correct |
67 |
Correct |
2222 ms |
40244 KB |
Output is correct |