QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#183293 | #7105. Pixel Art | PlentyOfPenalty | WA | 0ms | 13256kb | C++14 | 3.5kb | 2023-09-19 13:13:18 | 2023-09-19 13:13:18 |
Judging History
answer
#include<bits/stdc++.h>
#define pi pair<int,int>
#define ppi pair<pi,int>
#define l first
#define r second
#define it set<int>::iterator
#define iit set<ppi>::iterator
using namespace std;
const int N=1e5;
int n,m,Q,op,p,li,ri,ls,p1,p2,m1,m2,fa[N*10+10],cnt,ans;
int vis[N+10];
vector<pi>rw[N+10],cl[N+10];
vector<int>ad[N+10],dl[N+10];
set<int>ap;
set<ppi>c;
void Ins(int x){
//cout<<"INS "<<x<<"\n";
iit iv=c.upper_bound((ppi){(pi){x,m},cnt});
if(iv!=c.begin()){
--iv;
int tl=(*iv).l.l,tr=(*iv).l.r,tf=(*iv).r;
//cout<<"FIND["<<tl<<","<<tr<<"] tf="<<tf<<"\n";
assert(tl<x);
if(tr>x){
//cout<<"?\n";
it i=ap.lower_bound(x),j=i;
--j;
c.erase(iv),c.insert((ppi){(pi){tl,*j},tf}),c.insert((ppi){(pi){*i,tr},tf});
}
}
c.insert((ppi){(pi){x,x},++cnt}),fa[cnt]=cnt,++ans;
//cout<<"ELEMS:\n";
//for(iit tmp=c.begin();tmp!=c.end();++tmp)cout<<(*tmp).l.l<<" "<<(*tmp).l.r<<"\n";
ap.insert(x);
}
void Del(int x){
//cout<<"DEL "<<x<<"\n";
ap.erase(ap.find(x));
iit iv=c.upper_bound((ppi){(pi){x,m},cnt});
--iv;
int tl=(*iv).l.l,tr=(*iv).l.r,tf=(*iv).r;
//cout<<"IV:["<<tl<<" "<<tr<<"] tf="<<tf<<"\n";
assert(tl<=x&&x<=tr);
if(tl==tr)return(void)(c.erase(iv));
if(tl==x){
int ti=*ap.lower_bound(x);
c.erase(iv),c.insert((ppi){(pi){ti,tr},tf});
}else if(tr==x){
int ti=*--ap.lower_bound(x);
c.erase(iv),c.insert((ppi){(pi){tl,ti},tf});
}
//cout<<"ELEMS:\n";
//for(iit tmp=c.begin();tmp!=c.end();++tmp)cout<<"["<<(*tmp).l.l<<" "<<(*tmp).l.r<<"]\n";
}
int getf(int x){
return fa[x]==x?x:fa[x]=getf(fa[x]);
}
void Mrg(int x,int y){
if(getf(x)==y)return;
--ans;
fa[getf(x)]=y;
}
void Merge(int l,int r){
//cout<<"MERGE "<<l<<" "<<r<<"\n";
iit i=c.upper_bound((ppi){(pi){r,m},cnt}),j;
//if(i==c.end())cout<<"i=END.\n";
int tl=0,tr,ti;
while(i!=c.begin()&&(!tl||!(tl<=l&&r<=tr))){
j=i,--j;
//cout<<"["<<(*j).l.l<<","<<(*j).l.r<<"]\n";
if((*j).l.r<l)break;
if(!tl)tl=(*j).l.l,tr=(*j).l.r,ti=getf((*j).r);
else tl=(*j).l.l,Mrg((*j).r,ti);
c.erase(j);
}
if(tl)c.insert((ppi){(pi){tl,tr},ti});
}
int main(){
scanf("%d%d%d",&n,&m,&Q);
for(int i=1;i<=Q;++i){
scanf("%d%d%d%d",&op,&p,&li,&ri);
if(op){
cl[p].push_back((pi){li,ri});
rw[li].push_back((pi){p,p}),rw[ri].push_back((pi){p,p});
}else rw[p].push_back((pi){li,ri});
}
for(int i=1;i<=n;++i)if(rw[i].size())sort(rw[i].begin(),rw[i].end());
for(int i=1;i<=n;++i){
ls=0,p1=p2=m1=m2=0;
for(pi j:rw[i])if(j.l!=ls){
while(p1<rw[i-1].size()&&rw[i-1][p1].l<=j.l)m1=max(m1,rw[i-1][p1++].r);
while(p2<rw[i+1].size()&&rw[i+1][p2].l<=j.l)m2=max(m2,rw[i+1][p2++].r);
cl[j.l].push_back((pi){i-(m1>=j.l),i-(m2>=j.l)});
ls=j.l;
}
}
for(int i=1;i<=m;++i)for(pi j:cl[i])ad[j.l].push_back(i),dl[j.r+1].push_back(i);
for(int i=1;i<=n;++i){
//cout<<"----------------------i="<<i<<"\n";
for(int j:dl[i])--vis[j];
for(int j:ad[i])++vis[j];
for(int j:dl[i])if(!vis[j]&&ap.find(j)!=ap.end())Del(j);
for(int j:ad[i])if(ap.find(j)==ap.end())Ins(j);
for(pi j:rw[i])Merge(max(1,j.l-1),min(m,j.r+1));
printf("%d\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 13256kb
input:
3 2 5 2 1 1 1 2 2 3 2 5 2 5 2 1 1 1 3 2 3 2 5 3 3 3 1 1 1 2 3 1 3 2 1 3 2 3
output:
1 1 1
result:
wrong answer 1st lines differ - expected: '2 1', found: '1'