# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
791574 |
2023-07-24T07:35:19 Z |
GEN 이지후(#10078) |
Sličnost (COI23_slicnost) |
C++17 |
|
3000 ms |
10660 KB |
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = array<lint, 2>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
const int MAXT = 270000;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k, q;
cin >> n >> k >> q;
vector<int> a1(n), a2(n);
vector<int> r1(n), r2(n);
for (int i = 0; i < n; i++) {
cin >> a1[i];
a1[i]--;
r1[a1[i]] = i;
}
for (int i = 0; i < n; i++) {
cin >> a2[i];
a2[i]--;
r2[a2[i]] = i;
}
vector<vector<array<int, 3>>> swp(n + 1);
vector<vector<array<int, 4>>> temp(n + 1);
vector<pi> queries(q + 1);
for (int i = 0; i < n; i++) {
int x1 = max(k - 1, r1[i]), x2 = min(r1[i] + k, n);
int y1 = max(k - 1, r2[i]), y2 = min(r2[i] + k, n);
swp[x1].push_back({y1, y2, +1});
swp[x2].push_back({y1, y2, -1});
}
auto rangeAdd = [&](int p, int l, int r, int d, int ts) {
if (p < k - 1 || p >= n)
return;
l = max(l, k - 1);
r = min(r, n);
temp[p].push_back({ts, l, r, d});
};
for (int i = 1; i <= q; i++) {
int t;
cin >> t;
t--;
int p1 = a1[t], p2 = a1[t + 1];
swap(a1[t], a1[t + 1]);
rangeAdd(r1[p1], r2[p1], r2[p1] + k, -1, i);
rangeAdd(r1[p1] + k, r2[p1], r2[p1] + k, +1, i);
rangeAdd(r1[p2] + k - 1, r2[p2], r2[p2] + k, -1, i);
rangeAdd(r1[p2] - 1, r2[p2], r2[p2] + k, +1, i);
r1[p1]++;
r1[p2]--;
}
vector<int> arr(n);
for (int i = k - 1; i < n; i++) {
for (auto &x : swp[i]) {
for (int j = x[0]; j < x[1]; j++) {
arr[j] += x[2];
}
}
temp[i].push_back({q + 1, 0, 0});
int las = 0;
for (auto &[ts, l, r, d] : temp[i]) {
int mx = 0, mxc = 0;
for (int j = k - 1; j < n; j++) {
if (mx < arr[j]) {
mx = arr[j];
mxc = 0;
}
if (mx == arr[j])
mxc++;
}
for (int t = las; t < ts; t++) {
if (queries[t][0] < mx) {
queries[t][0] = mx;
queries[t][1] = 0;
}
if (queries[t][0] == mx)
queries[t][1] += mxc;
}
las = ts;
for (int j = l; j < r; j++)
arr[j] += d;
}
for (auto &[ts, l, r, d] : temp[i]) {
for (int j = l; j < r; j++)
arr[j] -= d;
}
}
for (int i = 0; i <= q; i++) {
if (queries[i][0] == 0)
queries[i][1] = 1ll * (n - k + 1) * (n - k + 1);
cout << queries[i][0] << " " << queries[i][1] << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
35 ms |
924 KB |
Output is correct |
17 |
Correct |
31 ms |
928 KB |
Output is correct |
18 |
Correct |
1 ms |
760 KB |
Output is correct |
19 |
Correct |
10 ms |
852 KB |
Output is correct |
20 |
Correct |
30 ms |
876 KB |
Output is correct |
21 |
Correct |
24 ms |
864 KB |
Output is correct |
22 |
Correct |
3 ms |
852 KB |
Output is correct |
23 |
Correct |
34 ms |
852 KB |
Output is correct |
24 |
Correct |
31 ms |
872 KB |
Output is correct |
25 |
Correct |
18 ms |
788 KB |
Output is correct |
26 |
Correct |
19 ms |
888 KB |
Output is correct |
27 |
Correct |
29 ms |
908 KB |
Output is correct |
28 |
Correct |
15 ms |
848 KB |
Output is correct |
29 |
Correct |
9 ms |
820 KB |
Output is correct |
30 |
Correct |
2 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
35 ms |
924 KB |
Output is correct |
17 |
Correct |
31 ms |
928 KB |
Output is correct |
18 |
Correct |
1 ms |
760 KB |
Output is correct |
19 |
Correct |
10 ms |
852 KB |
Output is correct |
20 |
Correct |
30 ms |
876 KB |
Output is correct |
21 |
Correct |
24 ms |
864 KB |
Output is correct |
22 |
Correct |
3 ms |
852 KB |
Output is correct |
23 |
Correct |
34 ms |
852 KB |
Output is correct |
24 |
Correct |
31 ms |
872 KB |
Output is correct |
25 |
Correct |
18 ms |
788 KB |
Output is correct |
26 |
Correct |
19 ms |
888 KB |
Output is correct |
27 |
Correct |
29 ms |
908 KB |
Output is correct |
28 |
Correct |
15 ms |
848 KB |
Output is correct |
29 |
Correct |
9 ms |
820 KB |
Output is correct |
30 |
Correct |
2 ms |
852 KB |
Output is correct |
31 |
Execution timed out |
3072 ms |
10660 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
35 ms |
924 KB |
Output is correct |
17 |
Correct |
31 ms |
928 KB |
Output is correct |
18 |
Correct |
1 ms |
760 KB |
Output is correct |
19 |
Correct |
10 ms |
852 KB |
Output is correct |
20 |
Correct |
30 ms |
876 KB |
Output is correct |
21 |
Correct |
24 ms |
864 KB |
Output is correct |
22 |
Correct |
3 ms |
852 KB |
Output is correct |
23 |
Correct |
34 ms |
852 KB |
Output is correct |
24 |
Correct |
31 ms |
872 KB |
Output is correct |
25 |
Correct |
18 ms |
788 KB |
Output is correct |
26 |
Correct |
19 ms |
888 KB |
Output is correct |
27 |
Correct |
29 ms |
908 KB |
Output is correct |
28 |
Correct |
15 ms |
848 KB |
Output is correct |
29 |
Correct |
9 ms |
820 KB |
Output is correct |
30 |
Correct |
2 ms |
852 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
0 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
340 KB |
Output is correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
196 ms |
1464 KB |
Output is correct |
47 |
Correct |
187 ms |
1516 KB |
Output is correct |
48 |
Correct |
2 ms |
852 KB |
Output is correct |
49 |
Correct |
55 ms |
1108 KB |
Output is correct |
50 |
Correct |
165 ms |
1524 KB |
Output is correct |
51 |
Correct |
10 ms |
996 KB |
Output is correct |
52 |
Correct |
103 ms |
1328 KB |
Output is correct |
53 |
Correct |
122 ms |
1564 KB |
Output is correct |
54 |
Correct |
165 ms |
1500 KB |
Output is correct |
55 |
Correct |
50 ms |
1236 KB |
Output is correct |
56 |
Correct |
185 ms |
1444 KB |
Output is correct |
57 |
Correct |
125 ms |
1472 KB |
Output is correct |
58 |
Correct |
23 ms |
976 KB |
Output is correct |
59 |
Correct |
106 ms |
1312 KB |
Output is correct |
60 |
Correct |
16 ms |
988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
35 ms |
924 KB |
Output is correct |
17 |
Correct |
31 ms |
928 KB |
Output is correct |
18 |
Correct |
1 ms |
760 KB |
Output is correct |
19 |
Correct |
10 ms |
852 KB |
Output is correct |
20 |
Correct |
30 ms |
876 KB |
Output is correct |
21 |
Correct |
24 ms |
864 KB |
Output is correct |
22 |
Correct |
3 ms |
852 KB |
Output is correct |
23 |
Correct |
34 ms |
852 KB |
Output is correct |
24 |
Correct |
31 ms |
872 KB |
Output is correct |
25 |
Correct |
18 ms |
788 KB |
Output is correct |
26 |
Correct |
19 ms |
888 KB |
Output is correct |
27 |
Correct |
29 ms |
908 KB |
Output is correct |
28 |
Correct |
15 ms |
848 KB |
Output is correct |
29 |
Correct |
9 ms |
820 KB |
Output is correct |
30 |
Correct |
2 ms |
852 KB |
Output is correct |
31 |
Execution timed out |
3072 ms |
10660 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |