QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#210958#6322. Forestryucup-team870WA 868ms559200kbC++172.7kb2023-10-11 21:55:042023-10-11 21:55:05

Judging History

你现在查看的是最新测评结果

  • [2023-10-11 21:55:05]
  • 评测
  • 测评结果:WA
  • 用时:868ms
  • 内存:559200kb
  • [2023-10-11 21:55:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define per(i,j,k) for(int i=j;i>=k;--i)
#define P pair<int,int>
#define ll long long
#define vi vector<int>
#define mi int mid=(l+r)>>1;
// #define db double
const int N=3e5+5,V=62,mod=998244353,inf=1e9+7;
int ls[N*V],rs[N*V]; 
ll s1[N*V],s2[N*V],tag[N*V];
int Rt[N],a[N],tot;
ll qp(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)res=res*x%mod;
        x=x*x%mod; y>>=1;
    }
    return res;
}
const int i2=qp(2,mod-2);
vi tu[N];
void pu(int i){
    s1[i]=(s1[ls[i]]+s1[rs[i]])%mod; s2[i]=(s2[ls[i]]+s2[rs[i]])%mod;
}
void ud(int i,ll v){
    tag[i]=tag[i]*v%mod; s1[i]=s1[i]*v%mod; s2[i]=s2[i]*v%mod;
}
void pd(int i){
    if(tag[i]==1)return;
    ud(ls[i],tag[i]); ud(rs[i],tag[i]); tag[i]=1;
}
int crt(int rt,int l,int r,int x){
    int now=++tot; tag[now]=1;
    if(l==r){
        s1[now]=1; s2[now]=l; return now;
    }
    mi pd(rt);
    if(mid>=x)ls[now]=crt(ls[rt],l,mid,x),rs[now]=rs[rt];
    else rs[now]=crt(rs[rt],mid+1,r,x),ls[now]=ls[rt];
    pu(now);
    return now;
}
int mg(int rt1,int rt2,int l,int r,ll v1,ll v2){
    if(!rt1){
        ud(rt2,v1); return rt2;
    }
    if(!rt2){
        ud(rt1,v2); return rt1;
    }
    if(l==r){
        ud(rt1,(v2+s1[rt2])%mod); ud(rt2,v1);
        s1[rt1]=(s1[rt1]+s1[rt2])%mod; s2[rt1]=(s2[rt1]+s2[rt2])%mod; return rt1;
    }
    mi
    pd(rt1); pd(rt2);
    ls[rt1]=mg(ls[rt1],ls[rt2],l,mid,v1+s1[rs[rt1]],v2+s1[rs[rt2]]);
    rs[rt1]=mg(rs[rt1],rs[rt2],mid+1,r,v1,v2);
    pu(rt1); return rt1;
}
ll ans;
void dfs1(int rt,int l,int r){
    if(!rt)return;
    if(l==r){
        cout<<l<<' '<<s1[rt]<<' '<<s2[rt]<<'\n';
    }
    mi
    pd(rt);
    dfs1(ls[rt],l,mid);
    dfs1(rs[rt],mid+1,r);
}
void dfs(int now,int pre){
    Rt[now]=crt(0,1,inf,a[now]);
    for(int son:tu[now]){
        if(son==pre)continue;
        dfs(son,now);
        ud(Rt[now],i2);
        Rt[son]=crt(Rt[son],1,inf,inf);
        Rt[now]=mg(Rt[now],Rt[son],1,inf,0,0);
    }
    ans=(ans+1ll*(now==1?1:i2)*s2[Rt[now]])%mod;
    // cout<<now<<"####\n";
    // dfs1(Rt[now],1,inf);
}
signed main(){
    // IOS
    // rep(i,1,8){
    //     rep(j,1,8){
    //         cout<<i*qp(j,mod-2)%mod<<' ';
    //     }
    //     cout<<'\n';
    // }
    int n;cin>>n;
    rep(i,1,n)cin>>a[i];
    rep(i,2,n){
        int u,v;cin>>u>>v;
        tu[u].push_back(v); tu[v].push_back(u);
    }
    dfs(1,0);
    cout<<ans*qp(2,n-1)%mod;
}
/*
499122177:1/2   748683265:1/4  873463809:1/8  
623902721:3/8  374341633:5/8
4
4 4 2 3
1 2
2 4
3 2
*/

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 14392kb

input:

4
1 2 3 4
1 2
2 4
3 2

output:

44

result:

ok 1 number(s): "44"

Test #2:

score: 0
Accepted
time: 0ms
memory: 14184kb

input:

5
3 5 6 5 1
4 1
2 3
3 5
1 3

output:

154

result:

ok 1 number(s): "154"

Test #3:

score: -100
Wrong Answer
time: 868ms
memory: 559200kb

input:

278989
864394090 384799247 186936242 598547507 962916136 540758021 158527118 688236322 682301622 948660645 881768181 481432818 557201870 794956026 205262301 920739629 141926922 990361777 818811172 150579096 1032726 328924563 638044961 21740781 484574329 737977343 113738003 345289940 363021157 582495...

output:

762295491

result:

wrong answer 1st numbers differ - expected: '434293031', found: '762295491'