Submission #557750

#TimeUsernameProblemLanguageResultExecution timeMemory
557750Yazan_AlattarPaint (COI20_paint)C++14
9 / 100
55 ms6308 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define F first #define S second #define pb push_back #define endl "\n" #define all(x) x.begin(), x.end() const int M = 500007; const ll inf = 2e9; const ll mod = 1e9 + 7; const double pi = acos(-1); const double eps = 1e-6; const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0}; const int block = 320; int n, m, col[M], l[M], r[M], p[M], sz[M]; int root(int x){ while(p[x] != x){ p[x] = p[p[x]]; x = p[x]; } return x; } void connect(int x, int y){ x = root(x); y = root(y); if(x == y) return; if(sz[x] > sz[y]) swap(x, y); p[x] = y; sz[y] += sz[x]; l[y] = min(l[y], l[x]); r[y] = max(r[y], r[x]); return; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 1; i <= m; ++i){ cin >> col[i]; p[i] = i; sz[i] = 1; l[i] = r[i] = i; if(i > 1 && col[i] == col[i - 1]) connect(i, i - 1); } int q; cin >> q; while(q--){ int x, c; cin >> x >> x >> c; if(col[root(x)] == c) continue; int rt = root(x); col[rt] = c; if(l[rt] > 1 && col[root(l[rt] - 1)] == c) connect(rt, root(l[rt] - 1)); rt = root(x); if(r[rt] < m && col[root(r[rt] + 1)] == c) connect(rt, root(r[rt] + 1)); col[root(x)] = c; } for(int i = 1; i <= m; ++i) cout << col[root(i)] << " "; cout << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...