QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#65120 | #5113. Bridge | P500 | TL | 1461ms | 55764kb | C++17 | 1.9kb | 2022-11-27 17:30:25 | 2022-11-27 17:30:29 |
Judging History
answer
/*
The 2022 ICPC Asia Xi’an Regional Contest
Problem A. Bridge
*/
#include <bits/stdc++.h>
using namespace std;
constexpr int N = (int)1e5 + 5;
int qt[N], x[N], y[N], Y[N], S[N], a[N], J[N], L[640], R[640], id[N], cnt, f[640][N];
int main() {
cin.tie(0)->ios::sync_with_stdio(false);
int n, m, q;
cin >> n >> m >> q;
for (int i = 0; i < q; i++) {
cin >> qt[i];
if (qt[i] == 1) cin >> x[i] >> y[i];
else cin >> x[i];
}
for (int i = 0; i < q; i++) if (qt[i] == 1) Y[y[i]]++;
for (int i = 1; i <= m; i++) S[i] = S[i - 1] + Y[i];
int bn = sqrt(m + 1) + 10;
if(m > 4e5) bn = 10 * sqrt(m + 1);
for (int l = 1, r = 1, tot = 0; l <= m; l = r, tot = 0) {
while (r <= m and tot < bn) tot += Y[r++];
if (Y[r - 1] >= bn and l + 1 != r) {
L[cnt] = l; R[cnt] = r - 2; cnt++;
L[cnt] = r - 1; R[cnt] = r - 1; cnt++;
}
else {
L[cnt] = l; R[cnt] = r - 1; cnt++;
}
}
for (int i = 0; i < cnt; i++)
for (int j = 1; j <= n; j++) f[i][j] = j;
for (int i = 0; i <= cnt; i++)
for (int j = L[i]; j <= R[i]; j++) id[j] = i;
for (int i = 1; i <= m; i++) J[i] = S[i - 1];
for (int t = 0; t < q; t++) {
if (qt[t] == 1) {
int k = id[y[t]];
if (L[k] == R[k]) swap(f[k][x[t]], f[k][x[t] + 1]);
else {
a[J[y[t]]++] = x[t];
for (int i = 1; i <= m; i++) f[k][i] = i;
for (int i = R[k]; i >= L[k]; i--)
for (int j = S[i - 1]; j < J[i]; j++)
swap(f[k][a[j]], f[k][a[j] + 1]);
}
}
else {
int answer = x[t];
for (int i = 0; i < cnt; i++) answer = f[i][answer];
cout << answer << '\n';
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5552kb
input:
3 4 13 2 2 1 1 3 2 1 2 2 2 3 1 2 4 2 1 2 2 2 3 1 2 1 2 1 2 2 2 3
output:
2 2 1 3 3 1 2 3 2 1
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 1461ms
memory: 55764kb
input:
3 100000 99997 2 2 2 2 2 3 2 3 2 3 2 3 2 3 1 2 11047 1 1 98732 1 2 90045 1 1 43556 2 1 2 3 1 2 17242 1 1 17027 2 1 1 1 94195 2 1 2 2 2 1 2 3 1 1 34124 1 2 14354 1 2 673 1 2 39812 1 2 35520 1 2 16046 2 3 2 2 1 1 25410 2 3 2 1 2 3 2 2 1 2 55684 2 1 1 2 24811 1 2 92268 1 2 60268 2 2 1 1 89272 1 2 19232...
output:
2 2 3 3 3 3 3 3 2 1 2 1 2 3 3 1 1 2 1 3 3 2 1 3 2 1 2 1 2 2 2 2 1 1 2 1 3 2 1 3 2 1 3 2 2 1 3 3 2 3 2 3 1 2 1 1 2 3 2 1 3 2 3 2 3 2 2 1 1 2 1 1 2 3 2 1 1 3 1 1 2 2 3 2 2 1 1 1 2 3 3 1 1 2 1 1 3 1 3 2 3 2 3 2 2 2 3 3 2 2 2 3 3 2 2 2 3 1 2 1 1 3 2 3 2 2 2 1 1 1 3 3 3 2 1 1 3 3 3 1 1 2 3 2 3 3 3 3 2 3 ...
result:
ok 60761 numbers
Test #3:
score: 0
Accepted
time: 2ms
memory: 3740kb
input:
100000 5 20 1 40277 1 2 55431 2 22404 2 29137 2 10206 2 72758 2 92880 1 96104 2 2 12641 1 99618 2 2 88481 1 76531 3 1 91957 5 1 23999 2 2 35922 1 69730 5 1 16353 2 1 90312 1 1 75264 5 2 77283
output:
55431 22404 29137 10206 72758 92880 12641 88481 35922 77283
result:
ok 10 numbers
Test #4:
score: 0
Accepted
time: 2ms
memory: 3440kb
input:
3 5 20 2 3 1 2 2 2 3 1 1 4 2 1 1 2 5 1 1 1 2 1 2 2 2 1 2 1 2 2 2 3 2 3 2 1 2 1 2 1 2 3 2 2 2 3
output:
3 2 2 2 3 2 2 3 1 1 2 2 2 1 3 1
result:
ok 16 numbers
Test #5:
score: -100
Time Limit Exceeded
input:
200 100000 99995 1 180 45150 2 137 1 97 78979 1 14 74747 1 151 41036 1 178 88736 1 26 50618 1 132 72623 1 95 37475 2 184 1 31 44675 1 183 14874 1 66 14597 2 191 2 102 1 27 61558 1 36 39304 2 119 2 185 1 156 50000 2 200 2 152 1 17 51778 1 39 39403 2 168 1 50 67213 1 92 56771 2 28 2 196 1 99 29006 2 4...
output:
137 184 191 102 119 185 200 151 168 27 196 43 73 16 28 64 88 106 139 117 90 131 64 64 107 11 38 149 133 184 166 20 95 185 71 85 151 96 106 103 91 45 195 112 82 113 183 178 47 112 12 185 41 153 77 179 44 165 84 111 192 161 144 33 139 9 37 38 177 45 146 83 88 166 1 180 175 180 12 166 186 44 2 115 124 ...