QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#473124 | #5402. 术树数 | Doqe | 18 | 361ms | 14236kb | C++14 | 2.1kb | 2024-07-11 22:07:55 | 2024-07-11 22:07:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10,B=20;
int q,k,m;
int fa[N][B],dep[N];
inline int LCA(int u,int v)
{
if(dep[u]>dep[v])swap(u,v);
int D=dep[v]-dep[u];
if(D)for(int i=__lg(D);~i;--i)if(D>>i&1)v=fa[v][i];
if(u==v)return u;
for(int i=__lg(dep[u]);~i;--i)
if(fa[u][i]!=fa[v][i])u=fa[u][i],v=fa[v][i];
return fa[u][0];
}
inline int add(int x,int y){int z=0,p=1;while(x||y)z+=(x%k+y%k)%k*p,x/=k,y/=k,p*=k;return z;}
inline int dec(int x,int y){int z=0,p=1;while(x||y)z+=(x%k+k-y%k)%k*p,x/=k,y/=k,p*=k;return z;}
inline int mul(int x,int w){int z=0,p=1;while(x )z+=(x%k*w)%k*p,x/=k,p*=k;return z;}
int Base[25];
void ini(){Base[0]=1;for(int i=1;i<=m;++i)Base[i]=Base[i-1]*k;}
inline int get(int x,int i){return x/Base[i]%k;}
inline int exgcd(int a,int b,int&x,int&y)
{
if(!b){x=1,y=0;return a;}
int d=exgcd(b,a%b,y,x);y-=a/b*x;
return d;
}
namespace Basis
{
int a[N];
inline void ins(int x)
{
// cerr<<"INS\n";
for(int i=m-1,w;~i;--i)if(w=get(x,i))
{
if(!a[i])
{
int p,q,d=exgcd(get(x,i),k,p,q);
a[i]=mul(x,p);x=mul(x,k/d);
}
else
{
while(get(x,i))
{
int d=get(a[i],i)/get(x,i);
a[i]=dec(a[i],mul(x,d));
// cerr<<i<<" : \n";
// for(int j=0;j<m;++j)cerr<<get(x ,j);cerr<<endl;
// for(int j=0;j<m;++j)cerr<<get(a[i],j);cerr<<endl;
swap(x,a[i]);
}
}
}
// cerr<<"ED\n";
}
inline int ask(int x)
{
for(int i=m-1;~i;--i)
{
int u=get(x,i);
if(u&&a[i])x=dec(x,mul(a[i],u/get(a[i],i)));
}
return x;
}
}
int val[N],tt=1;
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin>>q>>k>>m;
ini();
while(q--)
{
int o,x,y,v;cin>>o;
if(o==1)
{
int x,v;cin>>x>>v;
val[++tt]=add(val[x],v);
dep[tt]=dep[x]+1;
fa[tt][0]=x;
for(int i=1;i<B;++i)fa[tt][i]=fa[fa[tt][i-1]][i-1];
Basis::ins(mul(v,2));
}
else if(o==2)
{
cin>>x>>y>>v;
Basis::ins(add(dec(add(val[x],val[y]),mul(val[LCA(x,y)],2)),v));
}
else
{
cin>>x>>y;
cout<<Basis::ask(dec(add(val[x],val[y]),mul(val[LCA(x,y)],2)))<<"\n";
}
}
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5736kb
input:
30 7 3 1 1 301 1 1 236 1 2 278 3 2 4 3 2 4 2 1 4 265 1 1 242 1 4 278 1 6 337 3 2 3 2 5 7 304 2 5 6 34 1 4 178 3 6 7 3 5 7 3 1 4 1 1 178 3 3 4 3 1 6 3 3 4 2 6 7 131 1 1 213 3 1 3 2 3 10 11 3 4 6 2 5 9 169 1 6 9 2 5 10 29 1 9 111 3 9 11
output:
25 25 0 0 0 0 0 0 0 0 0 0
result:
wrong answer 1st lines differ - expected: '0', found: '25'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 361ms
memory: 14236kb
input:
198517 3 16 1 1 40710744 1 2 21885097 1 1 23592366 1 4 7387074 1 5 16074177 1 1 41027400 1 4 18082971 1 2 12822448 1 1 2286557 1 1 27896295 1 11 14532760 1 8 2357296 1 11 9190559 1 6 40503152 3 4 11 3 1 7 3 3 7 3 8 14 3 12 15 3 2 3 1 10 34606866 1 13 42718465 1 16 30353561 3 5 11 3 2 6 3 16 18 1 3 2...
output:
0 0 0 244 244 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 4th lines differ - expected: '0', found: '244'
Subtask #4:
score: 0
Wrong Answer
Test #26:
score: 19
Accepted
time: 56ms
memory: 10068kb
input:
198891 26426880 1 1 1 0 2 1 2 0 3 1 2 1 1 0 3 2 3 3 1 2 1 2 0 1 2 0 1 3 0 1 6 0 2 1 6 0 2 3 6 0 3 2 3 1 2 13213440 1 2 13213440 1 4 13213440 3 4 10 1 1 13213440 2 3 4 0 2 3 8 13213440 1 1 0 1 12 0 1 13 0 1 3 0 3 2 11 3 2 12 2 11 14 13213440 1 6 0 2 12 14 0 2 1 2 0 1 10 0 1 12 0 2 3 13 0 3 12 14 3 1 ...
output:
0 0 0 0 13213440 13213440 0 0 0 13213440 0 0 13213440 0 13213440 0 13213440 0 13213440 13213440 13213440 13213440 13213440 0 13213440 13213440 0 13213440 13213440 0 0 0 13213440 0 13213440 0 13213440 0 0 0 13213440 13213440 0 13213440 13213440 13213440 13213440 0 13213440 13213440 13213440 13213440 ...
result:
ok 66344 lines
Test #27:
score: 0
Accepted
time: 59ms
memory: 12136kb
input:
199011 22494024 1 1 1 11247012 1 1 11247012 2 1 2 11247012 3 1 3 1 3 11247012 2 1 4 0 1 1 11247012 1 2 11247012 2 4 5 11247012 3 1 2 1 5 0 3 2 5 2 5 6 11247012 2 2 3 0 1 1 11247012 3 4 8 2 1 5 11247012 3 5 7 1 6 11247012 1 4 0 3 1 7 2 1 9 11247012 1 7 11247012 2 3 4 11247012 3 4 5 2 1 9 11247012 3 5...
output:
11247012 11247012 0 11247012 0 11247012 11247012 11247012 0 11247012 0 0 0 11247012 11247012 11247012 11247012 11247012 11247012 11247012 0 11247012 11247012 11247012 11247012 11247012 11247012 0 0 0 11247012 11247012 11247012 0 0 0 0 11247012 0 11247012 11247012 0 11247012 0 0 11247012 0 11247012 1...
result:
ok 66431 lines
Test #28:
score: 0
Accepted
time: 59ms
memory: 12192kb
input:
198242 23269680 1 1 1 11634840 2 1 2 11634840 3 1 2 2 1 2 11634840 1 1 11634840 1 1 0 1 2 0 1 1 0 2 2 6 11634840 2 2 6 11634840 3 4 6 3 5 6 1 6 11634840 2 3 6 11634840 3 2 7 2 2 5 0 2 2 3 0 2 2 3 0 2 3 7 0 2 2 3 0 3 1 3 3 2 5 2 1 3 11634840 3 3 6 3 2 5 3 5 7 2 1 6 0 1 4 0 1 4 11634840 2 7 8 11634840...
output:
11634840 0 11634840 0 11634840 0 11634840 0 0 0 0 11634840 11634840 0 11634840 11634840 0 0 11634840 0 11634840 11634840 11634840 11634840 11634840 11634840 11634840 11634840 11634840 0 11634840 11634840 11634840 11634840 0 11634840 11634840 11634840 11634840 0 0 11634840 0 11634840 11634840 1163484...
result:
ok 66135 lines
Test #29:
score: -19
Wrong Answer
time: 56ms
memory: 12044kb
input:
198177 22462440 1 1 1 15723708 3 1 2 1 2 0 3 2 3 2 2 3 17969952 2 1 2 20216196 1 1 15723708 3 2 3 2 1 3 11231220 2 1 2 11231220 1 1 11231220 2 1 3 2246244 2 1 2 20216196 3 3 4 1 4 8984976 2 5 6 4492488 2 3 6 4492488 2 2 5 4492488 1 4 17969952 1 6 20216196 3 3 7 1 1 15723708 1 4 0 3 3 9 3 1 5 1 7 449...
output:
15723708 0 0 0 0 0 2246244 2246244 2246244 0 0 2246244 0 0 0 0 2246244 2246244 0 2246244 0 0 0 0 0 2246244 2246244 0 0 2246244 2246244 0 0 0 2246244 2246244 2246244 0 2246244 0 2246244 0 0 0 0 2246244 0 0 2246244 2246244 0 0 0 0 2246244 0 2246244 0 0 0 2246244 0 2246244 2246244 2246244 0 2246244 0 2...
result:
wrong answer 1st lines differ - expected: '2246244', found: '15723708'
Subtask #5:
score: 15
Accepted
Test #30:
score: 15
Accepted
time: 330ms
memory: 12172kb
input:
199458 2 25 1 1 31252443 2 1 2 22827339 1 2 13517756 1 2 5635412 1 3 33397078 1 3 33542998 2 3 5 1484991 3 5 6 2 1 3 7938846 2 1 2 3665458 1 3 29150948 3 4 5 1 3 733545 1 7 4698781 1 7 21699192 1 6 10854390 3 3 8 3 4 8 1 2 6889338 2 1 12 27646676 2 6 8 24407215 1 11 20847453 3 4 13 1 6 16891344 3 4 ...
output:
150016 891079 733545 1048849 7306736 7012 6336311 7310241 705870 794721 112806 777734 2522042 203310 370916 2339461 699806 747148 597151 969956 2633367 376785 884917 884917 331441 2696956 2423527 2304668 2457533 2783258 690228 864462 360811 124716 2098167 48248 2869827 605003 235881 2739062 2861794 ...
result:
ok 66461 lines
Test #31:
score: 0
Accepted
time: 328ms
memory: 12056kb
input:
198986 2 25 1 1 11331234 1 2 24833898 2 1 3 10628416 3 2 3 1 3 6115878 2 2 4 23717273 1 3 18406568 2 2 4 1949969 1 4 6063130 1 6 25760596 3 1 2 3 5 7 3 5 6 3 2 6 3 1 7 1 6 31753825 3 1 4 2 3 4 6115878 3 2 6 2 3 5 22447229 3 1 3 2 3 4 6115878 2 4 7 1813362 3 2 4 2 1 8 8192320 3 3 5 1 7 114729 1 9 188...
output:
969698 11331234 9443776 2324169 990686 1086581 11610035 990686 10628416 1949969 2269429 1949969 571284 3254790 682010 502346 824812 623366 377762 377762 2376509 884877 2316090 2244147 665245 341785 922389 928237 744294 69811 404242 789948 620664 513259 317968 222762 169970 969698 12365 1046658 91964...
result:
ok 65927 lines
Test #32:
score: 0
Accepted
time: 344ms
memory: 12144kb
input:
198119 2 25 1 1 1988220 2 1 2 10935842 2 1 2 10935842 3 1 2 1 2 9175257 2 1 2 30426983 1 3 21520990 1 2 7244347 2 3 5 19700729 1 3 24753647 3 4 6 2 1 2 30426983 3 2 4 1 6 25686082 2 1 6 22244116 1 7 20608501 3 3 6 1 2 29561714 2 2 3 21107138 1 1 21122181 1 6 7460982 2 7 9 19503627 1 9 8058976 3 1 8 ...
output:
1988220 3266481 684956 994474 48107 1167209 4443137 4685362 1360512 4639448 238700 348592 278885 295451 489693 344667 180320 328346 407326 454344 485048 139415 148539 301162 209675 136220 454344 201497 48475 346271 411773 397728 487925 400145 418154 120548 273314 523155 476405 141994 243836 128983 7...
result:
ok 65949 lines
Subtask #6:
score: 3
Accepted
Test #33:
score: 3
Accepted
time: 18ms
memory: 7816kb
input:
49958 1023 2 1 1 122428 1 1 917186 2 2 3 53148 1 3 876461 2 1 3 968146 2 2 4 569341 2 3 4 199413 2 1 4 238371 1 3 127427 1 2 887225 2 1 4 776059 2 4 6 155479 2 1 6 795533 1 5 159578 3 5 6 2 2 5 758778 2 5 6 601115 3 4 7 1 4 202224 2 5 6 902346 3 1 6 3 5 7 3 3 5 1 2 791251 1 5 502214 2 6 7 929048 1 6...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 16607 lines
Test #34:
score: 0
Accepted
time: 235ms
memory: 10180kb
input:
198392 7 9 1 1 23598910 3 1 2 1 1 25616681 2 1 2 22101090 2 2 3 25455751 3 1 2 3 1 2 1 3 25668120 3 1 3 1 3 23878180 1 4 10885281 1 1 5873751 2 2 7 31608236 3 2 3 3 3 5 2 2 6 37313936 2 1 6 36853293 2 4 7 6773989 2 1 7 19143946 3 2 7 3 3 7 3 1 2 1 1 31756932 3 3 6 2 5 8 39585364 1 2 27162269 3 4 5 2...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 65758 lines
Subtask #7:
score: 0
Skipped
Dependency #1:
0%