QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#792322 | #8950. 树据结构 | misfits# | 0 | 0ms | 28916kb | C++14 | 2.9kb | 2024-11-29 09:04:16 | 2024-11-29 09:04:18 |
Judging History
answer
#include<bits/stdc++.h>
#define LL int
#define SZ(x) ((LL)(x.size()))
#define all(x) (x).begin(),(x).end()
using namespace std;
inline LL read(){
LL q=0,w=1;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){q=q*10+(ch-'0');ch=getchar();}
return q*w;
}
void write(LL x){
if(x<0){putchar('-');x=(-x);}
if(x>9)write(x/10);
putchar('0'+x%10);
}
inline void writeln(LL x){write(x);puts("");}
inline void writecs(LL x){write(x);putchar(' ');}
inline void dmin(LL &x,LL y){if(x>y)x=y;return ;}
inline void dmax(LL &x,LL y){if(x<y)x=y;return ;}
#define cout cerr
#define pb push_back
const LL N = 100000+95 , M = 450 ;
LL n,m,fa[N];vector<LL>E[N];
struct atom{LL l,r,d;};atom dat[N][M];
LL dep[N],rep[N],ext[M],tag[N<<1][M];vector<LL>vc[N];LL a[N];
int main(){
n=read();m=read();dep[1]=1;vc[dep[1]].pb(1);LL mx=1;
for(LL t=2;t<=n;t++){fa[t]=read();E[fa[t]].pb(t);dep[t]=dep[fa[t]]+1;dmax(mx,dep[t]);vc[dep[t]].pb(t);}
vector<LL>vec;vec.pb(0);for(LL t=1;t<=mx;t++)vec.pb(SZ(vc[t]));
sort(all(vec));vec.erase(unique(all(vec)),vec.end());LL lim=SZ(vec)-1;
// cout<<" vec : ";for(auto d:vec)cout<<d<<" ";cout<<endl;
for(LL t=1;t<=n;t++){
LL l=1,r=lim,pos=-1;
while(l<=r){
LL mid=(l+r)>>1;
if(vec[mid]<=SZ(vc[dep[t]])){l=mid+1;pos=mid;}
else {r=mid-1;}
}
// cout<<" pos = "<<pos<<endl;
// cout<<" vec[pos] = "<<vec[pos]<<endl;
assert(pos!=-1&&vec[pos]==SZ(vc[dep[t]]));rep[t]=pos;dmax(ext[rep[t]],dep[t]);
}
for(LL t=1;t<=n;t++)
for(LL i=1;i<=lim;i++)dat[t][i]=(atom){n+1,0,n+1};
for(LL x=n;x>=1;x--){
dat[x][rep[x]]=(atom){x,x,dep[x]};
for(auto y:E[x])
for(LL i=rep[x]+1;i<=n;i++){
dmin(dat[x][i].l,dat[y][i].l);
dmax(dat[x][i].r,dat[y][i].r);
dmin(dat[x][i].d,dat[y][i].d);
}
}
/* for(LL x=1;x<=n;x++){
for(LL i=1;i<=lim;i++)
if(dat[x][i].l!=n+1){
cout<<" -> x = "<<x<<" vec[i] = "<<vec[i]<<" dat[x][i] : l = "<<dat[x][i].l<<" r = "<<dat[x][i].r<<" d = "<<dat[x][i].d<<endl;
}
cout<<endl;
}*/
LL dt=0,TC=m;
while(TC--){
LL opt=read();
if(opt==1){
LL x=read(),y=read();
for(LL i=rep[x];i<=lim;i++){
LL B=vec[i];LL k=ext[i]-dat[x][i].d+1;
LL l=dat[x][i].l,r=dat[x][i].r;
tag[(m-dt)+l][i]+=y;
if(r+1<=m+n)tag[(m-dt)+r+1][i]-=y;
if(l+k*B<=m+n)tag[(m-dt)+l+k*B][i]-=y;
if(r+1+k*B<=m*n)tag[(m-dt)+r+1+k*B][i]+=y;
}
}
else {dt++;}
}
for(LL x=1;x<=m+n;x++)
for(LL i=1;i<=lim;i++)tag[x][i]+=tag[x-1][i];
for(LL x=1;x<=m+n;x++)
for(LL i=1;i<=lim;i++)if(x+vec[i]<=m+n)tag[x+vec[i]][i]+=tag[x][i];
LL ans=0;
for(LL i=1;i<=n;i++){
LL x=m+i,u=0;
while(x>=1){
for(LL j=1;j<=lim;j++)u+=tag[x][j];
x-=n;
}
ans^=u;
// cout<<" -> i = "<<i<<" u = "<<u<<endl;
}
writeln(ans);
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 28916kb
input:
994 980 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 88 89 90 91 92 93 94 95 96 97 9...
output:
893041385
result:
wrong answer 1st lines differ - expected: '1003408', found: '893041385'
Subtask #2:
score: 0
Time Limit Exceeded
Test #13:
score: 0
Time Limit Exceeded
input:
98132 98277 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...
output:
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #25:
score: 0
Time Limit Exceeded
input:
98694 98643 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...
output:
result:
Subtask #4:
score: 0
Time Limit Exceeded
Test #37:
score: 0
Time Limit Exceeded
input:
65535 98062 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 ...
output:
result:
Subtask #5:
score: 0
Time Limit Exceeded
Test #49:
score: 0
Time Limit Exceeded
input:
99562 98687 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...
output:
result:
Subtask #6:
score: 0
Time Limit Exceeded
Test #61:
score: 0
Time Limit Exceeded
input:
49861 49257 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...
output:
result:
Subtask #7:
score: 0
Time Limit Exceeded
Test #73:
score: 0
Time Limit Exceeded
input:
98390 98942 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...