# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
791564 |
2023-07-24T07:29:01 Z |
GEN 이지후(#10078) |
Sličnost (COI23_slicnost) |
C++17 |
|
3000 ms |
524288 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 = 530000;
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<int>> dx(n + 1, vector<int>(n + 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);
dx[x1][y1]++;
dx[x1][y2]--;
dx[x2][y1]--;
dx[x2][y2]++;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (j)
dx[i][j] += dx[i][j - 1];
if (i)
dx[i][j] += dx[i - 1][j];
if (i && j)
dx[i][j] -= dx[i - 1][j - 1];
}
}
}
auto query = [&]() {
lint mx = 0, mxc = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (mx < dx[i][j]) {
mx = dx[i][j];
mxc = 0;
}
if (mx == dx[i][j]) {
mxc++;
}
}
}
if (mx == 0)
mxc = 1ll * (n - k + 1) * (n - k + 1);
cout << mx << " " << mxc << "\n";
};
auto rangeAdd = [&](int p, int l, int r, int d) {
if (p < k - 1 || p >= n)
return;
l = max(l, k - 1);
r = min(r, n);
for (int i = l; i < r; i++)
dx[p][i] += d;
};
query();
while (q--) {
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);
rangeAdd(r1[p1] + k, r2[p1], r2[p1] + k, +1);
rangeAdd(r1[p2] + k - 1, r2[p2], r2[p2] + k, -1);
rangeAdd(r1[p2] - 1, r2[p2], r2[p2] + k, +1);
r1[p1]++;
r1[p2]--;
query();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
272 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
272 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
170 ms |
94096 KB |
Output is correct |
17 |
Correct |
167 ms |
92856 KB |
Output is correct |
18 |
Correct |
165 ms |
93036 KB |
Output is correct |
19 |
Correct |
177 ms |
94144 KB |
Output is correct |
20 |
Correct |
183 ms |
98128 KB |
Output is correct |
21 |
Correct |
163 ms |
90944 KB |
Output is correct |
22 |
Correct |
177 ms |
97476 KB |
Output is correct |
23 |
Correct |
164 ms |
89596 KB |
Output is correct |
24 |
Correct |
182 ms |
94576 KB |
Output is correct |
25 |
Correct |
165 ms |
88980 KB |
Output is correct |
26 |
Correct |
183 ms |
96260 KB |
Output is correct |
27 |
Correct |
170 ms |
90608 KB |
Output is correct |
28 |
Correct |
168 ms |
90260 KB |
Output is correct |
29 |
Correct |
177 ms |
96300 KB |
Output is correct |
30 |
Correct |
170 ms |
93780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
272 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
170 ms |
94096 KB |
Output is correct |
17 |
Correct |
167 ms |
92856 KB |
Output is correct |
18 |
Correct |
165 ms |
93036 KB |
Output is correct |
19 |
Correct |
177 ms |
94144 KB |
Output is correct |
20 |
Correct |
183 ms |
98128 KB |
Output is correct |
21 |
Correct |
163 ms |
90944 KB |
Output is correct |
22 |
Correct |
177 ms |
97476 KB |
Output is correct |
23 |
Correct |
164 ms |
89596 KB |
Output is correct |
24 |
Correct |
182 ms |
94576 KB |
Output is correct |
25 |
Correct |
165 ms |
88980 KB |
Output is correct |
26 |
Correct |
183 ms |
96260 KB |
Output is correct |
27 |
Correct |
170 ms |
90608 KB |
Output is correct |
28 |
Correct |
168 ms |
90260 KB |
Output is correct |
29 |
Correct |
177 ms |
96300 KB |
Output is correct |
30 |
Correct |
170 ms |
93780 KB |
Output is correct |
31 |
Runtime error |
172 ms |
524288 KB |
Execution killed with signal 9 |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
272 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
280 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
272 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
170 ms |
94096 KB |
Output is correct |
17 |
Correct |
167 ms |
92856 KB |
Output is correct |
18 |
Correct |
165 ms |
93036 KB |
Output is correct |
19 |
Correct |
177 ms |
94144 KB |
Output is correct |
20 |
Correct |
183 ms |
98128 KB |
Output is correct |
21 |
Correct |
163 ms |
90944 KB |
Output is correct |
22 |
Correct |
177 ms |
97476 KB |
Output is correct |
23 |
Correct |
164 ms |
89596 KB |
Output is correct |
24 |
Correct |
182 ms |
94576 KB |
Output is correct |
25 |
Correct |
165 ms |
88980 KB |
Output is correct |
26 |
Correct |
183 ms |
96260 KB |
Output is correct |
27 |
Correct |
170 ms |
90608 KB |
Output is correct |
28 |
Correct |
168 ms |
90260 KB |
Output is correct |
29 |
Correct |
177 ms |
96300 KB |
Output is correct |
30 |
Correct |
170 ms |
93780 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
2 ms |
280 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Execution timed out |
3058 ms |
94092 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
272 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
170 ms |
94096 KB |
Output is correct |
17 |
Correct |
167 ms |
92856 KB |
Output is correct |
18 |
Correct |
165 ms |
93036 KB |
Output is correct |
19 |
Correct |
177 ms |
94144 KB |
Output is correct |
20 |
Correct |
183 ms |
98128 KB |
Output is correct |
21 |
Correct |
163 ms |
90944 KB |
Output is correct |
22 |
Correct |
177 ms |
97476 KB |
Output is correct |
23 |
Correct |
164 ms |
89596 KB |
Output is correct |
24 |
Correct |
182 ms |
94576 KB |
Output is correct |
25 |
Correct |
165 ms |
88980 KB |
Output is correct |
26 |
Correct |
183 ms |
96260 KB |
Output is correct |
27 |
Correct |
170 ms |
90608 KB |
Output is correct |
28 |
Correct |
168 ms |
90260 KB |
Output is correct |
29 |
Correct |
177 ms |
96300 KB |
Output is correct |
30 |
Correct |
170 ms |
93780 KB |
Output is correct |
31 |
Runtime error |
172 ms |
524288 KB |
Execution killed with signal 9 |
32 |
Halted |
0 ms |
0 KB |
- |