QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#133652 | #4934. Forbidden Card | BoulevardDust# | RE | 2ms | 9812kb | C++17 | 1.3kb | 2023-08-02 12:27:01 | 2023-08-02 12:27:23 |
Judging History
answer
#include <iostream>
#include <cstdio>
#define mn 200005
#define vn 1000005
using namespace std;
int n, m, N, r, a[2][mn];
int fst[vn], v[vn], c[mn], nxt[mn], f[mn], ans[mn];
int main() {
scanf("%d%d", &n, &m);
N = 2 * n + 1;
for(int i = 1; i <= n; ++i) {
scanf("%d%d", &a[0][i], &a[1][i]);
}
for(int i = n + 1; i <= 2 * n; ++i) {
for(int j = 0; j <= 1; ++j) {
a[j][i] = a[j][i - n];
}
}
a[0][N] = a[0][1], a[1][N] = a[1][1];
for(int i = 1; i <= N; ++i) {
if(fst[a[0][i]]) {
if(fst[a[1][i]]) {
r = i; c[r] = 2; break;
}
else {
c[i] = 1, fst[a[1][i]] = i;
}
}
else {
c[i] = 0, fst[a[0][i]] = i;
}
}
// printf("%d\n", r);
// for(int i = 1; i <= m; ++i) {
// printf("%d %d\n", i, fst[i]);
// }
for(int i = r; i >= 1; --i) {
if(v[a[1][i]]) {
nxt[i] = v[a[1][i]];
}
else {
nxt[i] = r;
}
v[a[c[i]][i]] = i;
// printf("%d %d\n", i, nxt[i]);
}
for(int i = r; i >= 1; --i) {
if(c[i] >= 1 || fst[a[1][i]] < i) {
f[i] = i;
}
else {
f[i] = f[nxt[i]];
}
// printf("%d %d\n", i, f[i]);
}
for(int x = 1; x <= m; ++x) {
if(!fst[x]) fst[x] = r;
++ans[f[fst[x]]];
}
ans[1] += ans[N];
for(int i = 1; i <= n; ++i) {
printf("%d\n", ans[i] + ans[i + n]);
}
// n = 1
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 9812kb
input:
3 6 1 2 2 4 4 2
output:
3 0 3
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 7992kb
input:
4 10 1 5 2 6 3 7 4 8
output:
4 2 2 2
result:
ok 4 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 5716kb
input:
1 2 1 2
output:
2
result:
ok single line: '2'
Test #4:
score: -100
Runtime Error
input:
69332 250102 51362 228823 206751 31351 181790 44202 186695 92215 172072 173179 86663 76959 42382 25827 204750 30001 42502 11959 201030 71886 227497 216114 164282 235028 178967 181951 125356 20611 169528 174071 50985 175562 63676 208400 189134 229462 49746 131529 180236 247427 29278 229589 30381 4412...