版本比较
题解:P14659 病毒传播
正文
增加 9 行删除 9 行
36 行未改动37383940414142434444454647489 行未改动5859606162626364646566676810 行未改动79808182838384858686878889902 行未改动939495969797989910010110210310410410510610610710810936 行未改动
int main() { cin >> n >> q; for (int j = 1; j <= n; ++ j) cin >> i[j], m[j] = true;
while (q --) { cin >> x;
if (m[x]) { m[x] = 0; if (i[x] == 1) ++ k; else s.insert(x);9 行未改动 k += s.size(); s.clear(); } }
for (int j = 1; j <= n; ++ j) cout << i[j] << ' ';
return 0;}```
10 行未改动
int main() { cin >> n >> q; for (int j = 1; j <= n; ++ j) cin >> i[j], m[j] = true; // 输入和初始化
while (q --) { cin >> x;
if (m[x]) { // 脱下口罩 m[x] = 0; if (i[x] == 1) ++ k; else s.insert(x);2 行未改动 m[x] = 1; if (i[x] == 1) -- k; else s.erase(x); }
if (k > 0 && !s.empty()) { // 之后的更新 for (int p: s) i[p] = 1; k += s.size(); s.clear(); } }
for (int j = 1; j <= n; ++ j) cout << i[j] << ' '; // 输出
return 0;}```