QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#764066 | #8106. Mosaic | Kevin5307 | WA | 0ms | 3660kb | C++23 | 3.7kb | 2024-11-19 23:49:45 | 2024-11-19 23:49:45 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
#define ls (x<<1)
#define rs (ls|1)
ll x[2020],y[2020];
int n;
int segt[2020<<2],tag[2020<<2],mx[2020<<2];
void build(int x,int l,int r)
{
segt[x]=tag[x]=mx[x]=0;
if(l==r) return ;
int mid=(l+r)/2;
build(ls,l,mid);
build(rs,mid+1,r);
}
void update(int x,int l,int r,int ql,int qr,int v)
{
if(ql<=l&&r<=qr)
{
segt[x]+=v;
tag[x]+=v;
mx[x]+=v;
return ;
}
int mid=(l+r)/2;
if(ql<=mid) update(ls,l,mid,ql,qr,v);
if(qr>mid) update(rs,mid+1,r,ql,qr,v);
segt[x]=min(segt[ls],segt[rs])+tag[x];
mx[x]=max(mx[ls],mx[rs])+tag[x];
}
int query(int x,int l,int r,int p)
{
if(l==r) return segt[x];
int mid=(l+r)/2;
if(p<=mid) return query(ls,l,mid,p)+tag[x];
else return query(rs,mid+1,r,p)+tag[x];
}
int get(int x,int l,int r,int p,int curtag=0)
{
if(p<=l)
{
if(curtag+mx[x]==0) return r+1;
if(l==r) return l;
int mid=(l+r)/2;
if(curtag+tag[x]+mx[ls]==0) return get(rs,mid+1,r,p,curtag+tag[x]);
return get(ls,l,mid,p,curtag+tag[x]);
}
int mid=(l+r)/2;
if(p>mid) return get(rs,mid+1,r,p,curtag+tag[x]);
int ans=get(ls,l,mid,p,curtag+tag[x]);
if(ans==mid+1) return get(rs,mid+1,r,p,curtag+tag[x]);
return ans;
}
ll r[2020];
int check(ll len)
{
vector<ll> pool;
for(int i=1;i<=n;i++)
if(y[i]>=len)
return 0;
else
pool.pb(y[i]);
pool.pb(0);
pool.pb(len);
srt(pool);
uni(pool);
build(1,1,sz(pool)-1);
vector<int> vec;
for(int i=1;i<=n;i++)
vec.pb(i);
sort(ALL(vec),[&](int u,int v){return mp(x[u],-y[u])<mp(x[v],-y[v]);});
set<array<ll,3>> st;
for(auto ind:vec)
{
while(sz(st)&&(*st.begin())[0]<x[ind])
{
update(1,1,sz(pool)-1,(*st.begin())[1],(*st.begin())[2],-1);
st.erase(st.begin());
}
if(segt[1]==0&&x[ind]) return 0;
while(sz(st)&&(*st.begin())[0]==x[ind])
{
update(1,1,sz(pool)-1,(*st.begin())[1],(*st.begin())[2],-1);
st.erase(st.begin());
}
int p=ub(pool,y[ind]);
if(query(1,1,sz(pool)-1,p)) return 0;
int val=get(1,1,sz(pool)-1,p);
update(1,1,sz(pool)-1,p,val-1,1);
r[ind]=pool[val-1]-pool[p-1];
st.insert(array<ll,3>{r[ind]+x[ind],p,val-1});
}
int val=(*st.rbegin())[0];
while(sz(st)&&(*st.begin())[0]<val)
{
update(1,1,sz(pool)-1,(*st.begin())[1],(*st.begin())[2],-1);
st.erase(st.begin());
}
if(segt[1]==0) return 0;
cout<<"YES";
for(int i=1;i<=n;i++)
cout<<" "<<r[i];
cout<<'\n';
return 1;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>x[i]>>y[i];
if(n==1)
{
cout<<"YES 1\n";
continue;
}
ll mnx=*min_element(x+1,x+n+1);
ll mny=*min_element(y+1,y+n+1);
for(int i=1;i<=n;i++)
{
x[i]-=mnx;
y[i]-=mny;
}
ll mx1=0,mx2=0;
for(int i=1;i<=n;i++)
{
if(!y[i]) mx1=max(mx1,x[i]);
if(!x[i]) mx2=max(mx2,y[i]);
}
int flag=0;
for(int i=1;i<=n&&!flag;i++)
flag|=check(x[i]+mx2);
for(int i=1;i<=n;i++)
swap(x[i],y[i]);
for(int i=1;i<=n&&!flag;i++)
flag|=check(x[i]+mx1);
if(!flag)
cout<<"NO\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
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: -100
Wrong Answer
time: 0ms
memory: 3660kb
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:
NO YES 1 NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO
result:
wrong answer Test 1: oczekiwano YES, wczytano NO.