#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ldb,ldb> pdd;
#define ff(i,a,b) for(int i = a; i <= b; i++)
#define fb(i,b,a) for(int i = b; i >= a; i--)
#define trav(a,x) for(auto& a : x)
#define sz(a) (int)(a).size()
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k) print the k-th smallest number in os(0-based)
const int mod = 1000000007;
const int inf = 1e9 + 5;
const int mxN = 100005;
int n, k, q;
int A[mxN];
int B[mxN];
int poz[mxN];
int L[mxN];
int R[mxN];
int mx[4 * mxN];
int sum[4 * mxN];
int cnt[4 * mxN];
void build(int v, int tl, int tr){
if(tl == tr){
mx[v] = sum[v] = 0;
cnt[v] = 1;
return;
}
int mid = (tl + tr) / 2;
build(v * 2, tl, mid); build(v * 2 + 1, mid + 1, tr);
sum[v] = sum[v * 2] + sum[v * 2 + 1];
mx[v] = max(mx[v * 2], mx[v * 2 + 1] + sum[v * 2]);
cnt[v] = (mx[v] == mx[v * 2] ? cnt[v * 2] : 0) + (mx[v] == mx[v * 2 + 1] + sum[v * 2] ? cnt[v * 2 + 1] : 0);
}
void update(int v, int tl, int tr, int pos, int val){
if(tl == tr){
mx[v] += val;
sum[v] += val;
return;
}
int mid = (tl + tr) / 2;
if(pos <= mid)update(v * 2, tl, mid, pos, val);
else update(v * 2 + 1, mid + 1, tr, pos, val);
sum[v] = sum[v * 2] + sum[v * 2 + 1];
mx[v] = max(mx[v * 2], mx[v * 2 + 1] + sum[v * 2]);
cnt[v] = (mx[v] == mx[v * 2] ? cnt[v * 2] : 0) + (mx[v] == mx[v * 2 + 1] + sum[v * 2] ? cnt[v * 2 + 1] : 0);
}
void calc(){
build(1,1,n - k + 1);
ff(i,1,k){
int l = L[poz[A[i]]];
int r = R[poz[A[i]]];
update(1,1,n - k + 1,l,1);
if(r < n - k + 1)update(1,1,n - k + 1,r + 1,-1);
}
int najv = mx[1]; ll br = cnt[1];
ff(i,k + 1,n){
int l1 = L[poz[A[i - k]]];
int r1 = R[poz[A[i - k]]];
update(1,1,n - k + 1,l1,-1);
if(r1 < n - k + 1)update(1,1,n - k + 1,r1 + 1,1);
int l2 = L[poz[A[i]]];
int r2 = R[poz[A[i]]];
update(1,1,n - k + 1,l2,1);
if(r2 < n - k + 1)update(1,1,n - k + 1,r2 + 1,-1);
if(mx[1] > najv){
najv = mx[1];
br = cnt[1];
}
else if(mx[1] == najv)br += cnt[1];
}
cout << najv << " " << br << '\n';
}
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k >> q;
ff(i,1,n)cin >> A[i];
ff(i,1,n)cin >> B[i], poz[B[i]] = i;
ff(i,1,n){
L[i] = max(1, i - k + 1);
R[i] = min(i, n - k + 1);
}
calc();
while(q--){
int t;
cin >> t;
swap(A[t], A[t + 1]);
calc();
}
return 0;
}
/*
4 3 0
2 4 1 3
1 2 3 4
// probati bojenje sahovski
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
3 ms |
6688 KB |
Output is correct |
17 |
Correct |
4 ms |
6488 KB |
Output is correct |
18 |
Correct |
1 ms |
6564 KB |
Output is correct |
19 |
Correct |
3 ms |
6660 KB |
Output is correct |
20 |
Correct |
5 ms |
6492 KB |
Output is correct |
21 |
Correct |
3 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
4 ms |
6492 KB |
Output is correct |
24 |
Correct |
3 ms |
6492 KB |
Output is correct |
25 |
Correct |
3 ms |
6492 KB |
Output is correct |
26 |
Correct |
4 ms |
6492 KB |
Output is correct |
27 |
Correct |
4 ms |
6492 KB |
Output is correct |
28 |
Correct |
3 ms |
6492 KB |
Output is correct |
29 |
Correct |
2 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
3 ms |
6688 KB |
Output is correct |
17 |
Correct |
4 ms |
6488 KB |
Output is correct |
18 |
Correct |
1 ms |
6564 KB |
Output is correct |
19 |
Correct |
3 ms |
6660 KB |
Output is correct |
20 |
Correct |
5 ms |
6492 KB |
Output is correct |
21 |
Correct |
3 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
4 ms |
6492 KB |
Output is correct |
24 |
Correct |
3 ms |
6492 KB |
Output is correct |
25 |
Correct |
3 ms |
6492 KB |
Output is correct |
26 |
Correct |
4 ms |
6492 KB |
Output is correct |
27 |
Correct |
4 ms |
6492 KB |
Output is correct |
28 |
Correct |
3 ms |
6492 KB |
Output is correct |
29 |
Correct |
2 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
65 ms |
7004 KB |
Output is correct |
32 |
Correct |
72 ms |
7000 KB |
Output is correct |
33 |
Correct |
11 ms |
6748 KB |
Output is correct |
34 |
Correct |
50 ms |
6892 KB |
Output is correct |
35 |
Correct |
101 ms |
7000 KB |
Output is correct |
36 |
Correct |
50 ms |
7000 KB |
Output is correct |
37 |
Correct |
18 ms |
7004 KB |
Output is correct |
38 |
Correct |
99 ms |
7004 KB |
Output is correct |
39 |
Correct |
65 ms |
7092 KB |
Output is correct |
40 |
Correct |
60 ms |
8016 KB |
Output is correct |
41 |
Correct |
73 ms |
8024 KB |
Output is correct |
42 |
Correct |
92 ms |
8028 KB |
Output is correct |
43 |
Correct |
54 ms |
8000 KB |
Output is correct |
44 |
Correct |
43 ms |
8020 KB |
Output is correct |
45 |
Correct |
21 ms |
8028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
3 ms |
6492 KB |
Output is correct |
17 |
Correct |
3 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
6492 KB |
Output is correct |
23 |
Correct |
2 ms |
6492 KB |
Output is correct |
24 |
Correct |
3 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
2 ms |
6624 KB |
Output is correct |
27 |
Correct |
2 ms |
6616 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
2 ms |
6492 KB |
Output is correct |
30 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
3 ms |
6688 KB |
Output is correct |
17 |
Correct |
4 ms |
6488 KB |
Output is correct |
18 |
Correct |
1 ms |
6564 KB |
Output is correct |
19 |
Correct |
3 ms |
6660 KB |
Output is correct |
20 |
Correct |
5 ms |
6492 KB |
Output is correct |
21 |
Correct |
3 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
4 ms |
6492 KB |
Output is correct |
24 |
Correct |
3 ms |
6492 KB |
Output is correct |
25 |
Correct |
3 ms |
6492 KB |
Output is correct |
26 |
Correct |
4 ms |
6492 KB |
Output is correct |
27 |
Correct |
4 ms |
6492 KB |
Output is correct |
28 |
Correct |
3 ms |
6492 KB |
Output is correct |
29 |
Correct |
2 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
3 ms |
6492 KB |
Output is correct |
32 |
Correct |
3 ms |
6492 KB |
Output is correct |
33 |
Correct |
1 ms |
6492 KB |
Output is correct |
34 |
Correct |
2 ms |
6492 KB |
Output is correct |
35 |
Correct |
2 ms |
6492 KB |
Output is correct |
36 |
Correct |
1 ms |
6492 KB |
Output is correct |
37 |
Correct |
2 ms |
6492 KB |
Output is correct |
38 |
Correct |
2 ms |
6492 KB |
Output is correct |
39 |
Correct |
3 ms |
6492 KB |
Output is correct |
40 |
Correct |
1 ms |
6492 KB |
Output is correct |
41 |
Correct |
2 ms |
6624 KB |
Output is correct |
42 |
Correct |
2 ms |
6616 KB |
Output is correct |
43 |
Correct |
1 ms |
6492 KB |
Output is correct |
44 |
Correct |
2 ms |
6492 KB |
Output is correct |
45 |
Correct |
2 ms |
6492 KB |
Output is correct |
46 |
Execution timed out |
3082 ms |
6668 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
3 ms |
6688 KB |
Output is correct |
17 |
Correct |
4 ms |
6488 KB |
Output is correct |
18 |
Correct |
1 ms |
6564 KB |
Output is correct |
19 |
Correct |
3 ms |
6660 KB |
Output is correct |
20 |
Correct |
5 ms |
6492 KB |
Output is correct |
21 |
Correct |
3 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
4 ms |
6492 KB |
Output is correct |
24 |
Correct |
3 ms |
6492 KB |
Output is correct |
25 |
Correct |
3 ms |
6492 KB |
Output is correct |
26 |
Correct |
4 ms |
6492 KB |
Output is correct |
27 |
Correct |
4 ms |
6492 KB |
Output is correct |
28 |
Correct |
3 ms |
6492 KB |
Output is correct |
29 |
Correct |
2 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
65 ms |
7004 KB |
Output is correct |
32 |
Correct |
72 ms |
7000 KB |
Output is correct |
33 |
Correct |
11 ms |
6748 KB |
Output is correct |
34 |
Correct |
50 ms |
6892 KB |
Output is correct |
35 |
Correct |
101 ms |
7000 KB |
Output is correct |
36 |
Correct |
50 ms |
7000 KB |
Output is correct |
37 |
Correct |
18 ms |
7004 KB |
Output is correct |
38 |
Correct |
99 ms |
7004 KB |
Output is correct |
39 |
Correct |
65 ms |
7092 KB |
Output is correct |
40 |
Correct |
60 ms |
8016 KB |
Output is correct |
41 |
Correct |
73 ms |
8024 KB |
Output is correct |
42 |
Correct |
92 ms |
8028 KB |
Output is correct |
43 |
Correct |
54 ms |
8000 KB |
Output is correct |
44 |
Correct |
43 ms |
8020 KB |
Output is correct |
45 |
Correct |
21 ms |
8028 KB |
Output is correct |
46 |
Correct |
3 ms |
6492 KB |
Output is correct |
47 |
Correct |
3 ms |
6492 KB |
Output is correct |
48 |
Correct |
1 ms |
6492 KB |
Output is correct |
49 |
Correct |
2 ms |
6492 KB |
Output is correct |
50 |
Correct |
2 ms |
6492 KB |
Output is correct |
51 |
Correct |
1 ms |
6492 KB |
Output is correct |
52 |
Correct |
2 ms |
6492 KB |
Output is correct |
53 |
Correct |
2 ms |
6492 KB |
Output is correct |
54 |
Correct |
3 ms |
6492 KB |
Output is correct |
55 |
Correct |
1 ms |
6492 KB |
Output is correct |
56 |
Correct |
2 ms |
6624 KB |
Output is correct |
57 |
Correct |
2 ms |
6616 KB |
Output is correct |
58 |
Correct |
1 ms |
6492 KB |
Output is correct |
59 |
Correct |
2 ms |
6492 KB |
Output is correct |
60 |
Correct |
2 ms |
6492 KB |
Output is correct |
61 |
Execution timed out |
3082 ms |
6668 KB |
Time limit exceeded |
62 |
Halted |
0 ms |
0 KB |
- |