답안 #898590

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
898590 2024-01-04T22:58:21 Z alexander707070 Sprinkler (JOI22_sprinkler) C++14
3 / 100
4000 ms 284436 KB
#include<bits/stdc++.h>
#define MAXN 200007
using namespace std;

int n,q,type;
long long mod,w;
int a,b,s,d;
vector<int> v[MAXN];
int num[MAXN],tt,from[MAXN],to[MAXN],parent[MAXN];

long long tree[42][4*MAXN],val[MAXN];

void dfs(int x,int p){
    from[x]=n; to[x]=0;
    parent[x]=p;

    for(int i=0;i<v[x].size();i++){
        if(v[x][i]==p)continue;

        tt++; num[v[x][i]]=tt;
        from[x]=min(from[x],tt);
        to[x]=max(to[x],tt);
    }

    for(int i=0;i<v[x].size();i++){
        if(v[x][i]==p)continue;
        dfs(v[x][i],x);
    }
}

void update(int id,int v,int l,int r,int ll,int rr,long long val){
    if(ll>rr)return;
    if(l==ll and r==rr){
        tree[id][v]*=val; tree[id][v]%=mod;
    }else{
        int tt=(l+r)/2;
        update(id,2*v,l,tt,ll,min(tt,rr),val);
        update(id,2*v+1,tt+1,r,max(tt+1,ll),rr,val);
    }
}

long long getval(int from,int to,int v,int l,int r,int pos){
    if(l==r){
        long long res=1;
        for(int i=from;i<=to;i++){
            res*=tree[i][v]; res%=mod;
        }
        return res;
    }

    long long res=1;
    for(int i=from;i<=to;i++){
        res*=tree[i][v]; res%=mod;
    }
    
    int tt=(l+r)/2;
    if(pos<=tt)return (getval(from,to,2*v,l,tt,pos) * res)%mod;
    return (getval(from,to,2*v+1,tt+1,r,pos) * res)%mod;
}

void query(int x,int dist,int ban,long long mult){
    if(x==0)return;
    val[x]*=mult; val[x]%=mod;
    if(dist==0)return;

    if(ban>=from[x] and ban<=to[x]){
        update(dist-1,1,1,n,from[x],ban-1,mult);
        update(dist-1,1,1,n,ban+1,to[x],mult);
    }else{
        update(dist-1,1,1,n,from[x],to[x],mult);
    }

    query(parent[x],dist-1,num[x],mult);
}

long long geth(int x,int dist){
    if(x==0 or dist>40)return 1;

    long long res=1;
    res*=getval(dist,40,1,1,n,num[x]);
    res%=mod;

    return (res*geth(parent[x],dist+1))%mod;
}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>mod;
    for(int i=1;i<=n-1;i++){
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i=0;i<=40;i++){
        for(int f=1;f<=4*n;f++){
            tree[i][f]=1;
        }
    }

    num[1]=1; tt=1;
    dfs(1,0);

    for(int i=1;i<=n;i++){
        cin>>val[i];
    }

    cin>>q;
    for(int i=1;i<=q;i++){
        cin>>type;
        if(type==1){
            cin>>s>>d>>w;
            query(s,d,0,w);
        }else{
            cin>>s;
            cout<<( val[s]*geth(s,0) )%mod<<"\n";
        }
    }

    return 0;
}

Compilation message

sprinkler.cpp: In function 'void dfs(int, int)':
sprinkler.cpp:17:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
sprinkler.cpp:25:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 94040 KB Output is correct
2 Correct 11 ms 94296 KB Output is correct
3 Correct 10 ms 94048 KB Output is correct
4 Correct 32 ms 96092 KB Output is correct
5 Correct 32 ms 96268 KB Output is correct
6 Correct 22 ms 96092 KB Output is correct
7 Correct 20 ms 96092 KB Output is correct
8 Correct 15 ms 96092 KB Output is correct
9 Correct 11 ms 94168 KB Output is correct
10 Correct 12 ms 94160 KB Output is correct
11 Correct 11 ms 94044 KB Output is correct
12 Correct 13 ms 94044 KB Output is correct
13 Correct 13 ms 94092 KB Output is correct
14 Correct 11 ms 94044 KB Output is correct
15 Correct 11 ms 94044 KB Output is correct
16 Correct 11 ms 94044 KB Output is correct
17 Correct 12 ms 94020 KB Output is correct
18 Correct 15 ms 94044 KB Output is correct
19 Correct 11 ms 94040 KB Output is correct
20 Correct 12 ms 94044 KB Output is correct
21 Correct 14 ms 94088 KB Output is correct
22 Correct 13 ms 94044 KB Output is correct
23 Correct 13 ms 94300 KB Output is correct
24 Correct 10 ms 94040 KB Output is correct
25 Correct 11 ms 94044 KB Output is correct
26 Correct 11 ms 94040 KB Output is correct
27 Correct 13 ms 94044 KB Output is correct
28 Correct 13 ms 94044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 94044 KB Output is correct
2 Execution timed out 4081 ms 275684 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 94044 KB Output is correct
2 Execution timed out 4081 ms 275684 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 94040 KB Output is correct
2 Execution timed out 4066 ms 284436 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 94044 KB Output is correct
2 Execution timed out 4070 ms 281708 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 94040 KB Output is correct
2 Correct 11 ms 94296 KB Output is correct
3 Correct 10 ms 94048 KB Output is correct
4 Correct 32 ms 96092 KB Output is correct
5 Correct 32 ms 96268 KB Output is correct
6 Correct 22 ms 96092 KB Output is correct
7 Correct 20 ms 96092 KB Output is correct
8 Correct 15 ms 96092 KB Output is correct
9 Correct 11 ms 94168 KB Output is correct
10 Correct 12 ms 94160 KB Output is correct
11 Correct 11 ms 94044 KB Output is correct
12 Correct 13 ms 94044 KB Output is correct
13 Correct 13 ms 94092 KB Output is correct
14 Correct 11 ms 94044 KB Output is correct
15 Correct 11 ms 94044 KB Output is correct
16 Correct 11 ms 94044 KB Output is correct
17 Correct 12 ms 94020 KB Output is correct
18 Correct 15 ms 94044 KB Output is correct
19 Correct 11 ms 94040 KB Output is correct
20 Correct 12 ms 94044 KB Output is correct
21 Correct 14 ms 94088 KB Output is correct
22 Correct 13 ms 94044 KB Output is correct
23 Correct 13 ms 94300 KB Output is correct
24 Correct 10 ms 94040 KB Output is correct
25 Correct 11 ms 94044 KB Output is correct
26 Correct 11 ms 94040 KB Output is correct
27 Correct 13 ms 94044 KB Output is correct
28 Correct 13 ms 94044 KB Output is correct
29 Correct 10 ms 94044 KB Output is correct
30 Execution timed out 4081 ms 275684 KB Time limit exceeded
31 Halted 0 ms 0 KB -