Ask for ABC477D
2026-09-26 21:53:55
发布于:江西
Who can help me? Thanks so much!
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 300005;
int chs[N]; // 1 for has chess, 0 for has no chess
char lz = 'a'; // lazy tag
char cl[N]; // the cell's color
int main() {
int n, q;
cin >> n >> q;
while (q--) {
int op;
cin >> op;
if (op == 1) {
int x;
cin >> x;
if (!chs[x]) { // the cell has no chess, use lazy tag and put a chess
cl[x] = lz;
chs[x] = 1;
} else { // the cell has chess
chs[x] = 0;
}
} else { // op 2, get a new lazy tag
char c;
cin >> c;
lz = c;
}
}
for (int i = 1; i <= n; i++) {
if (chs[i]) cout << cl[i]; // the cell has chess, output the cell's color
else cout << lz; // the cell has no chess, output lazy tag
}
cout << endl;
return 0;
}
全部评论 4
省流:楼主在 florr 和外国人深入交流之后魔怔了
1周前 来自 浙江
1Don't attention it.
1周前 来自 江西
0https://www.luogu.com.cn/ticket/TTRF863552
1周前 来自 浙江
0我英语不至于这么差吧?
1周前 来自 江西
0
正解是一个时光倒流的写法,先算出最后时刻每个格子是否被覆盖。然后反推,每次染色时检查答案还未确定且当前未被覆盖的格子,将他们标记并确定答案;每次修改时如果修改后是不被覆盖的则加入一个队列(实际上就是找每个格子的最后一次有效染色)。实现时用一个vector即可。
1周前 来自 上海
0其实 lz 已经会做了
1周前 来自 浙江
0没事也当是写口胡题解
1周前 来自 上海
0
呃呃呃不会是对18个点错13个点吧
1周前 来自 上海
0对,但是理论上你错的点应该比他多(
1周前 来自 浙江
0、
1周前 来自 上海
0Yes.
1周前 来自 江西
0
嗯,对我很有帮助
1周前 来自 新疆
0






























有帮助,赞一个