#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);
if(l[rt] > 1) connect(rt, root(l[rt] - 1));
rt = root(x);
if(r[rt] < m) 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
33 ms |
1332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |