QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#851923 | #9090. 由乃的 OJ | binbin | 100 ✓ | 249ms | 11140kb | C++14 | 4.6kb | 2025-01-11 09:05:47 | 2025-01-11 09:05:48 |
Judging History
answer
#pragma GCC optimize(2,3)
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
const int maxn=1e5+5;
inline ull read()
{
ull sum=0;char c=getchar();
while(c<'0'||c>'9') c=getchar();
while('0'<=c&&c<='9') sum=(sum<<1)+(sum<<3)+(c-'0'),c=getchar();
return sum;
}
class LintCutTree
{
public:
struct valnode{ull v0,v1;};
struct treenode{int ch[2],fa,opt;bool tag;valnode f,g;ull x;}tr[maxn];
inline ull calc(ull v,int x)
{
if(tr[x].opt==1) return v&tr[x].x;
else if(tr[x].opt==2) return v|tr[x].x;
return v^tr[x].x;
}
inline valnode merge(valnode x,valnode y)
{
valnode ans={0,0};
ans.v0=(x.v0&y.v1)|((~x.v0)&y.v0);
ans.v1=(x.v1&y.v1)|((~x.v1)&y.v0);
return ans;
}
private:
#define lch(x) tr[x].ch[0]
#define rch(x) tr[x].ch[1]
#define Get(x) (rch(tr[x].fa)==x)
#define Isroot(x) (lch(tr[x].fa)!=x&&rch(tr[x].fa)!=x)
inline void pushup(int x)
{
tr[x].f.v0=calc(0ull,x);tr[x].f.v1=calc((1ull<<64)-1,x);
tr[x].g.v0=calc(0ull,x);tr[x].g.v1=calc((1ull<<64)-1,x);
if(rch(x)) tr[x].f=merge(tr[rch(x)].f,tr[x].f),tr[x].g=merge(tr[x].g,tr[rch(x)].g);
if(lch(x)) tr[x].f=merge(tr[x].f,tr[lch(x)].f),tr[x].g=merge(tr[lch(x)].g,tr[x].g);
}
inline void rev(int x){swap(lch(x),rch(x));swap(tr[x].f,tr[x].g);tr[x].tag^=1;}
inline void pushdown(int x)
{
if(tr[x].tag)
{
if(lch(x)) rev(lch(x));
if(rch(x)) rev(rch(x));
tr[x].tag=0;
}
}
inline void updata(int x){if(!Isroot(x)) updata(tr[x].fa);pushdown(x);}
inline void rotate(int x)
{
int y=tr[x].fa,z=tr[y].fa,k=Get(x);
if(!Isroot(y)) tr[z].ch[rch(z)==y]=x;
tr[y].ch[k]=tr[x].ch[!k];if(tr[x].ch[!k]) tr[tr[x].ch[!k]].fa=y;
tr[x].ch[!k]=y;tr[y].fa=x,tr[x].fa=z;
pushup(y),pushup(x);
}
inline void splay(int x){updata(x);for(int fa;fa=tr[x].fa,!Isroot(x);rotate(x)) if(!Isroot(fa)) rotate(Get(fa)==Get(x)?fa:x);}
inline int Access(int x){int p=0;for(;x;p=x,x=tr[x].fa) splay(x),tr[x].ch[1]=p,pushup(x);return p;}
public:
inline void makeroot(int x){x=Access(x);rev(x);}
inline void link(int x,int y){makeroot(x);splay(x);tr[x].fa=y;}
inline void cut(int x,int y){makeroot(x);Access(y);splay(y);tr[y].fa=tr[x].ch[0]=0;pushup(x);}
public:
inline void modify(int x,int y,ull z)
{
makeroot(x);Access(x);
tr[x].opt=y,tr[x].x=z;
tr[x].f.v0=calc(0ull,x);tr[x].f.v1=calc((1ull<<64)-1,x);
tr[x].g.v0=calc(0ull,x);tr[x].g.v1=calc((1ull<<64)-1,x);
}
inline ull qry(int x,int y,ull z)
{
makeroot(y);Access(x);splay(y);
bool flg=0;ull ans=0;
for(int i=63;~i;i--)
{
ull c0=(tr[y].f.v0>>i)&1ull,c1=(tr[y].f.v1>>i)&1ull;
if(!flg)
{
if((c0^c1)==0)
{
ans^=c0<<i;
if((z>>i)&1) flg=1;
}
else
{
if(c0)
{
ans^=1ull<<i;
if((z>>i)&1) flg=1;
}
else if((z>>i)&1) ans^=1ull<<i;
}
}
else if(c0||c1) ans^=1ull<<i;
}
return ans;
}
}LCT;
int n,m,k;
int main()
{
// scanf("%d%d%d",&n,&m,&k);
n=read(),m=read(),k=read();
for(int i=1;i<=n;i++)
{
// scanf("%d%llu",&LCT.tr[i].opt,&LCT.tr[i].x);
LCT.tr[i].opt=read(),LCT.tr[i].x=read();
LCT.tr[i].f.v0=LCT.calc(0ull,i);LCT.tr[i].f.v1=LCT.calc((1ull<<64)-1,i);
LCT.tr[i].g.v0=LCT.calc(0ull,i);LCT.tr[i].g.v1=LCT.calc((1ull<<64)-1,i);
}
for(int i=1;i<n;i++)
{
int x,y;
// scanf("%d%d",&x,&y);
x=read(),y=read();
LCT.link(x,y);
}
for(int i=1;i<=m;i++)
{
int opt,x,y;ull z;
// scanf("%d%d%d%llu",&opt,&x,&y,&z);
opt=read(),x=read(),y=read(),z=read();
if(opt==1) printf("%llu\n",LCT.qry(x,y,z));
else LCT.modify(x,y,z);
}
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 0ms
memory: 3792kb
input:
1 1 64 2 9571068480616515248 1 1 1 16544127868907869972
output:
18446744073709551615
result:
ok single line: '18446744073709551615'
Test #2:
score: 10
Accepted
time: 0ms
memory: 3968kb
input:
1 1 64 1 1506855638569178048 1 1 1 6847545983554890940
output:
1506855638569178048
result:
ok single line: '1506855638569178048'
Test #3:
score: 10
Accepted
time: 0ms
memory: 3840kb
input:
1 1 64 3 6185676482409412160 1 1 1 12247208093671719720
output:
18302628885633695743
result:
ok single line: '18302628885633695743'
Test #4:
score: 10
Accepted
time: 225ms
memory: 10584kb
input:
100000 100000 5 2 29 2 4 1 9 3 8 1 12 2 10 2 0 1 14 1 30 2 19 2 24 3 7 1 3 1 15 3 17 1 25 2 14 3 30 1 12 2 20 2 12 1 5 1 5 1 6 2 5 1 22 1 13 3 27 1 20 1 9 1 11 1 21 1 6 2 19 2 17 3 30 2 2 1 27 1 28 2 1 3 24 2 11 1 10 1 9 3 16 3 8 1 25 2 27 3 12 1 4 2 11 1 30 1 2 1 8 1 3 3 18 2 19 1 22 1 15 3 0 2 18 ...
output:
0 1 0 23 31 1 16 18 0 26 27 14 20 24 5 0 27 10 31 0 19 31 0 0 31 16 8 2 2 3 4 1 8 13 12 14 8 0 23 1 10 0 12 0 20 8 25 4 12 0 0 31 16 8 0 12 21 0 0 0 0 0 25 30 17 0 1 8 7 3 14 0 31 8 21 0 20 0 5 0 15 0 21 31 2 13 0 19 3 10 15 0 18 29 2 1 17 11 1 19 2 8 31 4 11 30 17 1 9 14 0 12 0 0 26 20 15 1 0 0 2 0...
result:
ok 49880 lines
Test #5:
score: 10
Accepted
time: 227ms
memory: 10728kb
input:
100000 100000 5 1 9 3 5 1 25 2 28 1 12 1 19 3 13 2 13 3 5 1 29 3 29 3 30 1 14 2 14 1 2 3 21 3 14 1 18 1 20 1 7 1 9 3 21 3 0 1 18 2 8 3 30 1 4 1 13 1 24 2 0 1 6 1 9 2 23 1 8 3 22 1 8 1 24 2 17 1 15 2 20 2 0 1 30 1 21 1 24 1 19 1 24 1 10 2 3 1 28 2 15 1 16 1 15 2 22 1 21 1 21 3 15 2 14 1 24 1 30 1 9 1...
output:
31 4 16 0 30 0 0 31 6 2 29 5 31 18 8 0 1 0 23 11 31 15 27 0 0 5 17 0 8 27 23 25 0 0 17 0 14 3 23 1 28 11 18 31 31 4 0 6 4 0 21 0 0 0 31 29 27 31 19 0 0 18 29 1 31 5 0 23 28 0 0 1 0 0 18 0 0 27 10 0 8 1 14 4 12 23 6 11 28 31 0 27 0 0 25 2 4 4 21 0 15 30 2 0 21 8 6 27 17 5 24 24 30 0 10 0 8 19 3 8 0 6...
result:
ok 49839 lines
Test #6:
score: 10
Accepted
time: 208ms
memory: 11104kb
input:
100000 100000 64 3 6849478074866668544 3 11167113834542290196 3 382194824487069000 3 14485535956115150960 3 16118673601920803472 3 5674369401551604584 3 6215793282188699584 3 72121972327948764 3 9218349919402034176 3 2791969199565062517 3 1488260234114592384 3 10684975479869850040 3 1547171339095348...
output:
18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 13835058055282163711 18446744073709551615 18446744073709551615 18446744073709551615 9223372036854775807 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 1844674...
result:
ok 49860 lines
Test #7:
score: 10
Accepted
time: 199ms
memory: 11140kb
input:
100000 100000 64 2 10440930676570569884 2 1853185226231848470 2 11424060548571708416 2 8228033109522074696 2 14704927088009817204 2 2481947125753995884 2 2463649397205317370 2 17787389172593040 2 3530448242110471436 2 11808730411093889462 2 6116673936429460736 2 13127573790863940652 2 18078577447081...
output:
18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615 184467...
result:
ok 49876 lines
Test #8:
score: 10
Accepted
time: 249ms
memory: 10992kb
input:
100000 100000 64 2 18050098904278365056 3 9215593108859791936 1 5137021596549704320 3 15534346187870029184 1 7310222637146326000 3 3279938048055301888 1 6248099760397125208 1 3186790113317149056 1 10687267662883138752 1 12462148540767340544 1 17886287129257898144 1 649578698298817280 1 9542191391465...
output:
2185591808067574354 9833873043051689658 6440712970594456072 4936131567433582528 35970351104 12104505621479255928 71232032620544 16118241160335194616 275180158976 16035097326873914400 11785408677144247191 4785108963837952 7025933499840518528 5263253616581999616 1188950301625810944 2402812476819996 43...
result:
ok 49855 lines
Test #9:
score: 10
Accepted
time: 244ms
memory: 10948kb
input:
100000 100000 64 1 551025758598079232 1 1211785915174860736 3 2187829537987356160 1 2220965675984901316 1 9412245404289125760 1 9249500563055078400 1 526071969975740944 2 5012388911075220000 1 3935995639774175840 1 1491291578887728688 1 17942737912301642012 1 17815002529681708988 3 68241055875343818...
output:
72066424494883456 46161896327364624 1152921504606846976 7569425761435658432 1155316516363698688 137438955520 13853213363355525664 144159170156441600 4568862110464176544 15852890865987700304 17688953708372275104 3342334606528464176 3989340575047226590 18198800724555106254 2051004323597842752 46117212...
result:
ok 49875 lines
Test #10:
score: 10
Accepted
time: 245ms
memory: 10796kb
input:
100000 100000 64 1 16195426518315551760 1 16168263482799686880 1 11485851822963872640 1 18226298480034677760 1 14960344458316714300 1 17440931610142348040 1 12037480559755958016 1 5899053106052108169 1 1212106985330641920 3 13277424726596481344 1 8242516072558853304 3 2342372783874722512 3 439604132...
output:
0 17275808101269749704 725897853901424896 1152957790176549376 16142031474139857024 0 3099039497887684608 1514932549660358368 16644984264743190486 9223200856101262256 18361879293723502016 17777935717623240164 14436058707365259208 5773691765561301440 7904547079780177000 36090507125883680 3439857287541...
result:
ok 49871 lines