QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#65082#5113. Bridge12WA 12ms114148kbC++143.7kb2022-11-27 15:21:362022-11-27 15:21:37

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-27 15:21:37]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:114148kb
  • [2022-11-27 15:21:36]
  • 提交

answer

#include<cstdio>
#include<random>
#include<vector>
#include<set>
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define N 1000000
int ls[N],rs[N],rky[N],val[N],fa[N],rt[100005],fcnt = 0;
int opt[N],oa[N],ob[N];
set<int> Set[N];
vector<int> vec1[N],vec2[N];
int fan_rt[N],ans[N];
int new_node(int v)
{
    static std::mt19937 rnd(114514);
    int id = ++fcnt;
    ls[id] = rs[id] = 0;
    rky[id] = rnd();
    val[id] = v;
    return id;
}
void maintain(int v)
{
    fa[ls[v]] = v;
    fa[rs[v]] = v;
}
void split(int now,int k,int &x,int &y) 
{
    if(!now){x=y=0;return;}
    if(val[now] <= k)
    {
        x = now;
        split(rs[now],k,rs[now],y);
    }
    else{
        y = now;
        split(ls[now],k,x,ls[now]);
    }
    maintain(now);
    maintain(x);
    maintain(y);
}
int merge(int x,int y)
{
    if(!x||!y)return x|y;
    int r=0;
    if(rky[x]>rky[y]){
        r=x;
        rs[r]=merge(rs[r],y);
    }
    else{
        r=y;
        ls[r]=merge(x,ls[r]);
    }
    maintain(r);
    return r;
}
int getid(int a,int b){
    int id = std::lower_bound(vec1[a].begin(),vec1[a].end(),b)-vec1[a].begin();
    int factb = vec2[a][id];
    return factb;
}
int getfa(int x){
    // int f = fa[x];
    while(fa[x]){
        x = fa[x];
    }
    return x;
}
void dfs(int x){
//	printf("%d 's lson = %d",x,ls[x]);
//	printf("%d 's rson = %d",x,rs[x]);
//	if(ls[x])
//		printf("%d %d\n",x,ls[x]);
//	if(rs[x])
//		printf("%d %d\n",x,rs[x]);
	if(ls[x])
		dfs(ls[x]);
	if(rs[x])
		dfs(rs[x]);
	maintain(x);
}
int main(){
	srand(time(0));
    int n,m,q;
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=q;++i){
        scanf("%d",&opt[i]);
        if(opt[i]==1){
            scanf("%d%d",&oa[i],&ob[i]);
            Set[oa[i]].insert(ob[i]);
            Set[oa[i]+1].insert(ob[i]);
            Set[oa[i]].insert(ob[i]+1);
            Set[oa[i]+1].insert(ob[i]+1);
        } else{
            scanf("%d",&oa[i]);
        }
    }
    for(int i=1;i<=n;++i){
        for(auto p:Set[i]){
            int id = new_node(p);
            rt[i] = merge(rt[i],id);
            fan_rt[rt[i]] = i ;
            vec1[i].push_back(p);
            vec2[i].push_back(id);
            printf("s %d %d %d\n",i,p,id);
        }
        ans[i] = i ;
    }
    
    for(int i=1;i<=q;++i){
        if(opt[i]==1){
            int firsta = oa[i] , seconda = oa[i] + 1;
            int firstb = ob[i] , secondb = ob[i];
            

            int firstid = getid(firsta,firstb);
            int secondid = getid(seconda,secondb);
            

            int firstrt = getfa(firstid);
            int secondrt = getfa(secondid);
            
            
            int treea = fan_rt[firstrt];
            int treeb = fan_rt[secondrt];
            
            swap(ans[treea],ans[treeb]);

            int firstfront=0 , firstbehind=0;
            int secondfront=0 , secondbehind=0;
            
            split(rt[treea],firstb,firstfront,firstbehind);
            split(rt[treeb],secondb,secondfront,secondbehind);
            // std::cerr<<111<<" "<<firstb<<" "<<firstfront<<" "<<firstbehind<<std::endl;
            // std::cerr<<222<<" "<<secondfront<<" "<<secondbehind<<std::endl;

            // std::cerr<<11<<" "<<treea<<" "<<treeb<<std::endl;
            rt[treea] = merge(firstfront,secondbehind);
            rt[treeb] = merge(secondfront,firstbehind);
            
            fa[rt[treea]] = 0 ;
            fa[rt[treeb]] = 0 ;

            fan_rt[rt[treea]] = treea;
            fan_rt[rt[treeb]] = treeb;

        }
        else {
            printf("ans %d\n",ans[oa[i]]);
        }
    }
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 12ms
memory: 114148kb

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:

s 1 3 1
s 1 4 2
s 2 1 3
s 2 2 4
s 2 3 5
s 2 4 6
s 2 5 7
s 3 1 8
s 3 2 9
s 3 4 10
s 3 5 11
ans 2
ans 2
ans 1
ans 3
ans 3
ans 1
ans 2
ans 3
ans 2
ans 1

result:

wrong output format Expected integer, but "s" found