QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#768332 | #7767. 数据结构 | oceeff | 0 | 1143ms | 310088kb | C++14 | 4.4kb | 2024-11-21 09:25:35 | 2024-11-21 09:25:36 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
using namespace std;typedef unsigned long long un;typedef vector<int> vi;int read(){int num=0,f=1;char c;while(!isdigit(c=getchar()))if(c=='-')f=-1;while(isdigit(c))num=num*10+(c&15),c=getchar();return num*f;}un readu(){un num=0;bool fl=0;char c;while(!isdigit(c=getchar()))if(c=='-')fl=1;while(isdigit(c))num=num*10+(c&15),c=getchar();return fl?-num:num;}void write(int x,char ch=' '){int F[20],cnt=0;if(!x)putchar('0');if(x<0)putchar('-'),x=-x;while(x)F[cnt++]=x%10+'0',x/=10;while(cnt)putchar(F[--cnt]);putchar(ch);}void writeu(un x,char ch=' '){int F[20],cnt=0;if(!x)putchar('0');if(x<0)x=-x,putchar('-');while(x)F[cnt++]=x%10+'0',x/=10;while(cnt)putchar(F[--cnt]);putchar(ch);}
namespace Main
{
const int N=200010,k=4;const un inf=1e18;int n,m,q,dfn[N],ti,dep[N],head[N],to[N<<1],nxt[N<<1],tot,fa[N],sz[N],son[N],top[N],op,x,y,z;un ans,w;vi e[N],xx,yy,zz;void link(int x,int y){to[++tot]=y,nxt[tot]=head[x],head[x]=tot;}struct nd{int x,y;nd(int X,int Y):x(X),y(Y){}};bool operator<(nd x,nd y){return x.x<y.x;}typedef vector<nd> vii;vii S[N],f[N][k],g[N][k],s[N][k],h[N][k],a;
void output(vii&x){printf("#%d\n",(int)x.size());for(auto i:x)printf("#%d %d\n",i.x,i.y);}void merge(vii&x,vii&y){if(!y.size())return;if(!x.size())return x=y,void();for(auto&i:y)x.emplace_back(i);}void chk(vii&x){if(!x.size())return;vii y;sort(x.begin(),x.end());for(auto i:x)if(y.size()&&y.back().y+1==i.x)y.back().y=i.y;else y.emplace_back(i);x=y;}int LCA(int x,int y){for(;top[x]!=top[y];){if(dep[top[x]]<dep[top[y]])swap(x,y);x=fa[top[x]];}return dep[x]<dep[y]?x:y;}vii sub(vii&x,vii&y){vii z;int n=(int)x.size(),m=(int)y.size();for(int i=0,j=0,xx,yy;i<n;++i){for(xx=x[i].x,yy=x[i].y;j<m&&y[j].y<=yy;++j){if(xx<y[j].x)z.emplace_back(xx,y[j].x-1);xx=y[j].y+1;}if(xx<=yy)z.emplace_back(xx,yy);}return z;}
namespace sgt{un s[N<<2],len[N<<2],tag[N<<2];void pushup(int k){s[k]=s[k<<1]+s[k<<1|1];}void U(int k,un z){tag[k]+=z,s[k]+=z*len[k];}void pushdown(int k){if(tag[k])U(k<<1,tag[k]),U(k<<1|1,tag[k]),tag[k]=0;}void build(int k,int l,int r){len[k]=r-l+1;if(l<r){int mid=(l+r)>>1;build(k<<1,l,mid),build(k<<1|1,mid+1,r);}}
void add(int k,int l,int r,int L,int R,un z){/*if(l==1&&r==n)printf("U %d %d %llu\n",L,R,z);*/if(L<=l&&r<=R)U(k,z);else{int mid=(l+r)>>1;pushdown(k);if(L<=mid)add(k<<1,l,mid,L,R,z);if(mid<R)add(k<<1|1,mid+1,r,L,R,z);pushup(k);}}un sum(int k,int l,int r,int L,int R){/*if(l==1&&r==n)printf("Q %d %d\n",L,R);*/if(L<=l&&r<=R)return s[k];int mid=(l+r)>>1;return pushdown(k),(L<=mid?sum(k<<1,l,mid,L,R):0)+(mid<R?sum(k<<1|1,mid+1,r,L,R):0);}}
void dfs1(int x){sz[x]=1,dep[x]=dep[fa[x]]+1;for(int i=head[x];i;i=nxt[i])if(to[i]!=fa[x])fa[to[i]]=x,e[x].emplace_back(to[i]),dfs1(to[i]),sz[x]+=sz[to[i]],son[x]=(sz[to[i]]>sz[son[x]]?to[i]:son[x]);}
void dfs2(int x){vi xx;for(int i=x;i;i=son[i])xx.emplace_back(i),top[i]=x;yy=xx;for(int t=0;t<k;++t){zz.clear();for(auto i:yy){if(!dfn[i])dfn[i]=++ti;for(auto j:e[i])zz.emplace_back(j);}yy=zz;}for(int x:xx)for(int i:e[x])if(i!=son[x])dfs2(i);}
void dfs3(int x){S[x].emplace_back(dfn[x],dfn[x]),f[x][0].emplace_back(dfn[x],dfn[x]);for(int y:e[x]){dfs3(y),g[y][0].emplace_back(dfn[x],dfn[x]),merge(S[x],S[y]);for(int i=1;i<k;++i)merge(g[y][i],f[x][i]),merge(f[x][i],f[y][i-1]),chk(f[x][i]);}for(int i=1;i<k;++i)chk(f[x][i]);vii rs[k];for(int I=(int)e[x].size(),y;I--;){y=e[x][I];for(int i=1;i<k;++i)merge(g[y][i],rs[i]),merge(rs[i],f[y][i-1]),chk(rs[i]),chk(g[y][i]);}chk(S[x]);}
void dfs4(int x){for(int i=0;i<k;++i)s[x][i]=f[x][i],merge(s[x][i],s[fa[x]][i]),chk(s[x][i]);for(int i=0;i<k;++i){h[x][i]=f[x][i],(i&&(merge(h[x][i],h[x][i-1]),0));for(int j=1,y=x;j<=i&&y;++j,y=fa[y])merge(h[x][i],g[y][i-j]);chk(h[x][i]);}for(auto y:e[x])dfs4(y);}void F(int x,int y,int k){vii z=sub(s[x][k],s[y][k]);merge(a,z);}
void main()
{
n=read(),m=read();for(int i=n;--i;)x=read(),y=read(),link(x,y),link(y,x);dfs1(1),dfs2(1),dfs3(1),dfs4(1),sgt::build(1,1,n);
for(;m--;){op=read(),x=read();if(op&1)y=read(),q=read(),z=LCA(x,y),a=h[z][q],F(x,z,q),F(y,z,q),chk(a);else a=S[x];if(op<=2){w=readu();for(auto i:a)sgt::add(1,1,n,i.x,i.y,w);}else{ans=0;for(auto i:a)ans+=sgt::sum(1,1,n,i.x,i.y);}writeu(ans,'\n');}
}
}
int main()
{
const bool base=0,IO=1;int T;if(!base)T=1;else if(IO)T=read();else ios::sync_with_stdio(0),cin>>T;for(;T--;)Main::main();
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 18ms
memory: 98024kb
input:
5000 5000 1 2 2 3 3 4 4 5 5 6 5 7 6 8 7 9 9 10 8 11 11 12 12 13 12 14 14 15 15 16 16 17 16 18 18 19 18 20 20 21 20 22 22 23 23 24 23 25 23 26 26 27 27 28 28 29 27 30 30 31 29 32 32 33 33 34 32 35 35 36 36 37 35 38 36 39 38 40 38 41 41 42 42 43 43 44 42 45 44 46 45 47 47 48 48 49 48 50 49 51 51 52 52...
output:
0 0 37227703492 2136305359188 2794367845468 1309925069860 1698169768858 2678958746332 2678958746332 2678958746332 2678958746332 2678958746332 2678958746332 2678958746332 6690595071246 6690595071246 6690595071246 6690595071246 2087826052960 2087826052960 2087826052960 5786332239171 5786332239171 5786...
result:
wrong answer 1st numbers differ - expected: '37227703492', found: '0'
Subtask #2:
score: 0
Wrong Answer
Test #3:
score: 0
Wrong Answer
time: 1143ms
memory: 302756kb
input:
200000 200000 1 2 1 3 1 4 3 5 1 6 1 7 7 8 8 9 2 10 1 11 5 12 1 13 7 14 10 15 2 16 7 17 11 18 5 19 5 20 1 21 16 22 1 23 3 24 20 25 14 26 2 27 6 28 15 29 10 30 15 31 5 32 13 33 12 34 31 35 31 36 36 37 36 38 1 39 28 40 5 41 12 42 41 43 20 44 30 45 22 46 11 47 47 48 45 49 14 50 41 51 3 52 30 53 29 54 6 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7615073807 4176911055 4176911055 4176911055 0 0 0 0 4745654848 6222845818 6222845818 6222845818 6222845818 0 0 0 0 9739142819 9739142819 9739142819 0 1424960716 5224818790 5224818790 9459319003 13717923473 13717923473 13717923473 8673060864 8673060864 86730608...
result:
wrong answer 9th numbers differ - expected: '7615073807', found: '0'
Subtask #3:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 373ms
memory: 269628kb
input:
200000 200000 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:
0 0 0 0 0 0 134315201201061 134315201201061 38210069287857 75889674481730 25202765567748 179527420359031 179527420359031 75824479907233 75824479907233 75824479907233 75824479907233 75824479907233 75824479907233 75824479907233 75824479907233 156951577189979 156951577189979 246509811214535 25138338731...
result:
wrong answer 2nd numbers differ - expected: '134315201201061', found: '0'
Subtask #4:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 879ms
memory: 310088kb
input:
200000 200000 1 2 2 3 3 4 1 5 3 6 5 7 5 8 7 9 2 10 7 11 11 12 10 13 6 14 3 15 14 16 4 17 11 18 3 19 14 20 4 21 4 22 12 23 18 24 5 25 5 26 14 27 13 28 24 29 11 30 26 31 29 32 28 33 31 34 23 35 33 36 6 37 11 38 22 39 13 40 35 41 37 42 21 43 12 44 4 45 16 46 12 47 21 48 1 49 26 50 45 51 41 52 46 53 7 5...
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:
wrong answer 259th numbers differ - expected: '782172417', found: '0'
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #4:
0%
Subtask #7:
score: 0
Skipped
Dependency #2:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
0%