QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#425094 | #8106. Mosaic | cqbzly | RE | 0ms | 0kb | C++20 | 3.2kb | 2024-05-29 22:07:23 | 2024-05-29 22:07:24 |
answer
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define inf 0x3f3f3f3f
using namespace std;
//不会数据结构
const int N=2005;
int T,n,lx,ly,rx,ry,d[N],h;
int lsh[N],cnt;
int mx[N<<2],pos[N<<2],tag[N<<2],tl[N<<2];
bool vs[N];
struct node{
int x,y;
bool operator <(const node &a)const{
return y<a.y;
}
}a[N],b[N];
bool find(int x){
int p=lower_bound(lsh+1,lsh+1+cnt,x)-lsh;
return p<=cnt&&lsh[p]==x;
}
int get(int x){
return lower_bound(lsh+1,lsh+1+cnt,x)-lsh;
}
vector<int>fk[N];
void build(int p,int l,int r){
tl[p]=l;
if(l==r)return;
int mid=l+r>>1;
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
}
void add(int p,int x){
pos[p]=tl[p],mx[p]=x,tag[p]=x;
}
void pushup(int p){
mx[p]=max(mx[p<<1],mx[p<<1|1]);
pos[p]=(mx[p<<1]>=mx[p<<1|1])?pos[p<<1]:pos[p<<1|1];
}
void pushdown(int p){
if(tag[p]){
add(p<<1,tag[p]);
add(p<<1|1,tag[p]);
tag[p]=0;
}
}
void upd(int p,int l,int r,int ql,int qr,int x){
if(ql<=l&&r<=qr){
add(p,x);
return;
}
int mid=l+r>>1;pushdown(p);
if(ql<=mid)upd(p<<1,l,mid,ql,qr,x);
if(mid<qr)upd(p<<1|1,mid+1,r,ql,qr,x);
pushup(p);
}
pair<int,int>qry(int p,int l,int r,int ql,int qr){
if(ql<=l&&r<=qr)return {mx[p],pos[p]};
int mid=l+r>>1;pushdown(p);
if(qr<=mid)return qry(p<<1,l,mid,ql,qr);
if(mid<ql)return qry(p<<1|1,mid+1,r,ql,qr);
pair<int,int>fl=qry(p<<1,l,mid,ql,qr),fr=qry(p<<1|1,mid+1,r,ql,qr);
return (fl.fi>=fr.fi)?fl:fr;
}
bool work(int p,int x){
vs[p]=1,d[p]=x;int l=a[p].x;
if(find(lsh[l]+x)){
int r=find(lsh[a[p].x]+x);
if(qry(1,1,cnt,l,r-1).fi>a[p].y-x)return 0;
upd(1,1,cnt,l,r-1,a[p].y);
return 1;
}
else{
if(lsh[l]+x<lsh[cnt])return 0;
if(rx==lsh[cnt])rx=lsh[l]+x,h=a[p].y;
else{
if(rx!=lsh[l]+x)return 0;
h=a[p].y;
}
return 1;
}
}
void init(){
for(int i=1;i<=n;i++)fk[i].clear(),vs[i]=0;
for(int i=1;i<=n;i++)fk[a[i].x].pb(i);
}
bool check(){
lx=ly=inf,cnt=0;
for(int i=1;i<=n;i++){
lx=min(lx,a[i].x);
ly=min(ly,a[i].y);
lsh[++cnt]=a[i].x;
}
sort(lsh+1,lsh+1+cnt),cnt=unique(lsh+1,lsh+1+cnt)-lsh-1;
for(int i=1;i<=n;i++)a[i].x=get(a[i].x);
sort(a+1,a+1+n);
bool flg=0;
int p=0;
for(int i=1;i<=n;i++){
if(a[i].x==1){
if(a[i].y==ly)flg=1;
if(!p||a[i].y>a[p].y)p=i;
}
}
if(!flg)return 0;
build(1,1,cnt);
for(int i=2;i<=cnt;i++){
init();
work(p,lsh[i]-lsh[1]);
rx=lsh[cnt],ry=a[p].y+d[p];
add(1,ry),h=ry;
bool flg=1;
while(1){
int x=pos[1],y=mx[1];
if(fk[x].size()==0)break;
if(!work(fk[x].back(),y-a[fk[x].back()].y)){
flg=0;
break;
}
}
if(flg&&h==ly&&mx[1]==ly){
return 1;
}
}
return 0;
}
void opt(){
cout<<"YES"<<" ";
for(int i=1;i<=n;i++)cout<<d[i]<<" ";
cout<<"\n";
}
int main(){
// freopen("triples.in","r",stdin);
// freopen("triples.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>T;
while(T--){
cin>>n;for(int i=1;i<=n;i++)cin>>a[i].x>>a[i].y,b[i]=a[i];
if(n==1){
cout<<"YES 1"<<"\n";
continue;
}
if(check()){opt();continue;}
for(int i=1;i<=n;i++)a[i]=b[i],swap(a[i].x,a[i].y);
if(check()){opt();continue;}
cout<<"NO"<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 2 0 0 0 1 2 3 2 2 3 4 1 1 2 1 3 1 1 2