#include <bits/stdc++.h>
#include "bubblesort2.h"
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 998244353, maxn = 5e5 + 5, lg = 22, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
int seg[maxn<<2], laz[maxn<<2];
map<pp, int> mp; int id;
void updNode(int x, int k){
seg[x] += k, laz[x] += k;
}
void shift(int x){
if(laz[x]){
updNode(x<<1, laz[x]), updNode(x<<1|1, laz[x]);
laz[x] = 0;
}
}
void upd(int l, int r, int k, int x = 1, int lx = 0, int rx = id){
if(l <= lx && r >= rx){
updNode(x, k);
return;
} if(l >= rx || r <= lx) return;
shift(x);
int mid = (lx + rx)>>1;
upd(l, r, k, x<<1, lx, mid), upd(l, r, k, x<<1|1, mid, rx);
seg[x] = max(seg[x<<1], seg[x<<1|1]);
}
void add(int p, int v, int k){
int ps = mp[{v, p}];
upd(ps, ps + 1, k*(inf+p));
if(ps+1-id) upd(ps+1, id, -k);
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
int n = sz(A), q = sz(X);
rep(i,0,n) mp[{A[i], i}] = 0;
rep(i,0,q) mp[{V[i], X[i]}] = 0;
for(auto&c:mp) c.ss = id++;
upd(0, id, -inf);
rep(i,0,n) add(i, A[i], 1);
vector<int> res(q);
rep(i,0,q){
add(X[i], A[X[i]], -1), add(X[i], A[X[i]] = V[i], 1);
res[i] = seg[1];
}
return res;
}
// int main(){
// cin.tie(0) -> sync_with_stdio(0);
// int n, q; cin >> n >> q;
// vector<int> a(n);
// rep(i,0,n) cin >> a[i], mp[{a[i], i}] = 0;
// vector<pp> query(q);
// rep(i,0,q) cin >> query[i].ff >> query[i].ss, mp[{query[i].ss, query[i].ff}] = 0;
// for(auto&c:mp) c.ss = id++;
// upd(0, id, -inf);
// rep(i,0,n) add(i, a[i], 1);
// for(auto[p, v]: query){
// add(p, a[p], -1), add(p, a[p] = v, 1);
// cout << seg[1] << '\n';
// }
// return 0;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
412 KB |
Output is correct |
3 |
Correct |
5 ms |
732 KB |
Output is correct |
4 |
Correct |
5 ms |
736 KB |
Output is correct |
5 |
Correct |
5 ms |
724 KB |
Output is correct |
6 |
Correct |
5 ms |
724 KB |
Output is correct |
7 |
Correct |
5 ms |
724 KB |
Output is correct |
8 |
Correct |
5 ms |
724 KB |
Output is correct |
9 |
Correct |
4 ms |
712 KB |
Output is correct |
10 |
Correct |
4 ms |
596 KB |
Output is correct |
11 |
Correct |
5 ms |
596 KB |
Output is correct |
12 |
Correct |
5 ms |
596 KB |
Output is correct |
13 |
Correct |
5 ms |
596 KB |
Output is correct |
14 |
Correct |
5 ms |
596 KB |
Output is correct |
15 |
Correct |
5 ms |
596 KB |
Output is correct |
16 |
Correct |
5 ms |
596 KB |
Output is correct |
17 |
Correct |
6 ms |
596 KB |
Output is correct |
18 |
Correct |
4 ms |
576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
412 KB |
Output is correct |
3 |
Correct |
5 ms |
732 KB |
Output is correct |
4 |
Correct |
5 ms |
736 KB |
Output is correct |
5 |
Correct |
5 ms |
724 KB |
Output is correct |
6 |
Correct |
5 ms |
724 KB |
Output is correct |
7 |
Correct |
5 ms |
724 KB |
Output is correct |
8 |
Correct |
5 ms |
724 KB |
Output is correct |
9 |
Correct |
4 ms |
712 KB |
Output is correct |
10 |
Correct |
4 ms |
596 KB |
Output is correct |
11 |
Correct |
5 ms |
596 KB |
Output is correct |
12 |
Correct |
5 ms |
596 KB |
Output is correct |
13 |
Correct |
5 ms |
596 KB |
Output is correct |
14 |
Correct |
5 ms |
596 KB |
Output is correct |
15 |
Correct |
5 ms |
596 KB |
Output is correct |
16 |
Correct |
5 ms |
596 KB |
Output is correct |
17 |
Correct |
6 ms |
596 KB |
Output is correct |
18 |
Correct |
4 ms |
576 KB |
Output is correct |
19 |
Correct |
20 ms |
1780 KB |
Output is correct |
20 |
Correct |
30 ms |
1976 KB |
Output is correct |
21 |
Correct |
26 ms |
1984 KB |
Output is correct |
22 |
Correct |
28 ms |
1996 KB |
Output is correct |
23 |
Correct |
22 ms |
1880 KB |
Output is correct |
24 |
Correct |
25 ms |
1748 KB |
Output is correct |
25 |
Correct |
18 ms |
1724 KB |
Output is correct |
26 |
Correct |
18 ms |
1748 KB |
Output is correct |
27 |
Correct |
18 ms |
1700 KB |
Output is correct |
28 |
Correct |
19 ms |
1704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
3032 KB |
Output is correct |
2 |
Correct |
105 ms |
6460 KB |
Output is correct |
3 |
Correct |
209 ms |
10536 KB |
Output is correct |
4 |
Correct |
225 ms |
10444 KB |
Output is correct |
5 |
Correct |
234 ms |
10400 KB |
Output is correct |
6 |
Correct |
180 ms |
10404 KB |
Output is correct |
7 |
Correct |
160 ms |
10316 KB |
Output is correct |
8 |
Correct |
192 ms |
10448 KB |
Output is correct |
9 |
Correct |
232 ms |
10572 KB |
Output is correct |
10 |
Correct |
135 ms |
6772 KB |
Output is correct |
11 |
Correct |
132 ms |
6652 KB |
Output is correct |
12 |
Correct |
135 ms |
6732 KB |
Output is correct |
13 |
Correct |
140 ms |
6720 KB |
Output is correct |
14 |
Correct |
125 ms |
6760 KB |
Output is correct |
15 |
Correct |
143 ms |
6780 KB |
Output is correct |
16 |
Correct |
123 ms |
6808 KB |
Output is correct |
17 |
Correct |
124 ms |
6776 KB |
Output is correct |
18 |
Correct |
122 ms |
6744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
412 KB |
Output is correct |
3 |
Correct |
5 ms |
732 KB |
Output is correct |
4 |
Correct |
5 ms |
736 KB |
Output is correct |
5 |
Correct |
5 ms |
724 KB |
Output is correct |
6 |
Correct |
5 ms |
724 KB |
Output is correct |
7 |
Correct |
5 ms |
724 KB |
Output is correct |
8 |
Correct |
5 ms |
724 KB |
Output is correct |
9 |
Correct |
4 ms |
712 KB |
Output is correct |
10 |
Correct |
4 ms |
596 KB |
Output is correct |
11 |
Correct |
5 ms |
596 KB |
Output is correct |
12 |
Correct |
5 ms |
596 KB |
Output is correct |
13 |
Correct |
5 ms |
596 KB |
Output is correct |
14 |
Correct |
5 ms |
596 KB |
Output is correct |
15 |
Correct |
5 ms |
596 KB |
Output is correct |
16 |
Correct |
5 ms |
596 KB |
Output is correct |
17 |
Correct |
6 ms |
596 KB |
Output is correct |
18 |
Correct |
4 ms |
576 KB |
Output is correct |
19 |
Correct |
20 ms |
1780 KB |
Output is correct |
20 |
Correct |
30 ms |
1976 KB |
Output is correct |
21 |
Correct |
26 ms |
1984 KB |
Output is correct |
22 |
Correct |
28 ms |
1996 KB |
Output is correct |
23 |
Correct |
22 ms |
1880 KB |
Output is correct |
24 |
Correct |
25 ms |
1748 KB |
Output is correct |
25 |
Correct |
18 ms |
1724 KB |
Output is correct |
26 |
Correct |
18 ms |
1748 KB |
Output is correct |
27 |
Correct |
18 ms |
1700 KB |
Output is correct |
28 |
Correct |
19 ms |
1704 KB |
Output is correct |
29 |
Correct |
34 ms |
3032 KB |
Output is correct |
30 |
Correct |
105 ms |
6460 KB |
Output is correct |
31 |
Correct |
209 ms |
10536 KB |
Output is correct |
32 |
Correct |
225 ms |
10444 KB |
Output is correct |
33 |
Correct |
234 ms |
10400 KB |
Output is correct |
34 |
Correct |
180 ms |
10404 KB |
Output is correct |
35 |
Correct |
160 ms |
10316 KB |
Output is correct |
36 |
Correct |
192 ms |
10448 KB |
Output is correct |
37 |
Correct |
232 ms |
10572 KB |
Output is correct |
38 |
Correct |
135 ms |
6772 KB |
Output is correct |
39 |
Correct |
132 ms |
6652 KB |
Output is correct |
40 |
Correct |
135 ms |
6732 KB |
Output is correct |
41 |
Correct |
140 ms |
6720 KB |
Output is correct |
42 |
Correct |
125 ms |
6760 KB |
Output is correct |
43 |
Correct |
143 ms |
6780 KB |
Output is correct |
44 |
Correct |
123 ms |
6808 KB |
Output is correct |
45 |
Correct |
124 ms |
6776 KB |
Output is correct |
46 |
Correct |
122 ms |
6744 KB |
Output is correct |
47 |
Correct |
966 ms |
34812 KB |
Output is correct |
48 |
Runtime error |
1096 ms |
151380 KB |
Execution killed with signal 11 |
49 |
Halted |
0 ms |
0 KB |
- |