QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#667470 | #5113. Bridge | MCPlayer542 | WA | 36ms | 13780kb | C++14 | 2.3kb | 2024-10-22 23:21:50 | 2024-10-22 23:21:50 |
Judging History
answer
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
struct node
{
static int getsz(node *x)
{
if(x) return x->sz;
return 0;
}
int v,sz,l,r;
node *f,*so[2];
node(int vv=0,int ll=0,int rr=0)
{
init(vv,ll,rr);
}
void init(int vv,int ll,int rr)
{
v=vv;
l=ll;
r=rr;
sz=1;
f=so[0]=so[1]=nullptr;
}
void pushup()
{
sz=getsz(so[0])+getsz(so[1])+1;
}
bool isright()
{
return f&&f->so[1]==this;
}
void rot()
{
bool b=!isright();
node *gfa=f->f,*son=so[b];
if(gfa) gfa->so[f->isright()]=this;
if(son) son->f=f;
f->so[!b]=son;
f->f=this;
so[b]=f;
f=gfa;
so[b]->pushup();
pushup();
}
void splay(node *fath=nullptr)
{
while(f!=fath)
{
if(f->f!=fath) isright()^f->isright()?rot():f->rot();
rot();
}
}
void setson(node *son=nullptr,bool b=0)
{
node *pr=so[b];
if(pr) pr->f=nullptr;
if(son) son->f=this;
so[b]=son;
pushup();
splay();
}
};
vector<node*> nd[100010];
vector<int> cuts[100010];
int n,m,k,l,q;
struct oper
{
int op,a,b;
void operate()
{
if(op==1)
{
int p1=lower_bound(cuts[a].begin(),cuts[a].end(),b)-cuts[a].begin()-1,p2=lower_bound(cuts[a+1].begin(),cuts[a+1].end(),b)-cuts[a+1].begin()-1;
nd[a][p1]->splay();
nd[a][p1+1]->splay(nd[a][p1]);
nd[a+1][p2]->splay();
nd[a+1][p2+1]->splay(nd[a+1][p2]);
nd[a][p1]->setson(nd[a+1][p2+1],1);
nd[a+1][p2]->setson(nd[a][p1+1],1);
}
else
{
nd[a][0]->splay();
node *p=nd[a][0];
while(p->so[1]) p=p->so[1];
printf("%d\n",p->v);
}
}
}op[100010];
int main()
{
scanf("%d%d%d",&n,&m,&q);
for(int i=0;i<q;++i)
{
scanf("%d%d",&op[i].op,&op[i].a);
if(op[i].op==1)
{
scanf("%d",&op[i].b);
cuts[op[i].a].push_back(op[i].b);
cuts[op[i].a+1].push_back(op[i].b);
}
}
for(int i=1;i<=n;++i)
{
cuts[i].push_back(0);
cuts[i].push_back(m+1);
nd[i].resize(cuts[i].size()-1);
sort(cuts[i].begin(),cuts[i].end());
for(int j=1,lim=cuts[i].size();j<lim;++j)
{
nd[i][j-1]=new node(i,cuts[i][j-1]+1,cuts[i][j]);
if(j!=1) nd[i][j-2]->setson(nd[i][j-1],1);
}
}
for(int i=0;i<q;++i) op[i].operate();
return 0;
}
/*
3 4 13
2 2
1 1 3
2 1
2 2
2 3
1 2 4
2 1
2 2
2 3
1 2 1
2 1
2 2
2 3
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 8888kb
input:
3 4 13 2 2 1 1 3 2 1 2 2 2 3 1 2 4 2 1 2 2 2 3 1 2 1 2 1 2 2 2 3
output:
2 2 1 3 3 1 2 3 2 1
result:
ok 10 numbers
Test #2:
score: -100
Wrong Answer
time: 36ms
memory: 13780kb
input:
3 100000 99997 2 2 2 2 2 3 2 3 2 3 2 3 2 3 1 2 11047 1 1 98732 1 2 90045 1 1 43556 2 1 2 3 1 2 17242 1 1 17027 2 1 1 1 94195 2 1 2 2 2 1 2 3 1 1 34124 1 2 14354 1 2 673 1 2 39812 1 2 35520 1 2 16046 2 3 2 2 1 1 25410 2 3 2 1 2 3 2 2 1 2 55684 2 1 1 2 24811 1 2 92268 1 2 60268 2 2 1 1 89272 1 2 19232...
output:
2 2 3 3 3 3 3 3 2 1 2 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 2 2 2 3 2 2 2 3 3 2 2 3 2 3 2 3 2 3 2 3 3 3 3 2 2 2 2 3 2 3 3 3 2 2 2 3 2 2 2 2 3 3 3 2 2 2 3 3 2 3 3 2 2 3 2 3 2 3 2 2 2 2 3 2 2 3 2 2 3 3 2 2 2 2 2 2 2 2 3 2 2 3 3 2 2 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
wrong answer 12th numbers differ - expected: '1', found: '3'