QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#448681#7760. 化学实验strlen_s_0 29ms5652kbC++142.3kb2024-06-19 22:20:492024-06-19 22:20:51

Judging History

This is the latest submission verdict.

  • [2024-06-19 22:20:51]
  • Judged
  • Verdict: 0
  • Time: 29ms
  • Memory: 5652kb
  • [2024-06-19 22:20:49]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
const int N=5e5+10;
struct node{
  int son[2],fa,siz,st;
}t[N];
int tp,n,q,lans;
struct LCT{
  #define ls son[0]
  #define rs son[1]
  void pushup(int k){t[k].siz=t[t[k].ls].siz+t[t[k].rs].siz+t[k].st+1;}
  bool isroot(int k){return t[t[k].fa].ls!=k&&t[t[k].fa].rs!=k;}
  bool isright(int k){return t[t[k].fa].rs==k;}
  void rotate(int x){
    int y=t[x].fa,z=t[y].fa,k=isright(x);
    if(!isroot(y))t[z].son[isright(y)]=x;
    t[y].son[k]=t[x].son[k^1];
    if(t[x].son[k^1])t[t[x].son[k^1]].fa=y;
    t[x].son[k^1]=y;t[y].fa=x,t[x].fa=z;
    pushup(y);pushup(x);
  }
  void splay(int x){for(int f=t[x].fa;!isroot(x);rotate(x),f=t[x].fa)if(!isroot(f))rotate(isright(f)^isright(x)?x:f);}
  void access(int x){for(int p=0;x;p=x,x=t[x].fa)splay(x),t[x].st+=t[t[x].rs].siz-t[p].siz,t[x].rs=p,pushup(x);}
  int find(int x){
    splay(x);
    while(t[x].ls)x=t[x].ls;
    return x;
  }
  int dfs(int u,int lim){
    if(!u)return 0;
    if(u<=lim){
      int x=dfs(t[u].ls,lim);
      if(x)return x;
      return u;
    }
    else return dfs(t[u].rs,lim);
  }
  int dfs2(int u,int lim){
    if(!u)return 0;
    if(u>lim){
      int x=dfs2(t[u].rs,lim);
      if(x>lim)return x;
      return u;
    }
    else return dfs2(t[u].ls,lim);
  }
  int merge(int x,int y){
    if(!x||!y)return x|y;
    if(x<y)swap(x,y);
    int c=dfs2(x,y);
//    cout<<"GG "<<x<<' '<<y<<' '<<c<<endl;
    splay(c);t[t[c].rs].fa=0;
    int p=merge(t[c].rs,y);
    t[c].rs=p,t[p].fa=c;
    pushup(c);
    return c;
  }
  void link(int x,int y){
    access(x);access(y);splay(x);
    int f=t[x].fa;
    if(!f||f==y)return;
    access(f);splay(y);
    x=find(x),y=find(y);
    splay(x),splay(y);
    if(x<y)swap(x,y);
    merge(x,y);
    splay(x);
    t[x].fa=f;
  }
  int qry(int u,int lim){
    access(u);splay(u);
    u=dfs(u,lim);splay(u);
    return t[u].st+t[t[u].rs].siz+1;
  }
}T;
signed main(){
  ios::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);
  cin>>tp>>n>>q;
  for(int i=1;i<=n;i++)t[i].fa=n+1,t[i].siz=1;
  t[n+1].siz=n+1,t[n+1].st=n;
  while(q--){
    int op,x,y;
    cin>>op>>x>>y;
    x=(x-1+tp*lans)%n+1,y=(y-1+tp*lans)%n+1;
    if(op==1)T.link(x,y);
    else lans=T.qry(x,y),cout<<lans<<'\n';
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3792kb

input:

1 7500 7500
1 263 1446
1 6338 3037
1 5651 6129
1 572 3137
1 3159 5472
1 6038 4451
1 5988 5462
1 3873 1562
1 3516 5142
1 3375 2376
1 5832 1884
1 6243 3066
1 4001 6195
1 5301 6851
1 4382 2910
1 5299 562
1 452 335
1 3459 814
1 6681 6391
1 5816 4975
1 2244 1118
1 1410 1067
1 331 6324
1 6305 1294
1 4251 ...

output:

7468

result:

wrong answer 1st lines differ - expected: '3984', found: '7468'

Subtask #2:

score: 0
Time Limit Exceeded

Test #11:

score: 0
Time Limit Exceeded

input:

1 5000 100000
2 872 876
1 2895 4566
1 2676 1220
2 1852 1856
2 4153 4153
2 3675 3685
2 1489 1493
2 2782 2784
2 206 207
2 555 560
2 4149 4157
2 1875 1885
2 364 374
2 8 17
2 746 754
2 4785 4786
2 2394 2394
2 3386 3389
2 365 373
2 2290 2296
2 1419 1428
2 3651 3659
2 1922 1927
2 4877 4882
2 2597 2599
2 4...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:


Subtask #3:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 29ms
memory: 5652kb

input:

0 100000 100000
1 29135 32144
1 58340 30601
1 68869 18606
1 73019 84578
1 13050 79881
1 22773 20030
1 74542 28744
1 46491 64238
1 26985 17174
1 93308 48003
1 90547 4510
1 18373 35069
1 34019 14080
1 13461 19407
1 33811 60169
1 22131 76457
1 88085 38979
1 49749 20241
1 90505 42660
1 25889 75426
1 420...

output:

99962

result:

wrong answer 1st lines differ - expected: '80930', found: '99962'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #4:

0%