답안 #559105

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
559105 2022-05-09T11:39:48 Z leaked Paint (COI20_paint) C++17
0 / 100
304 ms 494496 KB
#include <bits/stdc++.h>

#define f first
#define s second
#define m_p make_pair
#define vec vector
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)(x).size()
#define pw(x) (1LL<<(x))

using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
const int N=2e5+1;
const int K=4000;
vec<int> who[2*N/K+1][N];
int idt;
int c[N];
int id[N],p[N];
vec<int> neig[N];

vec<int> with[N];
bool u[N][2*N/K+1];
vec<int> bigs;

int n,m;
int ii(int i,int j){
    return i*m+j;
}
void make(int v){
    id[v]=-1;p[v]=v;
}
int get(int v){
    return p[v]=(p[v]==v?v:get(p[v]));
}
void mg(int a,int b){
    a=get(a),b=get(b);
    if(a==b) return;
    if(sz(neig[a])>sz(neig[b])) swap(a,b);
    p[a]=b;
    for(auto &z : neig[a]){
        if(get(z)==b) continue;
        neig[b].pb(z);
        if(id[get(z)]!=-1){
            int j=id[get(z)];
            if(!u[b][j]){
                u[b][j]=1;
                with[b].pb(get(z));
            }
        }
    }


    if(id[b]==-1 && sz(neig[b])>=K){
        id[b]=idt++;
        bigs.pb(b);
        for(auto &z : neig[b]){
            if(get(z)==b) continue;
            who[id[b]][c[get(z)]].pb(z);
            if(!u[get(z)][id[b]]){
                u[get(z)][id[b]]=1;
                with[get(z)].pb(b);
            }
        }
    }
    else if(id[b]!=-1){
        for(auto &z : neig[a]){
            if(get(z)==b) continue;
            who[id[b]][c[get(z)]].pb(z);
            if(!u[get(z)][id[b]]){
                u[get(z)][id[b]]=1;
                with[get(z)].pb(b);
            }
        }
    }
    for(auto &z : with[b]){
        who[z][c[b]].pb(b);
    }
    neig[a].clear();
}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=0;i<n*m;i++)
        make(i);
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)
            cin>>c[ii(i,j)];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(i){
                if(c[ii(i-1,j)]==c[ii(i,j)])
                    mg(ii(i,j),ii(i-1,j));
                else
                    neig[get(ii(i,j))].pb(ii(i-1,j)),neig[get(ii(i-1,j))].pb(ii(i,j));
            }
            if(j){
                if(c[ii(i,j-1)]==c[ii(i,j)])
                    mg(ii(i,j),ii(i,j-1));
                else
                    neig[get(ii(i,j))].pb(ii(i,j-1)),neig[get(ii(i,j))].pb(ii(i,j-1));
            }
        }
    }
    auto colour=[&](int v,int ct){
        c[v]=ct;
        if(id[v]!=-1){
            vec<int> kek=who[id[v]][ct];
            who[id[v]][ct].clear();
            for(auto &z : kek)
                mg(v,z);
        }
        else{
            vec<int> kek=neig[v];
            for(auto &z : kek){
                if(c[v]==c[get(z)])
                    mg(v,z);
            }
        }
    };
    int q;
    cin>>q;
    for(int t=0;t<q;t++){
        int i,j,ct;
        cin>>i>>j>>ct;--i;--j;
        colour(get(ii(i,j)),ct);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)
            cout<<c[get(ii(i,j))]<<' ';
        cout<<'\n';
    }
    return 0;
}
/*
16 5
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 216 ms 484080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 262 ms 487156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 281 ms 494496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 304 ms 492220 KB Output isn't correct
2 Halted 0 ms 0 KB -