#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
const int nx = 4e5+100;
int st[nx], co[nx], lz[nx];
void cons(int i, int l, int r){
st[i]=lz[i]=0;
co[i] = r-l+1;
if(l==r) return;
int m = l+r>>1;
cons(i<<1, l, m);cons(i<<1|1, m+1, r);
}
void upd(int i, int l, int r, int a, int b, int v){
if(lz[i]){
st[i] += lz[i];
if(l!=r){
lz[i<<1] += lz[i];
lz[i<<1|1] += lz[i];
}
lz[i]=0;
}
if(b<l||r<a) return;
if(a <= l && r <= b) {
st[i] += v;
if(l!=r){
lz[i<<1] += v;
lz[i<<1|1] += v;
}
return;
}
int m = l+r>>1;
upd(i<<1, l, m, a, b, v);upd(i<<1|1, m+1, r, a, b, v);
st[i] = max(st[i<<1], st[i<<1|1]);
co[i] = 0;
if(st[i<<1] == st[i]) co[i]=co[i<<1];
if(st[i<<1|1] == st[i]) co[i]+=co[i<<1|1];
}
void ans(int n, int k, int a[], int b[]){
cons(1, 0, n-1);
for(int i = 0;i < k;i++) {
upd(1, 0, n-1, max(0, b[a[i]]-k+1), min(n-k,b[a[i]]), 1);
}
int tans = st[1];long long c = co[1];
for(int i = 1;i+k <= n;i++){
upd(1, 0, n-1, max(0, b[a[i-1]]-k+1), min(n-k,b[a[i-1]]), -1);
upd(1, 0, n-1, max(0, b[a[i+k-1]]-k+1), min(n-k,b[a[i+k-1]]), 1);
if(st[1] > tans){
tans = st[1];
c = co[1];
} else if(st[1] == tans) c += co[1];
}
cout << tans << ' ' << c << '\n';
}
void solve(){
int n, k ,q;cin >> n >> k >> q;
int a[n],b[n+1];
for(int i = 0;i < n;i++) cin >> a[i];
for(int i = 0;i < n;i++) {
int th;cin >> th;
b[th] = i;
}
ans(n, k, a, b);
while(q--){
int p;cin >> p;
p--;
swap(a[p],a[p+1]);
ans(n,k,a,b);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
Compilation message
Main.cpp: In function 'void cons(int, int, int)':
Main.cpp:11:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
11 | int m = l+r>>1;
| ~^~
Main.cpp: In function 'void upd(int, int, int, int, int, int)':
Main.cpp:32:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
32 | int m = l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
2 ms |
4444 KB |
Output is correct |
17 |
Correct |
2 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
3 ms |
4664 KB |
Output is correct |
20 |
Correct |
6 ms |
4596 KB |
Output is correct |
21 |
Correct |
3 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
4444 KB |
Output is correct |
23 |
Correct |
4 ms |
4444 KB |
Output is correct |
24 |
Correct |
3 ms |
4444 KB |
Output is correct |
25 |
Correct |
3 ms |
4444 KB |
Output is correct |
26 |
Correct |
4 ms |
4444 KB |
Output is correct |
27 |
Correct |
4 ms |
4672 KB |
Output is correct |
28 |
Correct |
3 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
2 ms |
4444 KB |
Output is correct |
17 |
Correct |
2 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
3 ms |
4664 KB |
Output is correct |
20 |
Correct |
6 ms |
4596 KB |
Output is correct |
21 |
Correct |
3 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
4444 KB |
Output is correct |
23 |
Correct |
4 ms |
4444 KB |
Output is correct |
24 |
Correct |
3 ms |
4444 KB |
Output is correct |
25 |
Correct |
3 ms |
4444 KB |
Output is correct |
26 |
Correct |
4 ms |
4444 KB |
Output is correct |
27 |
Correct |
4 ms |
4672 KB |
Output is correct |
28 |
Correct |
3 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
46 ms |
5468 KB |
Output is correct |
32 |
Correct |
50 ms |
5468 KB |
Output is correct |
33 |
Correct |
23 ms |
5464 KB |
Output is correct |
34 |
Correct |
67 ms |
5484 KB |
Output is correct |
35 |
Correct |
96 ms |
5468 KB |
Output is correct |
36 |
Correct |
58 ms |
5468 KB |
Output is correct |
37 |
Correct |
24 ms |
5468 KB |
Output is correct |
38 |
Correct |
91 ms |
5468 KB |
Output is correct |
39 |
Correct |
61 ms |
5468 KB |
Output is correct |
40 |
Correct |
77 ms |
5468 KB |
Output is correct |
41 |
Correct |
84 ms |
5468 KB |
Output is correct |
42 |
Correct |
106 ms |
5468 KB |
Output is correct |
43 |
Correct |
65 ms |
5464 KB |
Output is correct |
44 |
Correct |
51 ms |
5468 KB |
Output is correct |
45 |
Correct |
29 ms |
5468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
2 ms |
4440 KB |
Output is correct |
17 |
Correct |
2 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
2 ms |
4444 KB |
Output is correct |
20 |
Correct |
2 ms |
4440 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
4444 KB |
Output is correct |
23 |
Correct |
2 ms |
4444 KB |
Output is correct |
24 |
Correct |
2 ms |
4556 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
2 ms |
4444 KB |
Output is correct |
27 |
Correct |
2 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
2 ms |
4444 KB |
Output is correct |
17 |
Correct |
2 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
3 ms |
4664 KB |
Output is correct |
20 |
Correct |
6 ms |
4596 KB |
Output is correct |
21 |
Correct |
3 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
4444 KB |
Output is correct |
23 |
Correct |
4 ms |
4444 KB |
Output is correct |
24 |
Correct |
3 ms |
4444 KB |
Output is correct |
25 |
Correct |
3 ms |
4444 KB |
Output is correct |
26 |
Correct |
4 ms |
4444 KB |
Output is correct |
27 |
Correct |
4 ms |
4672 KB |
Output is correct |
28 |
Correct |
3 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
2 ms |
4440 KB |
Output is correct |
32 |
Correct |
2 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
2 ms |
4444 KB |
Output is correct |
35 |
Correct |
2 ms |
4440 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
2 ms |
4444 KB |
Output is correct |
38 |
Correct |
2 ms |
4444 KB |
Output is correct |
39 |
Correct |
2 ms |
4556 KB |
Output is correct |
40 |
Correct |
1 ms |
4444 KB |
Output is correct |
41 |
Correct |
2 ms |
4444 KB |
Output is correct |
42 |
Correct |
2 ms |
4444 KB |
Output is correct |
43 |
Correct |
1 ms |
4444 KB |
Output is correct |
44 |
Correct |
2 ms |
4444 KB |
Output is correct |
45 |
Correct |
1 ms |
4444 KB |
Output is correct |
46 |
Execution timed out |
3076 ms |
4444 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
2 ms |
4444 KB |
Output is correct |
17 |
Correct |
2 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
3 ms |
4664 KB |
Output is correct |
20 |
Correct |
6 ms |
4596 KB |
Output is correct |
21 |
Correct |
3 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
4444 KB |
Output is correct |
23 |
Correct |
4 ms |
4444 KB |
Output is correct |
24 |
Correct |
3 ms |
4444 KB |
Output is correct |
25 |
Correct |
3 ms |
4444 KB |
Output is correct |
26 |
Correct |
4 ms |
4444 KB |
Output is correct |
27 |
Correct |
4 ms |
4672 KB |
Output is correct |
28 |
Correct |
3 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
46 ms |
5468 KB |
Output is correct |
32 |
Correct |
50 ms |
5468 KB |
Output is correct |
33 |
Correct |
23 ms |
5464 KB |
Output is correct |
34 |
Correct |
67 ms |
5484 KB |
Output is correct |
35 |
Correct |
96 ms |
5468 KB |
Output is correct |
36 |
Correct |
58 ms |
5468 KB |
Output is correct |
37 |
Correct |
24 ms |
5468 KB |
Output is correct |
38 |
Correct |
91 ms |
5468 KB |
Output is correct |
39 |
Correct |
61 ms |
5468 KB |
Output is correct |
40 |
Correct |
77 ms |
5468 KB |
Output is correct |
41 |
Correct |
84 ms |
5468 KB |
Output is correct |
42 |
Correct |
106 ms |
5468 KB |
Output is correct |
43 |
Correct |
65 ms |
5464 KB |
Output is correct |
44 |
Correct |
51 ms |
5468 KB |
Output is correct |
45 |
Correct |
29 ms |
5468 KB |
Output is correct |
46 |
Correct |
2 ms |
4440 KB |
Output is correct |
47 |
Correct |
2 ms |
4444 KB |
Output is correct |
48 |
Correct |
1 ms |
4444 KB |
Output is correct |
49 |
Correct |
2 ms |
4444 KB |
Output is correct |
50 |
Correct |
2 ms |
4440 KB |
Output is correct |
51 |
Correct |
1 ms |
4444 KB |
Output is correct |
52 |
Correct |
2 ms |
4444 KB |
Output is correct |
53 |
Correct |
2 ms |
4444 KB |
Output is correct |
54 |
Correct |
2 ms |
4556 KB |
Output is correct |
55 |
Correct |
1 ms |
4444 KB |
Output is correct |
56 |
Correct |
2 ms |
4444 KB |
Output is correct |
57 |
Correct |
2 ms |
4444 KB |
Output is correct |
58 |
Correct |
1 ms |
4444 KB |
Output is correct |
59 |
Correct |
2 ms |
4444 KB |
Output is correct |
60 |
Correct |
1 ms |
4444 KB |
Output is correct |
61 |
Execution timed out |
3076 ms |
4444 KB |
Time limit exceeded |
62 |
Halted |
0 ms |
0 KB |
- |