#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define PII pair<pii , pii>
#define ld long double
#define ll long long
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= b;i++)
#define per(i , a , b) for(int i=a;i >= b;i--)
using namespace std ;
const int maxn = 1e5 +10 , N = 1e5 +1 , maxq = 202 , inf = 1e9 , maxk = 2022 , mod =1e9+7 ;
struct node{
int mx, t, s , l , r ;
node(){
mx = s = l = r= t =0 ;
}
};node nw ;
vector<node> seg ;
void mrg(int p){
int l = seg[p].l , r= seg[p].r ;
seg[p].s = seg[l].s + seg[r].s ;
seg[p].mx = max(seg[l].mx , seg[l].s + seg[r].mx) ;
if(seg[p].mx == seg[l].mx)seg[p].t += seg[l].t ;
if(seg[p].mx == seg[l].s + seg[r].mx)seg[p].t += seg[r].t ;
}
int c =1 ,root[maxn] , p[maxn] , pos[maxn] , n , k , q ;
int bui(int l = 1, int r =n-k+1){
int mid = (l+r)/2 ;
if(l == r){
seg.pb(nw) ;
seg[c].t = 1;
c++;
return c-1;
}
int id = c ;c++;
seg.pb(nw);
seg[id].l = bui(l,mid);
seg[id].r = bui(mid+1,r);
mrg(id) ;
return id ;
}
inline int ff(int l , int r , int x, int y){
if((l <= x&& x <= r) || (l <= y && y <= r))return 1 ;
return 0 ;
}
int upd(int x ,int w , int x2 , int w2 , int p , int l ,int r){
int id = c , mid = (l+r)/2 ; c++ ;
seg.pb(nw);
if(l == r){
int su = seg[p].s ;
if(x==l){
su += w;
}
if(x2==l){
su += w2 ;
}
seg[id].mx = seg[id].s = su;
seg[id].t = 1;
return id ;
}
seg[id].l = seg[p].l ;
seg[id].r = seg[p].r ;
if(ff(l , mid , x , x2))seg[id].l = upd(x,w,x2,w2,seg[p].l , l ,mid);
if(ff(mid+1, r , x ,x2))seg[id].r = upd(x,w,x2,w2,seg[p].r ,mid+1,r);
mrg(id) ;
return id ;
}
map <int ,ll> mp ;
void add_(int x ,int y){
mp[x] += y;
}
void rem_(int x, int y){
mp[x] -= y ;
if(mp[x] == 0){
mp.erase(x) ;
}
}
void add(int x , int r){
rem_(seg[root[r]].mx , seg[root[r]].t) ;
root[r]= upd((x+1 <= n-k+1 ? x+1 : max(1 ,x-k+1)) , (x+1 <= n-k+1 ? -1 : 0) , max(1 ,x-k+1), 1 , root[r] , 1 , n-k+1);
add_(seg[root[r]].mx , seg[root[r]].t) ;
}
void rem(int x , int r){
rem_(seg[root[r]].mx , seg[root[r]].t) ;
root[r]= upd((x+1 <= n-k+1 ? x+1 : max(1 ,x-k+1)) , (x+1 <= n-k+1 ? 1 : 0) , max(1 ,x-k+1), -1 , root[r] , 1 , n-k+1);
add_(seg[root[r]].mx , seg[root[r]].t) ;
}
void cp(){
cout << (*mp.rbegin()).F << " " << (*mp.rbegin()).S << "\n";
}
signed main(){
ios::sync_with_stdio(false), cin.tie(0);
seg.pb(nw) ;
cin >> n >> k >> q ;
rep(i ,1, n){
cin >> p[i] ;
}
rep(i ,1, n){
int x;
cin >> x;
pos[x] = i;
}
rep(i ,1, n)p[i] = pos[p[i]] ;
root[1] = bui();
add_(0 , n-k+1);
rep(i ,1 ,k){
add(p[i] , 1) ;
}
rep(i ,2 , n-k+1){
add_(seg[root[i-1]].mx , seg[root[i-1]].t) ;
root[i] = root[i-1] ;
add(p[i+k-1], i) ;
rem(p[i-1] , i) ;
}
cp();
while(q--){
int t ;
cin>>t;
if(t >= k){
int f = t-k+1 ;
add(p[t+1] , f) ;
rem(p[t] , f);
}
if(t+k <= n){
add(p[t] , t+1);
rem(p[t+1] , t+1);
}
swap(p[t] , p[t+1]);
cp();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
500 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
500 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
7 ms |
6604 KB |
Output is correct |
17 |
Correct |
6 ms |
6344 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
8 ms |
5836 KB |
Output is correct |
20 |
Correct |
11 ms |
7116 KB |
Output is correct |
21 |
Correct |
6 ms |
7116 KB |
Output is correct |
22 |
Correct |
3 ms |
1876 KB |
Output is correct |
23 |
Correct |
8 ms |
6860 KB |
Output is correct |
24 |
Correct |
7 ms |
6860 KB |
Output is correct |
25 |
Correct |
12 ms |
6092 KB |
Output is correct |
26 |
Correct |
6 ms |
6600 KB |
Output is correct |
27 |
Correct |
10 ms |
5668 KB |
Output is correct |
28 |
Correct |
8 ms |
7372 KB |
Output is correct |
29 |
Correct |
5 ms |
3020 KB |
Output is correct |
30 |
Correct |
3 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
500 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
7 ms |
6604 KB |
Output is correct |
17 |
Correct |
6 ms |
6344 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
8 ms |
5836 KB |
Output is correct |
20 |
Correct |
11 ms |
7116 KB |
Output is correct |
21 |
Correct |
6 ms |
7116 KB |
Output is correct |
22 |
Correct |
3 ms |
1876 KB |
Output is correct |
23 |
Correct |
8 ms |
6860 KB |
Output is correct |
24 |
Correct |
7 ms |
6860 KB |
Output is correct |
25 |
Correct |
12 ms |
6092 KB |
Output is correct |
26 |
Correct |
6 ms |
6600 KB |
Output is correct |
27 |
Correct |
10 ms |
5668 KB |
Output is correct |
28 |
Correct |
8 ms |
7372 KB |
Output is correct |
29 |
Correct |
5 ms |
3020 KB |
Output is correct |
30 |
Correct |
3 ms |
1876 KB |
Output is correct |
31 |
Correct |
159 ms |
84600 KB |
Output is correct |
32 |
Correct |
203 ms |
167064 KB |
Output is correct |
33 |
Correct |
19 ms |
3792 KB |
Output is correct |
34 |
Correct |
142 ms |
84832 KB |
Output is correct |
35 |
Correct |
265 ms |
167828 KB |
Output is correct |
36 |
Correct |
153 ms |
167120 KB |
Output is correct |
37 |
Correct |
51 ms |
43688 KB |
Output is correct |
38 |
Correct |
224 ms |
167656 KB |
Output is correct |
39 |
Correct |
161 ms |
167316 KB |
Output is correct |
40 |
Correct |
190 ms |
166576 KB |
Output is correct |
41 |
Correct |
204 ms |
166040 KB |
Output is correct |
42 |
Correct |
253 ms |
165784 KB |
Output is correct |
43 |
Correct |
149 ms |
85204 KB |
Output is correct |
44 |
Correct |
125 ms |
84484 KB |
Output is correct |
45 |
Correct |
53 ms |
43196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
500 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
804 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
500 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
7 ms |
6604 KB |
Output is correct |
17 |
Correct |
6 ms |
6344 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
8 ms |
5836 KB |
Output is correct |
20 |
Correct |
11 ms |
7116 KB |
Output is correct |
21 |
Correct |
6 ms |
7116 KB |
Output is correct |
22 |
Correct |
3 ms |
1876 KB |
Output is correct |
23 |
Correct |
8 ms |
6860 KB |
Output is correct |
24 |
Correct |
7 ms |
6860 KB |
Output is correct |
25 |
Correct |
12 ms |
6092 KB |
Output is correct |
26 |
Correct |
6 ms |
6600 KB |
Output is correct |
27 |
Correct |
10 ms |
5668 KB |
Output is correct |
28 |
Correct |
8 ms |
7372 KB |
Output is correct |
29 |
Correct |
5 ms |
3020 KB |
Output is correct |
30 |
Correct |
3 ms |
1876 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
460 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
1 ms |
604 KB |
Output is correct |
39 |
Correct |
1 ms |
604 KB |
Output is correct |
40 |
Correct |
1 ms |
604 KB |
Output is correct |
41 |
Correct |
1 ms |
604 KB |
Output is correct |
42 |
Correct |
1 ms |
804 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
14 ms |
11972 KB |
Output is correct |
47 |
Correct |
15 ms |
11720 KB |
Output is correct |
48 |
Correct |
3 ms |
604 KB |
Output is correct |
49 |
Correct |
13 ms |
12488 KB |
Output is correct |
50 |
Correct |
23 ms |
21448 KB |
Output is correct |
51 |
Correct |
7 ms |
3024 KB |
Output is correct |
52 |
Correct |
13 ms |
12488 KB |
Output is correct |
53 |
Correct |
24 ms |
22468 KB |
Output is correct |
54 |
Correct |
22 ms |
21132 KB |
Output is correct |
55 |
Correct |
12 ms |
11208 KB |
Output is correct |
56 |
Correct |
24 ms |
22468 KB |
Output is correct |
57 |
Correct |
24 ms |
22724 KB |
Output is correct |
58 |
Correct |
7 ms |
7368 KB |
Output is correct |
59 |
Correct |
25 ms |
11364 KB |
Output is correct |
60 |
Correct |
7 ms |
7016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
500 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
7 ms |
6604 KB |
Output is correct |
17 |
Correct |
6 ms |
6344 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
8 ms |
5836 KB |
Output is correct |
20 |
Correct |
11 ms |
7116 KB |
Output is correct |
21 |
Correct |
6 ms |
7116 KB |
Output is correct |
22 |
Correct |
3 ms |
1876 KB |
Output is correct |
23 |
Correct |
8 ms |
6860 KB |
Output is correct |
24 |
Correct |
7 ms |
6860 KB |
Output is correct |
25 |
Correct |
12 ms |
6092 KB |
Output is correct |
26 |
Correct |
6 ms |
6600 KB |
Output is correct |
27 |
Correct |
10 ms |
5668 KB |
Output is correct |
28 |
Correct |
8 ms |
7372 KB |
Output is correct |
29 |
Correct |
5 ms |
3020 KB |
Output is correct |
30 |
Correct |
3 ms |
1876 KB |
Output is correct |
31 |
Correct |
159 ms |
84600 KB |
Output is correct |
32 |
Correct |
203 ms |
167064 KB |
Output is correct |
33 |
Correct |
19 ms |
3792 KB |
Output is correct |
34 |
Correct |
142 ms |
84832 KB |
Output is correct |
35 |
Correct |
265 ms |
167828 KB |
Output is correct |
36 |
Correct |
153 ms |
167120 KB |
Output is correct |
37 |
Correct |
51 ms |
43688 KB |
Output is correct |
38 |
Correct |
224 ms |
167656 KB |
Output is correct |
39 |
Correct |
161 ms |
167316 KB |
Output is correct |
40 |
Correct |
190 ms |
166576 KB |
Output is correct |
41 |
Correct |
204 ms |
166040 KB |
Output is correct |
42 |
Correct |
253 ms |
165784 KB |
Output is correct |
43 |
Correct |
149 ms |
85204 KB |
Output is correct |
44 |
Correct |
125 ms |
84484 KB |
Output is correct |
45 |
Correct |
53 ms |
43196 KB |
Output is correct |
46 |
Correct |
1 ms |
600 KB |
Output is correct |
47 |
Correct |
1 ms |
604 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
460 KB |
Output is correct |
50 |
Correct |
1 ms |
604 KB |
Output is correct |
51 |
Correct |
1 ms |
348 KB |
Output is correct |
52 |
Correct |
1 ms |
604 KB |
Output is correct |
53 |
Correct |
1 ms |
604 KB |
Output is correct |
54 |
Correct |
1 ms |
604 KB |
Output is correct |
55 |
Correct |
1 ms |
604 KB |
Output is correct |
56 |
Correct |
1 ms |
604 KB |
Output is correct |
57 |
Correct |
1 ms |
804 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
604 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
14 ms |
11972 KB |
Output is correct |
62 |
Correct |
15 ms |
11720 KB |
Output is correct |
63 |
Correct |
3 ms |
604 KB |
Output is correct |
64 |
Correct |
13 ms |
12488 KB |
Output is correct |
65 |
Correct |
23 ms |
21448 KB |
Output is correct |
66 |
Correct |
7 ms |
3024 KB |
Output is correct |
67 |
Correct |
13 ms |
12488 KB |
Output is correct |
68 |
Correct |
24 ms |
22468 KB |
Output is correct |
69 |
Correct |
22 ms |
21132 KB |
Output is correct |
70 |
Correct |
12 ms |
11208 KB |
Output is correct |
71 |
Correct |
24 ms |
22468 KB |
Output is correct |
72 |
Correct |
24 ms |
22724 KB |
Output is correct |
73 |
Correct |
7 ms |
7368 KB |
Output is correct |
74 |
Correct |
25 ms |
11364 KB |
Output is correct |
75 |
Correct |
7 ms |
7016 KB |
Output is correct |
76 |
Correct |
727 ms |
332244 KB |
Output is correct |
77 |
Correct |
704 ms |
332484 KB |
Output is correct |
78 |
Correct |
35 ms |
5756 KB |
Output is correct |
79 |
Correct |
521 ms |
168080 KB |
Output is correct |
80 |
Runtime error |
1293 ms |
524288 KB |
Execution killed with signal 9 |
81 |
Halted |
0 ms |
0 KB |
- |