#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define fi first
#define se second
#define ll long long
const int MX = 1e5 + 10;
const int INF = 1e9 + 7;
int N, K, Q, p[MX], q[MX], pos[MX];
pii merge(pii a, pii b){
if(a.fi > b.fi) return a;
if(b.fi > a.fi) return b;
return make_pair(a.fi, a.se + b.se);
}
struct node{
int l, r, lz; pii val;
node *lc, *rc;
node(int l = 0, int r = -1) : l(l), r(r), lz(0), lc(NULL), rc(NULL) {
val.fi = 0;
val.se = r - l + 1;
}
void prop(){
if(l != r){
int mid = l + r >> 1;
if(lc == NULL) lc = new node(l, mid);
if(rc == NULL) rc = new node(mid + 1, r);
lc -> lz += lz; lc -> val.fi += lz;
rc -> lz += lz; rc -> val.fi += lz;
}
lz = 0;
}
pii query(int lf, int rg){
if(r < lf || l > rg) return {-INF, 1};
if(lf <= l && r <= rg) return val;
prop();
return merge(lc -> query(lf, rg), rc -> query(lf, rg));
}
void upd(int lf, int rg, int v){
if(r < lf || l > rg) return;
prop();
if(lf <= l && r <= rg){
val.fi += v;
lz += v;
prop();
}else{
int mid = l + r >> 1;
lc -> upd(lf, rg, v);
rc -> upd(lf, rg, v);
val = merge(lc -> val, rc -> val);
}
}
};
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> K >> Q;
for(int i = 0; i < N; i++) cin >> p[i];
for(int i = 0; i < N; i++) cin >> q[i], pos[q[i]] = i;
node *root = new node(0, N - 1);
for(int i = 0; i < K; i++)
root -> upd(max(0, pos[p[i]] - K + 1), pos[p[i]], 1);
pii curr = root -> query(0, N - K);
int mx = -INF; ll cnt = 0;
if(curr.fi > mx) mx = curr.fi, cnt = curr.se;
else if(curr.fi == mx) cnt += curr.se;
for(int i = K; i < N; i++){
root -> upd(max(0, pos[p[i - K]] - K + 1), pos[p[i - K]], -1);
root -> upd(max(0, pos[p[i]] - K + 1), pos[p[i]], 1);
curr = root -> query(0, N - K);
if(curr.fi > mx) mx = curr.fi, cnt = curr.se;
else if(curr.fi == mx) cnt += curr.se;
}
cout << mx << " " << cnt << '\n';
}
Compilation message
Main.cpp: In member function 'void node::prop()':
Main.cpp:31:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
31 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: In member function 'void node::upd(int, int, int)':
Main.cpp:55:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | int mid = l + r >> 1;
| ~~^~~
Main.cpp:55:8: warning: unused variable 'mid' [-Wunused-variable]
55 | int mid = l + r >> 1;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
3 ms |
852 KB |
Output is correct |
18 |
Correct |
2 ms |
852 KB |
Output is correct |
19 |
Correct |
4 ms |
852 KB |
Output is correct |
20 |
Correct |
5 ms |
852 KB |
Output is correct |
21 |
Correct |
6 ms |
852 KB |
Output is correct |
22 |
Correct |
2 ms |
900 KB |
Output is correct |
23 |
Correct |
5 ms |
852 KB |
Output is correct |
24 |
Correct |
4 ms |
852 KB |
Output is correct |
25 |
Correct |
4 ms |
852 KB |
Output is correct |
26 |
Correct |
4 ms |
852 KB |
Output is correct |
27 |
Correct |
5 ms |
852 KB |
Output is correct |
28 |
Correct |
4 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
852 KB |
Output is correct |
30 |
Correct |
2 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
3 ms |
852 KB |
Output is correct |
18 |
Correct |
2 ms |
852 KB |
Output is correct |
19 |
Correct |
4 ms |
852 KB |
Output is correct |
20 |
Correct |
5 ms |
852 KB |
Output is correct |
21 |
Correct |
6 ms |
852 KB |
Output is correct |
22 |
Correct |
2 ms |
900 KB |
Output is correct |
23 |
Correct |
5 ms |
852 KB |
Output is correct |
24 |
Correct |
4 ms |
852 KB |
Output is correct |
25 |
Correct |
4 ms |
852 KB |
Output is correct |
26 |
Correct |
4 ms |
852 KB |
Output is correct |
27 |
Correct |
5 ms |
852 KB |
Output is correct |
28 |
Correct |
4 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
852 KB |
Output is correct |
30 |
Correct |
2 ms |
896 KB |
Output is correct |
31 |
Correct |
67 ms |
11776 KB |
Output is correct |
32 |
Correct |
87 ms |
11596 KB |
Output is correct |
33 |
Correct |
47 ms |
11596 KB |
Output is correct |
34 |
Correct |
88 ms |
11684 KB |
Output is correct |
35 |
Correct |
139 ms |
11932 KB |
Output is correct |
36 |
Correct |
81 ms |
11472 KB |
Output is correct |
37 |
Correct |
38 ms |
11852 KB |
Output is correct |
38 |
Correct |
137 ms |
11568 KB |
Output is correct |
39 |
Correct |
87 ms |
11896 KB |
Output is correct |
40 |
Correct |
106 ms |
11340 KB |
Output is correct |
41 |
Correct |
119 ms |
11852 KB |
Output is correct |
42 |
Correct |
142 ms |
11520 KB |
Output is correct |
43 |
Correct |
98 ms |
11468 KB |
Output is correct |
44 |
Correct |
85 ms |
11896 KB |
Output is correct |
45 |
Correct |
53 ms |
11724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
3 ms |
852 KB |
Output is correct |
18 |
Correct |
2 ms |
852 KB |
Output is correct |
19 |
Correct |
4 ms |
852 KB |
Output is correct |
20 |
Correct |
5 ms |
852 KB |
Output is correct |
21 |
Correct |
6 ms |
852 KB |
Output is correct |
22 |
Correct |
2 ms |
900 KB |
Output is correct |
23 |
Correct |
5 ms |
852 KB |
Output is correct |
24 |
Correct |
4 ms |
852 KB |
Output is correct |
25 |
Correct |
4 ms |
852 KB |
Output is correct |
26 |
Correct |
4 ms |
852 KB |
Output is correct |
27 |
Correct |
5 ms |
852 KB |
Output is correct |
28 |
Correct |
4 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
852 KB |
Output is correct |
30 |
Correct |
2 ms |
896 KB |
Output is correct |
31 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
3 ms |
852 KB |
Output is correct |
18 |
Correct |
2 ms |
852 KB |
Output is correct |
19 |
Correct |
4 ms |
852 KB |
Output is correct |
20 |
Correct |
5 ms |
852 KB |
Output is correct |
21 |
Correct |
6 ms |
852 KB |
Output is correct |
22 |
Correct |
2 ms |
900 KB |
Output is correct |
23 |
Correct |
5 ms |
852 KB |
Output is correct |
24 |
Correct |
4 ms |
852 KB |
Output is correct |
25 |
Correct |
4 ms |
852 KB |
Output is correct |
26 |
Correct |
4 ms |
852 KB |
Output is correct |
27 |
Correct |
5 ms |
852 KB |
Output is correct |
28 |
Correct |
4 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
852 KB |
Output is correct |
30 |
Correct |
2 ms |
896 KB |
Output is correct |
31 |
Correct |
67 ms |
11776 KB |
Output is correct |
32 |
Correct |
87 ms |
11596 KB |
Output is correct |
33 |
Correct |
47 ms |
11596 KB |
Output is correct |
34 |
Correct |
88 ms |
11684 KB |
Output is correct |
35 |
Correct |
139 ms |
11932 KB |
Output is correct |
36 |
Correct |
81 ms |
11472 KB |
Output is correct |
37 |
Correct |
38 ms |
11852 KB |
Output is correct |
38 |
Correct |
137 ms |
11568 KB |
Output is correct |
39 |
Correct |
87 ms |
11896 KB |
Output is correct |
40 |
Correct |
106 ms |
11340 KB |
Output is correct |
41 |
Correct |
119 ms |
11852 KB |
Output is correct |
42 |
Correct |
142 ms |
11520 KB |
Output is correct |
43 |
Correct |
98 ms |
11468 KB |
Output is correct |
44 |
Correct |
85 ms |
11896 KB |
Output is correct |
45 |
Correct |
53 ms |
11724 KB |
Output is correct |
46 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
47 |
Halted |
0 ms |
0 KB |
- |