답안 #898587

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
898587 2024-01-04T22:48:58 Z alexander707070 Sprinkler (JOI22_sprinkler) C++14
38 / 100
720 ms 295928 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 id,int v,int l,int r,int pos){
    if(l==r)return tree[id][v];
    
    int tt=(l+r)/2;
    if(pos<=tt)return (getval(id,2*v,l,tt,pos) * tree[id][v])%mod;
    return (getval(id,2*v+1,tt+1,r,pos) * tree[id][v])%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>2)return 1;

    long long res=1;
    for(int i=dist;i<=2;i++){
        res*=getval(i,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 18 ms 94044 KB Output is correct
2 Correct 10 ms 94044 KB Output is correct
3 Correct 10 ms 94040 KB Output is correct
4 Incorrect 12 ms 96092 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 94044 KB Output is correct
2 Correct 618 ms 281868 KB Output is correct
3 Correct 333 ms 287424 KB Output is correct
4 Correct 456 ms 292864 KB Output is correct
5 Correct 462 ms 287012 KB Output is correct
6 Correct 440 ms 286496 KB Output is correct
7 Correct 451 ms 287312 KB Output is correct
8 Correct 396 ms 287808 KB Output is correct
9 Correct 607 ms 295760 KB Output is correct
10 Correct 408 ms 295376 KB Output is correct
11 Correct 636 ms 286880 KB Output is correct
12 Correct 340 ms 287352 KB Output is correct
13 Correct 315 ms 287596 KB Output is correct
14 Correct 334 ms 288284 KB Output is correct
15 Correct 300 ms 287316 KB Output is correct
16 Correct 316 ms 287912 KB Output is correct
17 Correct 313 ms 288356 KB Output is correct
18 Correct 10 ms 94044 KB Output is correct
19 Correct 11 ms 94044 KB Output is correct
20 Correct 11 ms 94044 KB Output is correct
21 Correct 11 ms 94044 KB Output is correct
22 Correct 11 ms 94044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 94044 KB Output is correct
2 Correct 618 ms 281868 KB Output is correct
3 Correct 333 ms 287424 KB Output is correct
4 Correct 456 ms 292864 KB Output is correct
5 Correct 462 ms 287012 KB Output is correct
6 Correct 440 ms 286496 KB Output is correct
7 Correct 451 ms 287312 KB Output is correct
8 Correct 396 ms 287808 KB Output is correct
9 Correct 607 ms 295760 KB Output is correct
10 Correct 408 ms 295376 KB Output is correct
11 Correct 636 ms 286880 KB Output is correct
12 Correct 340 ms 287352 KB Output is correct
13 Correct 315 ms 287596 KB Output is correct
14 Correct 334 ms 288284 KB Output is correct
15 Correct 300 ms 287316 KB Output is correct
16 Correct 316 ms 287912 KB Output is correct
17 Correct 313 ms 288356 KB Output is correct
18 Correct 10 ms 94044 KB Output is correct
19 Correct 11 ms 94044 KB Output is correct
20 Correct 11 ms 94044 KB Output is correct
21 Correct 11 ms 94044 KB Output is correct
22 Correct 11 ms 94044 KB Output is correct
23 Correct 10 ms 94040 KB Output is correct
24 Correct 619 ms 286804 KB Output is correct
25 Correct 471 ms 287252 KB Output is correct
26 Correct 484 ms 295928 KB Output is correct
27 Correct 488 ms 287060 KB Output is correct
28 Correct 482 ms 287216 KB Output is correct
29 Correct 479 ms 287156 KB Output is correct
30 Correct 467 ms 287748 KB Output is correct
31 Correct 589 ms 293116 KB Output is correct
32 Correct 362 ms 295656 KB Output is correct
33 Correct 659 ms 286976 KB Output is correct
34 Correct 384 ms 287308 KB Output is correct
35 Correct 11 ms 94040 KB Output is correct
36 Correct 11 ms 94144 KB Output is correct
37 Correct 10 ms 94044 KB Output is correct
38 Correct 11 ms 94004 KB Output is correct
39 Correct 10 ms 94040 KB Output is correct
40 Correct 10 ms 94044 KB Output is correct
41 Correct 10 ms 94044 KB Output is correct
42 Correct 10 ms 94040 KB Output is correct
43 Correct 10 ms 94044 KB Output is correct
44 Correct 11 ms 94144 KB Output is correct
45 Correct 10 ms 94044 KB Output is correct
46 Correct 10 ms 94132 KB Output is correct
47 Correct 11 ms 94044 KB Output is correct
48 Correct 11 ms 94044 KB Output is correct
49 Correct 10 ms 94040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 94044 KB Output is correct
2 Incorrect 720 ms 287912 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 94040 KB Output is correct
2 Incorrect 633 ms 287360 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 94044 KB Output is correct
2 Correct 10 ms 94044 KB Output is correct
3 Correct 10 ms 94040 KB Output is correct
4 Incorrect 12 ms 96092 KB Output isn't correct
5 Halted 0 ms 0 KB -