QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#803080 | #9865. Dolls | ucup-team3586# | WA | 7ms | 22412kb | C++23 | 5.1kb | 2024-12-07 15:53:59 | 2024-12-07 15:54:01 |
Judging History
This is the latest submission verdict.
- [2025-01-08 13:49:40]
- hack成功,自动添加数据
- (/hack/1434)
- [2024-12-07 15:53:59]
- Submitted
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
#define ls (k<<1)
#define rs (k<<1|1)
#define mid ((l+r)>>1)
int n,pos=0;
namespace ST{
int xds[maxn<<2],add[maxn<<2],xdp[maxn<<2];
void ADD(int k,int v){
add[k]+=v,xds[k]+=v;
}
void pushup(int k){
if(xds[ls]<xds[rs])xdp[k]=xdp[ls];
else xdp[k]=xdp[rs];
xds[k]=min(xds[ls],xds[rs]);
}
void pushdown(int k){
ADD(ls,add[k]);ADD(rs,add[k]);
add[k]=0;
}
void buildt(int k,int l,int r){
xdp[k]=r;xds[k]=0;add[k]=0;
if(l==r)return ;
buildt(ls,l,mid);buildt(rs,mid+1,r);
}
void modify(int k,int l,int r,int x,int y,int v){
if(x>y)return ;
if(x<=l&&r<=y)return ADD(k,v);
pushdown(k);
if(x<=mid)modify(ls,l,mid,x,y,v);
if(mid<y)modify(rs,mid+1,r,x,y,v);
pushup(k);
}
void query(int k,int l,int r,int p){
if(xds[k]>0)return ;
if(l==r){
pos=max(pos,l);
return ;
}
pushdown(k);
if(p<=mid)query(ls,l,mid,p);
else{
if(xds[ls]==0)pos=max(pos,xdp[ls]);
query(rs,mid+1,r,p);
}
}
}
using namespace ST;
struct node{
int al,ar,vl,vr,id;
node(int a=0,int b=0,int c=0,int d=0,int e=0){
al=a,ar=b,vl=c,vr=d,id=e;
}
};
namespace DT{
node st[maxn],val[maxn];
int tp,fa[maxn],cnt=0,rt,P[maxn],rev[maxn];
int type[maxn];//0 正序合点 1 析点 2 倒序合点
void CLEAR(int n)
{
for(int i=0;i<=n*2;i++)
st[i]=node(),
val[i]=node(),
fa[i]=0,P[i]=0,rev[i]=0,type[i]=0;
cnt=0;
rt=0;
tp=0;
}
void ins(int i){
// puts("A");fflush(stdout);
bool f=1;
node cur(i,i,P[i],P[i],++cnt);
rev[i]=cnt;
val[cnt]=cur;
type[cnt]=1;
while(f){
if(!tp){f=0;break;}
node t=st[tp];
// puts("A!!!");fflush(stdout);
if((t.vr+1==cur.vl||t.vl-1==cur.vr)&&type[t.id]!=1){
if((type[t.id]==0&&t.vl<cur.vl)||(type[t.id]==2&&t.vl>cur.vl)){
fa[cur.id]=t.id;
t.ar=cur.ar,t.vl=min(t.vl,cur.vl),t.vr=max(t.vr,cur.vr);
val[t.id]=t;--tp;cur=t;f=1;
continue;
}
}
// puts("B!!!");fflush(stdout);
pos=0;
query(1,1,n,cur.al-1);
// puts("C!!!");fflush(stdout);
if(pos==0){f=0;break;}
if(pos==t.al){
fa[t.id]=fa[cur.id]=++cnt;
node N(t.al,cur.ar,min(cur.vl,t.vl),max(cur.vr,t.vr),cnt);
if(t.vl<cur.vl)type[N.id]=0;
else type[N.id]=2;
val[cnt]=N;--tp;cur=N;f=1;
continue;
}
// puts("D!!!");fflush(stdout);
int Min=cur.vl,Max=cur.vr;
fa[cur.id]=++cnt;
node N(cur.al,cur.ar,0,0,cnt);
// puts("E!!!");fflush(stdout);
while(tp){
// puts("F!!!");fflush(stdout);
t=st[tp];--tp;N.al=t.al;
Min=min(Min,t.vl);Max=max(Max,t.vr);
fa[t.id]=N.id;
if(t.al==pos)break;
}
N.vl=Min,N.vr=Max;
type[N.id]=1;val[N.id]=N;f=1;cur=N;
}
st[++tp]=cur;
// puts("AA");fflush(stdout);
}
int stmn[maxn],stmx[maxn],tp1=0,tp2=0;
void upd(int i){
modify(1,1,n,1,i-1,-1);
while(tp1&&P[stmn[tp1]]>P[i])modify(1,1,n,stmn[tp1-1]+1,stmn[tp1],P[stmn[tp1]]-P[i]),tp1--;
stmn[++tp1]=i;
while(tp2&&P[stmx[tp2]]<P[i])modify(1,1,n,stmx[tp2-1]+1,stmx[tp2],P[i]-P[stmx[tp2]]),tp2--;
stmx[++tp2]=i;
}
bool build(){
for(int i=1;i<=n;i++)upd(i),ins(i);
rt=st[tp].id;
// for(int i=1; i<=cnt; ++i)
// printf("%d %d %d\n",type[i],val[i].al,val[i].ar);
for(int i=1;i<=cnt;i++)
if(type[i]==1&&val[i].al<val[i].ar)
{
tp1=0,tp2=0,CLEAR(n);
// printf("Xi %d %d\n",val[i].al,val[i].ar);
return 0;
}
tp1=0,tp2=0,CLEAR(n);
return 1;
}
}
using namespace DT;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
int tmp[1<<20],in[1<<20];
bool check(int l,int r)
{
// printf("%d %d\n",l,r);fflush(stdout);
int sz=r-l+1;
for(int i=1; i<=sz; ++i)
tmp[i]=in[i+l-1];
sort(tmp+1,tmp+sz+1);
for(int i=1; i<=sz; ++i)
P[i]=lower_bound(tmp+1,tmp+sz+1,in[i+l-1])-tmp;
// for(int i=1; i<=sz; ++i)
// printf("%d ",P[i]);
// puts("");puts("");
fflush(stdout);
n=sz,pos=0;
buildt(1,1,sz);
return build();
}
signed main(){
for(int T=read(); T--;)
{
int n=read();
for(int i=1; i<=n; ++i) in[i]=read();
// printf("qwq=%d\n",check(1,3));
int x=1,ans=0;
while(x<=n)
{
++ans;
int res=x,l=x+1,r=n;
for(int len=1; x+len-1<=n; len<<=1)
if(check(x,x+len-1)) res=x+len-1,r=x+len;
else{r=x+len-2;break;}
while(l<=r)
{
int Mid=(l+r)>>1;
if(check(x,Mid)) res=Mid,l=Mid+1;
else r=Mid-1;
}
// printf("%d %d\n",x,res);
x=res+1;
}
printf("%d\n",n-ans);
}
// ios::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
// cin>>n;
// for(int i=1;i<=n;i++)cin>>P[i];
// int q;cin>>q;
// buildt(1,1,n);build();
// dfs1(rt);dfs2(rt,rt);
// for(int i=1;i<=q;i++){
// int x,y;cin>>x>>y;
// x=rev[x],y=rev[y];
// int L=LCA(x,y);
// if(type[L]==1){
// cout<<val[L].al<<" "<<val[L].ar<<endl;
// }else{
// int lx=Find(x,dep[x]-dep[L]-1),ly=Find(y,dep[y]-dep[L]-1);
// cout<<val[lx].al<<" "<<val[ly].ar<<endl;
// }
// }
// return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 22292kb
input:
8 4 2 1 4 3 4 1 4 2 3 4 3 1 4 2 5 1 3 5 2 4 5 1 4 2 5 3 5 2 5 3 1 4 6 1 3 6 5 2 4 6 2 5 1 3 6 4
output:
3 3 2 3 3 3 4 4
result:
ok 8 numbers
Test #2:
score: -100
Wrong Answer
time: 7ms
memory: 22412kb
input:
5913 1 1 2 1 2 2 2 1 3 1 2 3 3 1 3 2 3 2 1 3 3 2 3 1 3 3 1 2 3 3 2 1 4 1 2 3 4 4 1 2 4 3 4 1 3 2 4 4 1 3 4 2 4 1 4 2 3 4 1 4 3 2 4 2 1 3 4 4 2 1 4 3 4 2 3 1 4 4 2 3 4 1 4 2 4 1 3 4 2 4 3 1 4 3 1 2 4 4 3 1 4 2 4 3 2 1 4 4 3 2 4 1 4 3 4 1 2 4 3 4 2 1 4 4 1 2 3 4 4 1 3 2 4 4 2 1 3 4 4 2 3 1 4 4 3 1 2 4...
output:
0 1 1 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 2 3 3 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 3 4 4 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 4 3 3 4 4 3 4 3 3 3 4 3 4 4 4 3 3 3 3 4 4 4 4 3 4 4 3 4 4 4 4 3 3 3 3 4 4 4 3 4 3 3 3 4 3 4 4 3 3 4 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 4 4 3 4 4 4 4 4 4 4 ...
result:
wrong answer 154th numbers differ - expected: '5', found: '4'