# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
411991 | 2021-05-26T11:47:32 Z | 반딧불(#7584) | Paint (COI20_paint) | C++17 | 72 ms | 28200 KB |
#include <bits/stdc++.h> #define LIM 600 using namespace std; typedef long long ll; int n, m; int arr[200002]; vector<int> link[200002]; int par[200002], sz[200002]; int bigIndex[200002], bigInfo[400000/LIM+3], bigCnt; bool chk[400000/LIM+3][200002]; bool nonsense[400000/LIM+3]; int find(int x){ if(x == par[x]) return x; return par[x] = find(par[x]); } void merge(int x, int y){ x = find(x), y = find(y); if(x==y) return; if(sz[x] < sz[y]) swap(x, y); par[y] = x, sz[x] += sz[y]; int laterSum = (int)link[x].size() + (int)link[y].size(); if(laterSum <= LIM){ if((int)link[x].size() < (int)link[y].size()) link[x].swap(link[y]); for(auto tmp: link[y]){ link[x].push_back(find(tmp)); } link[y].clear(); link[y].shrink_to_fit(); } else if(link[x].size() > LIM){ for(auto tmp: link[y]){ tmp = find(tmp); link[x].push_back(tmp); chk[bigIndex[x]][tmp] = 1; } if((int)link[y].size() > LIM) nonsense[bigIndex[y]] = 1; link[y].clear(); } else if(link[y].size() > LIM){ bigIndex[x] = bigIndex[y]; bigInfo[bigIndex[x]] = x; link[x].swap(link[y]); for(auto tmp: link[y]){ tmp = find(tmp); link[x].push_back(tmp); chk[bigIndex[x]][tmp] = 1; } link[y].clear(); } else{ int pnt = bigCnt++; bigIndex[x] = pnt; bigInfo[pnt] = x; for(auto &tmp: link[x]){ tmp = find(tmp); chk[pnt][tmp] = 1; } for(auto tmp: link[y]){ tmp = find(tmp); link[x].push_back(tmp); chk[pnt][tmp] = 1; } link[y].clear(); } for(int i=0; i<bigCnt; i++){ if(chk[i][y]) chk[i][x] = 1; } } void input(){ scanf("%d %d", &n, &m); for(int i=0; i<n*m; i++) scanf("%d", &arr[i]); for(int i=0; i<n*m; i++){ int r = i/m, c = i%m; par[i] = i, sz[i] = 1; if(r) link[i].push_back(i-m), link[i-m].push_back(i); if(c) link[i].push_back(i-1), link[i-1].push_back(1); } for(int i=0; i<n*m; i++){ int r = i/m, c = i%m; if(r && arr[i] == arr[i-m]) merge(i, i-m); if(c && arr[i] == arr[i-1]) merge(i, i-1); } } void operate(){ int q; scanf("%d", &q); while(q--){ int p, c; scanf("%d %d", &p, &c); p = find((p-1)*m+(c-1)); scanf("%d", &c); for(int i=0; i<bigCnt; i++){ if(!nonsense[i] && chk[i][p] && arr[bigInfo[i]] == arr[p]){ merge(bigInfo[i], p); p = find(p); } } arr[p] = c; if((int)link[p].size() <= LIM){ for(auto &nxt: link[p]){ nxt = find(nxt); if(arr[nxt] == arr[p]){ merge(nxt, p); p = find(p); } } } } } void output(){ for(int i=0; i<n*m; i++){ printf("%d ", arr[find(i)]); if(i%m == m-1) puts(""); } } int main(){ input(); operate(); output(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 19 ms | 10060 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 27 ms | 14544 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 72 ms | 28200 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 65 ms | 23672 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |