#pragma GCC optimize("Ofast,unroll-loops")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifndef SINA
#include "bubblesort2.h"
#endif
using namespace std;
using namespace __gnu_pbds;
typedef int ll;
typedef long double ld;
typedef pair <ll, ll> pll;
#ifdef SINA
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << std::endl; }
template <typename Arg1, typename... Args> void __f (const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); }
#define dbg2(x, j, n) cout<< #x << " : "; output((j), (n), x, 1); cout.flush();
#else
#define dbg(...) 0
#define dbg2(x, j, n) 0
#endif
#define SZ(x) ((ll)((x).size()))
#define File(s, t) freopen(s ".txt", "r", stdin); freopen(t ".txt", "w", stdout);
#define input(j, n, a) for (int _i = (j); _i < (n)+(j); _i++) cin>> a[_i];
#define output(j, n, a, t) for (int _i = (j); _i < (n)+(j); _i++) cout<< a[_i] << (((t) && _i != (n)+(j)-1)? ' ' : '\n');
#define kill(x) return cout<< (x) << endl, 0
#define cl const ll
#define fr first
#define sc second
#define lc (v << 1)
#define rc (lc | 1)
#define mid ((l + r) >> 1)
#define All(x) (x).begin(), (x).end()
cl inf = sizeof(ll) == 4 ? (1e9 + 10) : (3e18), mod = 1e9 + 7, MOD = 998244353;
template <class A,class B> ostream& operator << (ostream& out,const pair<A,B>&a){return out<<'('<<a.first<<", "<<a.second<<')';}
template <class A> ostream& operator << (ostream& out, const vector<A> &a) {
out<< '['; for (int i = -1; ++i < int(a.size());) out<< a[i] << (i + 1 < int(a.size()) ? ", " : ""); return out<<']'; }
template <class T, typename _t = less <T> > using Tree = tree <T, null_type, _t, rb_tree_tag, tree_order_statistics_node_update>;
cl N = 5e5 + 7;
struct segtree {
ll l, r, mx, lz;
segtree *lt, *rt;
inline segtree (cl &L = 1, cl &R = N - 2) : l(L), r(R), mx(0), lz(0) {}
void build () {
mx = -inf;
if (l == r) return;
lt = new segtree (l, mid);
rt = new segtree (mid + 1, r);
lt->build();
rt->build();
}
inline void push (cl &x) { mx += x; lz += x; }
inline void shift () { lt->push(lz); rt->push(lz); lz = 0; }
void upd (cl &ql, cl &qr, cl &x) {
if (r < ql || qr < l) return;
if (ql <= l && r <= qr) {
push(x);
return;
}
shift();
lt->upd(ql, qr, x);
rt->upd(ql, qr, x);
mx = max(lt->mx, rt->mx);
}
ll ask (cl &ql, cl &qr) {
if (r < ql || qr < l) return -inf;
if (ql <= l && r <= qr) return mx;
shift();
return max(lt->ask(ql, qr), rt->ask(ql, qr));
}
} seg;
vector <ll> countScans (vector <ll> a, vector <ll> x, vector <ll> v) {
ll n = SZ(a), q = SZ(x);
vector <pll> cmprs;
for (ll i = 0; i < n; i++) cmprs.push_back({a[i], i});
for (ll i = 0; i < q; i++) cmprs.push_back({v[i], x[i]});
sort(All(cmprs)); cmprs.resize(unique(All(cmprs)) - cmprs.begin());
seg.r = SZ(cmprs); seg.build();
const auto fun = [&](cl &val, cl &pos, cl &z) {
ll P = lower_bound(All(cmprs), pll(val, pos)) - cmprs.begin() + 1;
seg.upd(P, P, z * (inf + pos));
seg.upd(P + 1, seg.r, z * -1);
};
for (ll i = 0; i < n; i++) fun(a[i], i, 1);
vector <ll> ans (q);
for (ll i = 0, p1, p2; i < q; i++) {
fun(a[x[i]], x[i], -1);
a[x[i]] = v[i];
fun(v[i], x[i], 1);
ans[i] = seg.mx;
}
return ans;
}
#ifdef SINA
int main ()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cout<< countScans({1, 2, 3, 4}, {0, 2}, {3, 1}) << endl;
cerr<< "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
#endif
/*
*/
Compilation message
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:103:17: warning: unused variable 'p1' [-Wunused-variable]
103 | for (ll i = 0, p1, p2; i < q; i++) {
| ^~
bubblesort2.cpp:103:21: warning: unused variable 'p2' [-Wunused-variable]
103 | for (ll i = 0, p1, p2; i < q; i++) {
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Correct |
6 ms |
716 KB |
Output is correct |
4 |
Correct |
6 ms |
688 KB |
Output is correct |
5 |
Correct |
6 ms |
732 KB |
Output is correct |
6 |
Correct |
5 ms |
696 KB |
Output is correct |
7 |
Correct |
5 ms |
716 KB |
Output is correct |
8 |
Correct |
7 ms |
972 KB |
Output is correct |
9 |
Correct |
6 ms |
804 KB |
Output is correct |
10 |
Correct |
5 ms |
700 KB |
Output is correct |
11 |
Correct |
5 ms |
716 KB |
Output is correct |
12 |
Correct |
5 ms |
716 KB |
Output is correct |
13 |
Correct |
5 ms |
716 KB |
Output is correct |
14 |
Correct |
5 ms |
716 KB |
Output is correct |
15 |
Correct |
5 ms |
720 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
5 ms |
588 KB |
Output is correct |
18 |
Correct |
6 ms |
704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Correct |
6 ms |
716 KB |
Output is correct |
4 |
Correct |
6 ms |
688 KB |
Output is correct |
5 |
Correct |
6 ms |
732 KB |
Output is correct |
6 |
Correct |
5 ms |
696 KB |
Output is correct |
7 |
Correct |
5 ms |
716 KB |
Output is correct |
8 |
Correct |
7 ms |
972 KB |
Output is correct |
9 |
Correct |
6 ms |
804 KB |
Output is correct |
10 |
Correct |
5 ms |
700 KB |
Output is correct |
11 |
Correct |
5 ms |
716 KB |
Output is correct |
12 |
Correct |
5 ms |
716 KB |
Output is correct |
13 |
Correct |
5 ms |
716 KB |
Output is correct |
14 |
Correct |
5 ms |
716 KB |
Output is correct |
15 |
Correct |
5 ms |
720 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
5 ms |
588 KB |
Output is correct |
18 |
Correct |
6 ms |
704 KB |
Output is correct |
19 |
Correct |
21 ms |
1996 KB |
Output is correct |
20 |
Correct |
28 ms |
2316 KB |
Output is correct |
21 |
Correct |
23 ms |
2244 KB |
Output is correct |
22 |
Correct |
23 ms |
2264 KB |
Output is correct |
23 |
Correct |
22 ms |
2124 KB |
Output is correct |
24 |
Correct |
22 ms |
2112 KB |
Output is correct |
25 |
Correct |
21 ms |
1996 KB |
Output is correct |
26 |
Correct |
21 ms |
2004 KB |
Output is correct |
27 |
Correct |
21 ms |
1824 KB |
Output is correct |
28 |
Correct |
21 ms |
1856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
3656 KB |
Output is correct |
2 |
Correct |
101 ms |
7868 KB |
Output is correct |
3 |
Correct |
188 ms |
12328 KB |
Output is correct |
4 |
Correct |
188 ms |
12244 KB |
Output is correct |
5 |
Correct |
183 ms |
12184 KB |
Output is correct |
6 |
Correct |
186 ms |
12088 KB |
Output is correct |
7 |
Correct |
187 ms |
11996 KB |
Output is correct |
8 |
Correct |
181 ms |
12088 KB |
Output is correct |
9 |
Correct |
186 ms |
12056 KB |
Output is correct |
10 |
Correct |
139 ms |
8120 KB |
Output is correct |
11 |
Correct |
140 ms |
8120 KB |
Output is correct |
12 |
Correct |
141 ms |
8120 KB |
Output is correct |
13 |
Correct |
138 ms |
8156 KB |
Output is correct |
14 |
Correct |
136 ms |
8120 KB |
Output is correct |
15 |
Correct |
135 ms |
8164 KB |
Output is correct |
16 |
Correct |
129 ms |
8248 KB |
Output is correct |
17 |
Correct |
132 ms |
8144 KB |
Output is correct |
18 |
Correct |
127 ms |
8156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Correct |
6 ms |
716 KB |
Output is correct |
4 |
Correct |
6 ms |
688 KB |
Output is correct |
5 |
Correct |
6 ms |
732 KB |
Output is correct |
6 |
Correct |
5 ms |
696 KB |
Output is correct |
7 |
Correct |
5 ms |
716 KB |
Output is correct |
8 |
Correct |
7 ms |
972 KB |
Output is correct |
9 |
Correct |
6 ms |
804 KB |
Output is correct |
10 |
Correct |
5 ms |
700 KB |
Output is correct |
11 |
Correct |
5 ms |
716 KB |
Output is correct |
12 |
Correct |
5 ms |
716 KB |
Output is correct |
13 |
Correct |
5 ms |
716 KB |
Output is correct |
14 |
Correct |
5 ms |
716 KB |
Output is correct |
15 |
Correct |
5 ms |
720 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
5 ms |
588 KB |
Output is correct |
18 |
Correct |
6 ms |
704 KB |
Output is correct |
19 |
Correct |
21 ms |
1996 KB |
Output is correct |
20 |
Correct |
28 ms |
2316 KB |
Output is correct |
21 |
Correct |
23 ms |
2244 KB |
Output is correct |
22 |
Correct |
23 ms |
2264 KB |
Output is correct |
23 |
Correct |
22 ms |
2124 KB |
Output is correct |
24 |
Correct |
22 ms |
2112 KB |
Output is correct |
25 |
Correct |
21 ms |
1996 KB |
Output is correct |
26 |
Correct |
21 ms |
2004 KB |
Output is correct |
27 |
Correct |
21 ms |
1824 KB |
Output is correct |
28 |
Correct |
21 ms |
1856 KB |
Output is correct |
29 |
Correct |
32 ms |
3656 KB |
Output is correct |
30 |
Correct |
101 ms |
7868 KB |
Output is correct |
31 |
Correct |
188 ms |
12328 KB |
Output is correct |
32 |
Correct |
188 ms |
12244 KB |
Output is correct |
33 |
Correct |
183 ms |
12184 KB |
Output is correct |
34 |
Correct |
186 ms |
12088 KB |
Output is correct |
35 |
Correct |
187 ms |
11996 KB |
Output is correct |
36 |
Correct |
181 ms |
12088 KB |
Output is correct |
37 |
Correct |
186 ms |
12056 KB |
Output is correct |
38 |
Correct |
139 ms |
8120 KB |
Output is correct |
39 |
Correct |
140 ms |
8120 KB |
Output is correct |
40 |
Correct |
141 ms |
8120 KB |
Output is correct |
41 |
Correct |
138 ms |
8156 KB |
Output is correct |
42 |
Correct |
136 ms |
8120 KB |
Output is correct |
43 |
Correct |
135 ms |
8164 KB |
Output is correct |
44 |
Correct |
129 ms |
8248 KB |
Output is correct |
45 |
Correct |
132 ms |
8144 KB |
Output is correct |
46 |
Correct |
127 ms |
8156 KB |
Output is correct |
47 |
Correct |
757 ms |
38188 KB |
Output is correct |
48 |
Correct |
3080 ms |
117688 KB |
Output is correct |
49 |
Correct |
3403 ms |
128632 KB |
Output is correct |
50 |
Correct |
3342 ms |
128656 KB |
Output is correct |
51 |
Correct |
3341 ms |
128652 KB |
Output is correct |
52 |
Correct |
3356 ms |
128624 KB |
Output is correct |
53 |
Correct |
3351 ms |
128624 KB |
Output is correct |
54 |
Correct |
3008 ms |
128768 KB |
Output is correct |
55 |
Correct |
3210 ms |
128884 KB |
Output is correct |
56 |
Correct |
2917 ms |
128800 KB |
Output is correct |
57 |
Correct |
3117 ms |
128804 KB |
Output is correct |
58 |
Correct |
2916 ms |
128800 KB |
Output is correct |
59 |
Correct |
2658 ms |
115824 KB |
Output is correct |
60 |
Correct |
2718 ms |
115744 KB |
Output is correct |
61 |
Correct |
2728 ms |
115672 KB |
Output is correct |
62 |
Correct |
2506 ms |
109812 KB |
Output is correct |
63 |
Correct |
2555 ms |
109688 KB |
Output is correct |
64 |
Correct |
2567 ms |
109728 KB |
Output is correct |
65 |
Correct |
2312 ms |
103708 KB |
Output is correct |
66 |
Correct |
2382 ms |
103676 KB |
Output is correct |
67 |
Correct |
2385 ms |
103620 KB |
Output is correct |