This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int mi[N], mx[N], par[N], color[N];
int root(int x)
{
if(par[x] == x) return x;
return par[x] = root(par[x]);
}
void merge(int a, int b)
{
a = root(a), b = root(b);
if(a == b) return;
par[a] = b;
mi[b] = min(mi[a], mi[b]);
mx[b] = max(mx[a], mx[b]);
}
int main()
{
int r, c;
cin >> r >> c;
for(int i = 0; i < c; i ++)
mx[i] = mi[i] = par[i] = i;
int a[r][c];
for(int i = 0; i < r; i ++)
for(int j = 0; j < c; j ++)
{
cin >> a[i][j];
color[j] = a[i][j];
}
int q;
cin >> q;
while(q--)
{
int i, j, col;
cin >> i >> j >> col;
j--;
i = root(j);
color[i] = col;
if(mx[i] + 1 < c && color[root(mx[i] + 1)] == col)
merge(i, mx[i] + 1);
if(mi[i] > 0 && color[root(mi[i] - 1)] == col)
merge(i, mi[i] - 1);
}
for(int i = 0; i < c; i ++)
cout << color[root(i)] << ' ';
cout << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |