#include <bits/stdc++.h>
#define int long long
#define ii pair<int,int>
#define F first
#define S second
#define du long double
using namespace std;
int n,m;
const int N=2e5+10;
vector<int> idx[N];
int p[N];
set<int> st[N];
int a[N];
int x[]={0,0,1,-1};
int y[]={1,-1,0,0};
vector<int> vec;
bool out(int i,int j)
{
cout<<i<<" "<<j<<endl;
bool ans=i<1||j<1||i>n||j>m;
return ans;
}
int find(int u)
{
if(u==p[u])return u;
return p[u]=find(p[u]);
}
void compine(int u,int v)
{
u=find(u);
v=find(v);
if(u==v)return;
if(st[u].size()>st[v].size()){
swap(u,v);
}
for(auto x:st[u]){
st[v].insert(x);
}
st[v].erase(u);
p[u]=v;
}
void fix()
{
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
int x=idx[i][j];
x=find(x);
x=a[x];
cout<<x<<" ";
}
cout<<endl;
}
}
void solve()
{
cin>>n>>m;
for(int i=1;i<=n;i++){
idx[i].resize(m+10);
}
int cnt=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cnt++;
p[cnt]=cnt;
idx[i][j]=cnt;
cin>>a[cnt];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
vec.clear();
int u=idx[i][j];
int c=a[u];
for(int k=0;k<4;k++){
int ni=i+x[k];
int nj=j+y[k];
if(out(ni,nj))continue;
int v=idx[ni][nj];
int nc=a[v];
if(c==nc){
vec.push_back(v);
}
else st[u].insert(v);
}
for(auto x:vec){
cout<<x<<endl;
compine(u,x);
}
}
}
int q;
cin>>q;
while(q--){
// cout<<"\n\n";
// fix();
// cout<<"\n\n";
int c,i,j;
cin>>i>>j>>c;
int u=idx[i][j];
u=find(u);
a[u]=c;
if(!q){
// cout<<c<<endl;
}
vec.clear();
for(auto x:st[u]){
int xx=find(x);
if(a[xx]==c)vec.push_back(xx);
}
for(auto x:vec){
compine(u,x);
}
}
fix();
}
main()
{
//freopen(".in","r",stdin);freopen(".out","w",stdout);
int t=1;
// cin>>t;
while(t--)solve();
}
Compilation message
paint.cpp:120:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
120 | main()
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
14468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
501 ms |
23152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3086 ms |
71268 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1407 ms |
51224 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |