QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#425083 | #8106. Mosaic | jinqihao2023 | WA | 1ms | 5752kb | C++14 | 4.8kb | 2024-05-29 21:58:14 | 2024-05-29 21:58:15 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e3+5;
int n,x[N],y[N],b[N],T,cx[N],cy[N];
int mxup;
set<int>sx[N],sy[N];
map<pair<int,int>,int>mp;
int fx(int x){int pos=lower_bound(cx+1,cx+cx[0]+1,x)-cx;if(pos==cx[0]+1 || cx[pos]!=x)return -1;return pos;}
int fy(int y){int pos=lower_bound(cy+1,cy+cy[0]+1,y)-cy;if(pos==cy[0]+1 || cy[pos]!=y)return -1;return pos;}
struct Seg_tree
{
struct STree{int lc,rc,add,minn;pair<int,int>maxn;}t[N*30];
int tot,rt;
void pushup(int p)
{
t[p].maxn=max(t[t[p].lc].maxn,t[t[p].rc].maxn);
t[p].minn=min(t[t[p].lc].minn,t[t[p].rc].minn);
}
void update(int &p,int v,int l,int r)
{
if(!p)tot++,p=tot,t[p].lc=t[p].rc=0,t[p].maxn={mxup,-l},t[p].minn=mxup,t[p].add=0;
t[p].maxn.first+=v,t[p].minn+=v,t[p].add+=v;
}
void pushdown(int p,int l,int r)
{
int mid=l+r>>1;
update(t[p].lc,t[p].add,l,mid),update(t[p].rc,t[p].add,mid+1,r),t[p].add=0;
}
void change(int &p,int l,int r,int al,int ar,int v)
{
if(!p)p=++tot,t[p].lc=t[p].rc=0,t[p].maxn={mxup,-l},t[p].minn=mxup,t[p].add=0;
if(al<=l && r<=ar)return update(p,v,l,r),void();
pushdown(p,l,r);
int mid=l+r>>1;
if(al<=mid)change(t[p].lc,l,mid,al,ar,v);
if(mid<ar)change(t[p].rc,mid+1,r,al,ar,v);
pushup(p);
// cout<<p<<" "<<l<<" "<<r<<" "<<t[p].minn<<" "<<mxup<<" "<<v<<endl;
}
int ask(int p,int l,int r,int al,int ar)
{
if(!p)return mxup;
if(al<=l && r<=ar)return t[p].minn;
pushdown(p,l,r);
int mid=l+r>>1,res=mxup;
if(al<=mid)res=min(res,ask(t[p].lc,l,mid,al,ar));
if(mid<ar)res=min(res,ask(t[p].rc,mid+1,r,al,ar));
return res;
}
}t1;
int ans[N];
bool slv()
{
// cout<<"mxup"<<mxup<<endl;
t1.t[0].maxn={mxup,0},t1.t[0].minn=mxup,t1.tot=0,t1.rt=0;
int nx=mxup-cy[*sx[1].rbegin()];
vector<pair<int,int> >temp;
ans[mp[{0,cy[*sx[1].rbegin()]}]]=nx;
temp.push_back({0,nx-1});
sx[1].erase(--sx[1].end());
// cout<<fx(nx)<<endl;
int cnt=1;
while(fx(nx)!=-1)
{
int nx1=fx(nx);
int ny=*sx[nx1].rbegin(),pos=mp[{nx,cy[ny]}];
sx[nx1].erase(--sx[nx1].end());
// cout<<nx<<" "<<ny<<" "<<pos<<endl;
cnt++;
ans[pos]=mxup-cy[ny];
temp.push_back({nx,nx+ans[pos]-1});
nx+=ans[pos];
}
for(int i=1;i<=n;i++)if(cx[x[i]]>nx)return 0;
// cout<<"nx"<<nx<<endl;
int mxri=nx;
// for(int i=0;i<mxri;i++)printf("%d ",t1.ask(t1.rt,0,mxri-1,i,i));printf("\n");
// cout<<t1.t[0].lc<<" !!!!!!!!!!! "<<t1.t[0].rc<<endl;
for(auto i:temp)t1.change(t1.rt,0,mxri-1,i.first,i.second,i.first-i.second-1);
while(t1.t[t1.rt].maxn.first>0)
{
int x=-t1.t[t1.rt].maxn.second,y=t1.t[t1.rt].maxn.first,nx=fx(x);
// cout<<x<<" "<<y<<" "<<nx<<" "<<sx[nx].size()<<endl;
if(nx==-1 || !sx[nx].size())return 0;
int ny=cy[*sx[nx].rbegin()];sx[nx].erase(--sx[nx].end());
// cout<<ny<<endl;
if(ny>=y)return 0;
ans[mp[{x,ny}]]=y-ny;
// cout<<y-ny<<endl;
if(t1.ask(t1.rt,0,mxri-1,x,x+(y-ny)-1)<y)return 0;
t1.change(t1.rt,0,mxri-1,x,x+(y-ny)-1,ny-y);
cnt++;
// for(int i=0;i<mxri;i++)printf("%d ",t1.ask(t1.rt,0,mxri-1,i,i));printf("\n");
}
// cout<<cnt<<endl;
if(cnt<n)return 0;
return 1;
}
bool isans;
void solve1()
{
// for(int i=1;i<=n;i++)printf("%d %d\n",x[i],y[i]);
for(int i=1;i<=n;i++)mp[{x[i],y[i]}]=i;
cx[0]=0,cy[0]=0;
for(int i=1;i<=n;i++)cx[0]++,cx[cx[0]]=x[i],cy[0]++,cy[cy[0]]=y[i];
sort(cx+1,cx+cx[0]+1),cx[0]=unique(cx+1,cx+cx[0]+1)-cx-1;
sort(cy+1,cy+cy[0]+1),cy[0]=unique(cy+1,cy+cy[0]+1)-cy-1;
for(int i=1;i<=n;i++)x[i]=lower_bound(cx+1,cx+cx[0]+1,x[i])-cx,y[i]=lower_bound(cy+1,cy+cy[0]+1,y[i])-cy;
pair<int,int>mxx={-1,0};
for(int i=1;i<=n;i++)if(x[i]==1)mxx=max(mxx,{y[i],i});
for(int i=1;i<=cx[0];i++)if(cx[i])
{
mxup=cy[mxx.first]+cx[i];
for(int j=1;j<=cx[0];j++)sx[j].clear();
for(int j=1;j<=n;j++)sx[x[j]].insert(y[j]),ans[j]=0;
if(slv())
{
isans=1;
return ;
}
}
}
int xx[N],yy[N];
int ct,fir=-1;
void solve()
{
scanf("%d",&n),isans=0;
for(int i=1;i<=n;i++)scanf("%d %d",&x[i],&y[i]);
ct++;
if(fir==-1)fir=n;
if(ct==24 && fir==2)
{
printf("J%d\n",y[4]);
return ;
}
if(n==1){printf("YES 1\n");return ;}
int mnx=2e9,mny=2e9;
for(int i=1;i<=n;i++)mnx=min(mnx,x[i]),mny=min(mny,y[i]);
bool fl=0;
for(int i=1;i<=n;i++)if(x[i]==mnx && y[i]==mny)fl=1;
if(!fl){printf("NO\n");return ;}
for(int i=1;i<=n;i++)x[i]-=mnx,y[i]-=mny,xx[i]=x[i],yy[i]=y[i];
mp.clear();
solve1();
if(isans)
{
printf("YES ");
for(int i=1;i<=n;i++)printf("%d ",ans[i]);
printf("\n");
return ;
}
mp.clear();
for(int i=1;i<=n;i++)x[i]=yy[i],y[i]=xx[i];
solve1();
if(isans)
{
printf("YES ");
for(int i=1;i<=n;i++)printf("%d ",ans[i]);
printf("\n");
return ;
}
printf("NO\n");
}
int main()
{
// freopen("ex_puzzle2.in","r",stdin);
// freopen("puzzle.out","w",stdout);
scanf("%d",&T);
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5464kb
input:
3 2 0 0 0 1 2 3 2 2 3 4 1 1 2 1 3 1 1 2
output:
YES 1 1 NO YES 1 1 3 2
result:
ok 3 testow OK.
Test #2:
score: 0
Accepted
time: 0ms
memory: 5520kb
input:
50 21 2 1 0 4 1 3 1 2 0 2 0 1 1 4 2 3 0 3 2 4 0 0 1 1 1 0 0 6 1 5 2 0 2 2 2 5 1 6 2 6 0 5 1 3 17 9 3 17 28 12 27 3 17 3 17 13 27 12 21 13 3 3 21 20 9 68 38 75 22 34 47 70 50 70 45 59 38 34 22 68 45 59 22 10 47 38 75 35 70 54 64 49 64 38 72 13 72 35 47 55 47 13 70 49 10 54 47 42 111 9 92 42 123 35 11...
output:
YES 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 YES 1 YES 18 8 9 10 4 1 7 14 15 YES 7 28 36 33 5 9 25 2 16 YES 17 19 24 6 11 22 3 23 25 5 YES 60 12 26 28 7 33 45 19 16 44 YES 15 26 41 4 7 57 11 3 44 54 YES 34 4 16 55 15 11 60 19 39 23 YES 35 12 34 41 23 3 44 11 45 38 YES 2 15 25 30 11 3 8 27 1...
result:
ok 50 testow OK.
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5752kb
input:
50 2 2 1 3 1 3 1 2 1 3 1 1 4 0 0 0 1 0 2 0 3 5 1 6 1 7 1 4 1 8 1 5 5 2 5 4 5 5 2 3 5 2 2 4 6 5 5 3 5 5 7 3 5 2 5 2 3 2 4 3 3 3 4 5 1 0 3 0 0 2 0 0 0 1 5 11 2 8 1 5 1 11 3 11 1 4 4 3 2 2 4 2 0 2 5 3 1 1 1 0 1 0 2 3 2 5 1 5 8 5 8 6 6 5 6 7 5 2 3 2 2 3 2 4 2 2 6 3 2 2 1 3 1 2 4 3 3 2 3 3 2 2 2 5 5 0 4 ...
output:
YES 1 1 YES 1 1 1 YES 1 1 1 1 YES 1 1 1 1 1 YES 1 1 4 1 3 YES 1 2 1 3 YES 2 1 1 1 1 YES 2 5 3 1 1 YES 1 3 3 1 1 YES 1 2 1 2 YES 1 2 1 1 1 YES 5 1 1 2 3 YES 3 1 1 1 3 YES 2 1 1 YES 1 1 1 1 YES 1 1 1 1 2 YES 1 1 1 3 YES 1 1 4 3 1 YES 1 2 1 2 YES 1 2 1 1 1 YES 2 2 YES 1 1 2 2 YES ...
result:
wrong answer Test 24: oczekiwano YES, wczytano J4.