QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#883659 | #21529. 动态树(简单版) | AZN_0975 | Compile Error | / | / | C++20 | 1.6kb | 2025-02-05 17:52:52 | 2025-02-05 17:52:53 |
Judging History
This is the latest submission verdict.
- [2025-02-05 17:52:53]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2025-02-05 17:52:52]
- Submitted
answer
#define getchar_unlocked getchar
#include<bits/stdc++.h>
#define fr(i,l,r) for(int i(l),_##i(r);i<=_##i;i++)
template<class T>inline T rd(T&a){
T x=0;bool f=1;char c=getchar_unlocked();
for(;c<48|c>57;c=getchar_unlocked())f&=c!=45;
for(;c>47&c<58;c=getchar_unlocked())x=10*x+c-48;
return a=f?x:-x;
}template<class T,class...V>inline void rd(T&x,V&...v){rd(x),rd(v...);}
using namespace std;
const int N=1.5e5+3;
int n,m,op,x,y,ch[N][2],fa[N],val[N],s[N];bool tg[N];
#define ls(x) ch[x][0]
#define rs(x) ch[x][1]
#define UP(x) s[x]=s[ls(x)]^val[x]^s[rs(x)]
#define O(x) (x&&x==ls(fa[x])?0:x&&x==rs(fa[x])?1:-1)
inline void rev(int x){tg[x]^=1,swap(ls(x),rs(x));}
inline void pudo(int x){if(tg[x])rev(ls(x)),rev(rs(x)),tg[x]=0;}
inline void upd(int x){if(~O(x))upd(fa[x]);pudo(x);}
inline void con(int x,int f,int o){fa[x]=f,~o?ch[f][o]=x:0;}
inline void rot(int x){int y=fa[x],o=O(x);con(ch[x][!o],y,o),con(x,fa[y],O(y)),con(y,x,!o),UP(y),UP(x);}
inline void splay(int x){for(upd(x);~O(x);rot(x))if(~O(fa[x]))rot(O(x)^O(fa[x])?x:fa[x]);}
inline int acs(int x){int y=0;for(;x;x=fa[y=x])splay(x),rs(x)=y,UP(x);return y;}
inline void mkrt(int x){rev(acs(x));}
inline int frt(int x){for(x=acs(x);ls(x);x=ls(x));return x;}
inline void link(int x,int y){if(frt(x)^frt(y))mkrt(x),splay(x),fa[x]=y;}
inline void cut(int x,int y){mkrt(x),acs(x),splay(y),ls(y)||fa[y]^x?0:fa[y]=0;}
int main(){
rd(n,m);fr(i,1,n)s[i]=rd(val[i]);
while(m--)switch(rd(op,x,y),op){
case 0: mkrt(x),cout<<(frt(y)^x?-1:s[acs(y)])<<'\n';break;
case 1: link(x,y);break;
case 2: cut(x,y);break;
case 3: splay(x),val[x]=y,UP(x);
}return 0;
}
Details
answer.code:1:26: error: redefinition of ‘int getchar()’ 1 | #define getchar_unlocked getchar | ^~~~~~~ In file included from /usr/include/stdio.h:976, from /usr/include/c++/14/cstdio:42, from /usr/include/c++/14/ext/string_conversions.h:45, from /usr/include/c++/14/bits/basic_string.h:4154, from /usr/include/c++/14/string:54, from /usr/include/c++/14/bitset:52, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52, from answer.code:2: /usr/include/x86_64-linux-gnu/bits/stdio.h:47:1: note: ‘int getchar()’ previously defined here 47 | getchar (void) | ^~~~~~~