QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#56484 | #2555. Two Bullets | mendicillin2# | WA | 2ms | 3876kb | C++17 | 3.7kb | 2022-10-19 18:52:51 | 2022-10-19 18:52:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n;
struct ELE
{
int x,y;
int L,R,U,D;
short d;
int ls,rs;
int size;
int occ;
}a[100010];
bool cmp1(int A,int B)
{
return a[A].x<a[B].x;
}
bool cmp2(int A,int B)
{
return a[A].y<a[B].y;
}
int root=0,num=0;
bool jud(int p)
{
return a[p].size*0.6<max(a[a[p].ls].size,a[a[p].rs].size);
}
int rt[100010],cnt;
void unfold(int p)
{
if(p==0)return ;
unfold(a[p].ls);
if(a[p].occ)
{
cnt++;
rt[cnt]=p;
}
unfold(a[p].rs);
}
void update(int p)
{
a[p].size=a[a[p].ls].size+a[a[p].rs].size+a[p].occ;
a[p].L=a[p].x;
a[p].R=a[p].x;
a[p].U=a[p].y;
a[p].D=a[p].y;
if(a[p].ls)
a[p].L=min(a[a[p].ls].L,a[p].L),
a[p].R=max(a[a[p].ls].R,a[p].R),
a[p].D=min(a[a[p].ls].D,a[p].D),
a[p].U=max(a[a[p].ls].U,a[p].U);
if(a[p].rs)
a[p].L=min(a[a[p].rs].L,a[p].L),
a[p].R=max(a[a[p].rs].R,a[p].R),
a[p].D=min(a[a[p].rs].D,a[p].D),
a[p].U=max(a[a[p].rs].U,a[p].U);
}
int rebuild(int l,int r)
{
if(l==r)return 0;
int mid=(l+r)/2;
double avx=0,avy=0,vax=0,vay=0;
for(int i=l;i<r;i++)
avx+=a[rt[i]].x,
avy+=a[rt[i]].y;
avx/=(r-l);
avy/=(r-l);
for(int i=l;i<r;i++)
vax+=(a[rt[i]].x-avx)*(a[rt[i]].x-avx),
vay+=(a[rt[i]].y-avy)*(a[rt[i]].y-avy);
if(vax>=vay)
{
nth_element(rt+l,rt+mid,rt+r,cmp1);
a[rt[mid]].d=1;
}
else
{
nth_element(rt+l,rt+mid,rt+r,cmp2);
a[rt[mid]].d=2;
}
a[rt[mid]].ls=rebuild(l,mid);
a[rt[mid]].rs=rebuild(mid+1,r);
update(rt[mid]);
return rt[mid];
}
void bal(int &p)
{
cnt=0;
unfold(p);
p=rebuild(1,cnt+1);
}
void insert(int &p,int x,int y)
{
if(p==0)
{
if(root==0)root=1;
num++;
p=num;
a[p].x=x;
a[p].y=y;
a[p].ls=a[p].rs=0;
a[p].occ=1;
a[p].d=rand()%2+1;
update(p);
}
else
{
if(a[p].d==1)//°´xά¶È»®·Ö
{
if(x<=a[p].x)insert(a[p].ls,x,y);
else insert(a[p].rs,x,y);
}
else//°´yά¶È»®·Ö
{
if(y<=a[p].y)insert(a[p].ls,x,y);
else insert(a[p].rs,x,y);
}
update(p);
if(jud(p))bal(p);
}
}
void del(int &p,int x,int y)
{
if(a[p].x==x&&a[p].y==y)
{
a[p].occ=0;
a[p].D=0x7fffffff;
a[p].U=0;
a[p].L=0x7fffffff;
a[p].R=0;
}
else
{
if(a[p].d==1)//°´xά¶È»®·Ö
{
if(x<=a[p].x)del(a[p].ls,x,y);
else del(a[p].rs,x,y);
}
else//°´yά¶È»®·Ö
{
if(y<=a[p].y)del(a[p].ls,x,y);
else del(a[p].rs,x,y);
}
}
update(p);
if(jud(p))bal(p);
}
int xl,yd;
int ret=0;
void query(int p){
if(p==0)return ;
if(xl>a[p].R||yd>a[p].U)return ;
if(ret>=a[p].U)return ;
if(xl<=a[p].x&&yd<=a[p].y&&a[p].occ)
ret=a[p].y;
if(a[a[p].ls].size)
query(a[p].ls);
if(a[a[p].rs].size)
query(a[p].rs);
return ;
}
bool vis[100010];//ÒѾ±»É¾³ýµÄ½ÚµãµÄ±àºÅ
int ans[100010][2];
int top;
int sum;
int pos;
int in[100010];
int book[100010];
int main()
{
// freopen("TB.in","r",stdin);
// freopen("TB.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&in[i]);
book[in[i]]=i;
insert(root,i,in[i]);
}
bal(root);
pos=1;
while(sum<=n&&pos<=n)
{
if(vis[pos])
{
pos++;
continue;
}
if(n-sum==1)
{
sum++;
top++;
ans[top][0]=pos;
ans[top][1]=pos;
break;
}
top++;
vis[pos]=1;
sum++;
ans[top][0]=in[pos];
del(root,pos,in[pos]);
xl=pos+1;
yd=in[pos];
ret=0;
query(root);
int tar=book[ret];
if(tar==0x7fffffff)
{
ans[top][1]=in[pos];
continue;
}
vis[tar]=1;
ans[top][1]=in[tar];
del(root,tar,in[tar]);
sum++;
pos++;
}
printf("%d\n",top);
for(int i=1;i<=top;i++)
printf("%d %d\n",ans[i][0],ans[i][1]);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3812kb
input:
8 4 3 8 2 1 7 6 5
output:
4 4 8 3 7 2 6 1 5
result:
ok da
Test #2:
score: 0
Accepted
time: 2ms
memory: 3872kb
input:
8 5 6 7 1 2 8 3 4
output:
4 5 8 6 7 1 4 2 3
result:
ok da
Test #3:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
4 1 2 4 3
output:
2 1 4 2 3
result:
ok da
Test #4:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
2 1 2
output:
1 1 2
result:
ok da
Test #5:
score: -100
Wrong Answer
time: 2ms
memory: 3836kb
input:
2 2 1
output:
2 2 0 1 0
result:
wrong answer Integer parameter [name=y] equals to 0, violates the range [1, 3]