#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif
const int N = 1e5 + 5;
int n, k;
int ps[N];
int ind[N];
void upd(int l, int r, int v) {
for (int i = l; i <= min(n - 1, r); ++i) {
ps[i] += v;
}
}
pair<int, int> combine(pair<int, int> x, pair<int, int> y) {
if (x.first < y.first) swap(x, y);
if (x.first == y.first) {
x.second += y.second;
}
return x;
}
pair<int, int> qry() {
pair<int, int> ret;
//for (int i = 0; i < n; ++i) {
//debug(i, ps[i]);
//}
for (int i = k - 1; i < n; ++i) {
ret = combine(ret, make_pair(ps[i], 1));
}
return ret;
}
void solve(vector<int> a) {
for (int i = 0; i < k; ++i) {
upd(ind[a[i]], ind[a[i]] + k - 1, 1);
}
pair<int, int> ans;
for (int i = k - 1; i < n; ++i) {
auto v = qry();
ans = combine(ans, v);
upd(ind[a[i - k + 1]], ind[a[i - k + 1]] + k - 1, -1);
if (i + 1 < n) {
upd(ind[a[i + 1]], ind[a[i + 1]] + k - 1, 1);
}
}
for (int i = n - k + 1; i < n; ++i) {
upd(ind[a[i]], ind[a[i]] + k - 1, -1);
}
cout << ans.first << ' ' << ans.second << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int q;
cin >> n >> k >> q;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> b(n);
for (int i = 0; i < n; ++i) {
cin >> b[i];
ind[b[i]] = i;
}
solve(a);
while (q--) {
int t;
cin >> t;
swap(a[t - 1], a[t]);
solve(a);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
472 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
424 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
472 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
424 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
14 ms |
604 KB |
Output is correct |
17 |
Correct |
13 ms |
604 KB |
Output is correct |
18 |
Correct |
10 ms |
604 KB |
Output is correct |
19 |
Correct |
12 ms |
612 KB |
Output is correct |
20 |
Correct |
14 ms |
620 KB |
Output is correct |
21 |
Correct |
14 ms |
604 KB |
Output is correct |
22 |
Correct |
10 ms |
604 KB |
Output is correct |
23 |
Correct |
13 ms |
608 KB |
Output is correct |
24 |
Correct |
14 ms |
600 KB |
Output is correct |
25 |
Correct |
11 ms |
604 KB |
Output is correct |
26 |
Correct |
12 ms |
620 KB |
Output is correct |
27 |
Correct |
13 ms |
600 KB |
Output is correct |
28 |
Correct |
11 ms |
604 KB |
Output is correct |
29 |
Correct |
11 ms |
604 KB |
Output is correct |
30 |
Correct |
10 ms |
608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
472 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
424 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
14 ms |
604 KB |
Output is correct |
17 |
Correct |
13 ms |
604 KB |
Output is correct |
18 |
Correct |
10 ms |
604 KB |
Output is correct |
19 |
Correct |
12 ms |
612 KB |
Output is correct |
20 |
Correct |
14 ms |
620 KB |
Output is correct |
21 |
Correct |
14 ms |
604 KB |
Output is correct |
22 |
Correct |
10 ms |
604 KB |
Output is correct |
23 |
Correct |
13 ms |
608 KB |
Output is correct |
24 |
Correct |
14 ms |
600 KB |
Output is correct |
25 |
Correct |
11 ms |
604 KB |
Output is correct |
26 |
Correct |
12 ms |
620 KB |
Output is correct |
27 |
Correct |
13 ms |
600 KB |
Output is correct |
28 |
Correct |
11 ms |
604 KB |
Output is correct |
29 |
Correct |
11 ms |
604 KB |
Output is correct |
30 |
Correct |
10 ms |
608 KB |
Output is correct |
31 |
Execution timed out |
3057 ms |
3420 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
472 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
424 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
472 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
424 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
14 ms |
604 KB |
Output is correct |
17 |
Correct |
13 ms |
604 KB |
Output is correct |
18 |
Correct |
10 ms |
604 KB |
Output is correct |
19 |
Correct |
12 ms |
612 KB |
Output is correct |
20 |
Correct |
14 ms |
620 KB |
Output is correct |
21 |
Correct |
14 ms |
604 KB |
Output is correct |
22 |
Correct |
10 ms |
604 KB |
Output is correct |
23 |
Correct |
13 ms |
608 KB |
Output is correct |
24 |
Correct |
14 ms |
600 KB |
Output is correct |
25 |
Correct |
11 ms |
604 KB |
Output is correct |
26 |
Correct |
12 ms |
620 KB |
Output is correct |
27 |
Correct |
13 ms |
600 KB |
Output is correct |
28 |
Correct |
11 ms |
604 KB |
Output is correct |
29 |
Correct |
11 ms |
604 KB |
Output is correct |
30 |
Correct |
10 ms |
608 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
2 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
348 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Execution timed out |
3044 ms |
604 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
472 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
424 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
14 ms |
604 KB |
Output is correct |
17 |
Correct |
13 ms |
604 KB |
Output is correct |
18 |
Correct |
10 ms |
604 KB |
Output is correct |
19 |
Correct |
12 ms |
612 KB |
Output is correct |
20 |
Correct |
14 ms |
620 KB |
Output is correct |
21 |
Correct |
14 ms |
604 KB |
Output is correct |
22 |
Correct |
10 ms |
604 KB |
Output is correct |
23 |
Correct |
13 ms |
608 KB |
Output is correct |
24 |
Correct |
14 ms |
600 KB |
Output is correct |
25 |
Correct |
11 ms |
604 KB |
Output is correct |
26 |
Correct |
12 ms |
620 KB |
Output is correct |
27 |
Correct |
13 ms |
600 KB |
Output is correct |
28 |
Correct |
11 ms |
604 KB |
Output is correct |
29 |
Correct |
11 ms |
604 KB |
Output is correct |
30 |
Correct |
10 ms |
608 KB |
Output is correct |
31 |
Execution timed out |
3057 ms |
3420 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |