답안 #899661

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
899661 2024-01-06T20:14:55 Z alexander707070 Sprinkler (JOI22_sprinkler) C++14
100 / 100
647 ms 94432 KB
#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define MAXN 200007
using namespace std;

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

long long mult[MAXN][42];

void dfs(int x,int p){
    parent[x]=p;

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

void query(int x,int dist,long long p){
    if(dist<0)return;

    if(dist==0){
        mult[x][dist]*=p;
        mult[x][dist]%=mod;
        return;
    }

    mult[x][dist]*=p;
    mult[x][dist]%=mod;

    mult[x][dist-1]*=p;
    mult[x][dist-1]%=mod;

    if(x!=0)query(parent[x],dist-1,p);
    else query(parent[x],dist-2,p);
}

long long getval(int x,int dist){
    if(dist==41)return 1;
    if(x==0)return mult[x][dist];

    return (mult[x][dist]*getval(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<=n;i++){
        for(int f=0;f<=40;f++){
            mult[i][f]=1;
        }
    }

    dfs(1,0);

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

    cin>>q;
    for(int i=1;i<=q;i++){
        cin>>type;
        if(type==1){
            cin>>s>>d>>w;
            query(s,d,w);
        }else{
            cin>>s;
            cout<<getval(s,0)<<"\n";
        }
    }

    return 0;
}

Compilation message

sprinkler.cpp: In function 'void dfs(int, int)':
sprinkler.cpp:18:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7772 KB Output is correct
2 Correct 2 ms 7896 KB Output is correct
3 Correct 2 ms 7772 KB Output is correct
4 Correct 3 ms 10076 KB Output is correct
5 Correct 3 ms 10076 KB Output is correct
6 Correct 3 ms 10072 KB Output is correct
7 Correct 3 ms 10076 KB Output is correct
8 Correct 2 ms 10076 KB Output is correct
9 Correct 2 ms 7772 KB Output is correct
10 Correct 2 ms 7772 KB Output is correct
11 Correct 2 ms 7772 KB Output is correct
12 Correct 2 ms 7772 KB Output is correct
13 Correct 2 ms 7772 KB Output is correct
14 Correct 2 ms 7772 KB Output is correct
15 Correct 2 ms 7772 KB Output is correct
16 Correct 2 ms 7772 KB Output is correct
17 Correct 2 ms 7772 KB Output is correct
18 Correct 2 ms 7772 KB Output is correct
19 Correct 2 ms 7768 KB Output is correct
20 Correct 2 ms 7768 KB Output is correct
21 Correct 2 ms 7900 KB Output is correct
22 Correct 3 ms 7772 KB Output is correct
23 Correct 2 ms 7772 KB Output is correct
24 Correct 2 ms 7772 KB Output is correct
25 Correct 2 ms 7772 KB Output is correct
26 Correct 2 ms 7772 KB Output is correct
27 Correct 2 ms 7872 KB Output is correct
28 Correct 2 ms 7772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7768 KB Output is correct
2 Correct 439 ms 81492 KB Output is correct
3 Correct 254 ms 78660 KB Output is correct
4 Correct 392 ms 82948 KB Output is correct
5 Correct 328 ms 80468 KB Output is correct
6 Correct 234 ms 79688 KB Output is correct
7 Correct 223 ms 80208 KB Output is correct
8 Correct 183 ms 80492 KB Output is correct
9 Correct 508 ms 86068 KB Output is correct
10 Correct 259 ms 82512 KB Output is correct
11 Correct 403 ms 81348 KB Output is correct
12 Correct 242 ms 78276 KB Output is correct
13 Correct 158 ms 79012 KB Output is correct
14 Correct 173 ms 79192 KB Output is correct
15 Correct 160 ms 78964 KB Output is correct
16 Correct 165 ms 78932 KB Output is correct
17 Correct 173 ms 79936 KB Output is correct
18 Correct 2 ms 7772 KB Output is correct
19 Correct 2 ms 7772 KB Output is correct
20 Correct 2 ms 7772 KB Output is correct
21 Correct 2 ms 7812 KB Output is correct
22 Correct 2 ms 7772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7768 KB Output is correct
2 Correct 439 ms 81492 KB Output is correct
3 Correct 254 ms 78660 KB Output is correct
4 Correct 392 ms 82948 KB Output is correct
5 Correct 328 ms 80468 KB Output is correct
6 Correct 234 ms 79688 KB Output is correct
7 Correct 223 ms 80208 KB Output is correct
8 Correct 183 ms 80492 KB Output is correct
9 Correct 508 ms 86068 KB Output is correct
10 Correct 259 ms 82512 KB Output is correct
11 Correct 403 ms 81348 KB Output is correct
12 Correct 242 ms 78276 KB Output is correct
13 Correct 158 ms 79012 KB Output is correct
14 Correct 173 ms 79192 KB Output is correct
15 Correct 160 ms 78964 KB Output is correct
16 Correct 165 ms 78932 KB Output is correct
17 Correct 173 ms 79936 KB Output is correct
18 Correct 2 ms 7772 KB Output is correct
19 Correct 2 ms 7772 KB Output is correct
20 Correct 2 ms 7772 KB Output is correct
21 Correct 2 ms 7812 KB Output is correct
22 Correct 2 ms 7772 KB Output is correct
23 Correct 2 ms 8024 KB Output is correct
24 Correct 407 ms 81452 KB Output is correct
25 Correct 253 ms 78160 KB Output is correct
26 Correct 400 ms 89600 KB Output is correct
27 Correct 327 ms 85216 KB Output is correct
28 Correct 231 ms 85332 KB Output is correct
29 Correct 216 ms 85072 KB Output is correct
30 Correct 178 ms 85956 KB Output is correct
31 Correct 539 ms 89232 KB Output is correct
32 Correct 272 ms 88748 KB Output is correct
33 Correct 399 ms 85804 KB Output is correct
34 Correct 254 ms 84416 KB Output is correct
35 Correct 2 ms 7772 KB Output is correct
36 Correct 2 ms 7772 KB Output is correct
37 Correct 3 ms 8284 KB Output is correct
38 Correct 2 ms 7848 KB Output is correct
39 Correct 2 ms 7772 KB Output is correct
40 Correct 2 ms 7916 KB Output is correct
41 Correct 2 ms 7904 KB Output is correct
42 Correct 2 ms 7772 KB Output is correct
43 Correct 2 ms 7772 KB Output is correct
44 Correct 2 ms 7772 KB Output is correct
45 Correct 2 ms 7772 KB Output is correct
46 Correct 2 ms 8020 KB Output is correct
47 Correct 2 ms 7772 KB Output is correct
48 Correct 2 ms 7772 KB Output is correct
49 Correct 2 ms 7772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7772 KB Output is correct
2 Correct 546 ms 85256 KB Output is correct
3 Correct 603 ms 86652 KB Output is correct
4 Correct 465 ms 86544 KB Output is correct
5 Correct 365 ms 82880 KB Output is correct
6 Correct 256 ms 83024 KB Output is correct
7 Correct 237 ms 83552 KB Output is correct
8 Correct 188 ms 83652 KB Output is correct
9 Correct 566 ms 86120 KB Output is correct
10 Correct 584 ms 87380 KB Output is correct
11 Correct 411 ms 83028 KB Output is correct
12 Correct 404 ms 82556 KB Output is correct
13 Correct 308 ms 84088 KB Output is correct
14 Correct 317 ms 84592 KB Output is correct
15 Correct 2 ms 7772 KB Output is correct
16 Correct 2 ms 7772 KB Output is correct
17 Correct 2 ms 7772 KB Output is correct
18 Correct 2 ms 7920 KB Output is correct
19 Correct 2 ms 7772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7772 KB Output is correct
2 Correct 552 ms 92636 KB Output is correct
3 Correct 576 ms 90060 KB Output is correct
4 Correct 466 ms 91132 KB Output is correct
5 Correct 375 ms 88616 KB Output is correct
6 Correct 269 ms 88660 KB Output is correct
7 Correct 261 ms 88580 KB Output is correct
8 Correct 193 ms 88684 KB Output is correct
9 Correct 544 ms 93524 KB Output is correct
10 Correct 587 ms 92544 KB Output is correct
11 Correct 422 ms 89304 KB Output is correct
12 Correct 402 ms 87792 KB Output is correct
13 Correct 312 ms 88656 KB Output is correct
14 Correct 313 ms 88964 KB Output is correct
15 Correct 2 ms 7772 KB Output is correct
16 Correct 2 ms 7772 KB Output is correct
17 Correct 2 ms 7772 KB Output is correct
18 Correct 2 ms 7772 KB Output is correct
19 Correct 2 ms 7816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7772 KB Output is correct
2 Correct 2 ms 7896 KB Output is correct
3 Correct 2 ms 7772 KB Output is correct
4 Correct 3 ms 10076 KB Output is correct
5 Correct 3 ms 10076 KB Output is correct
6 Correct 3 ms 10072 KB Output is correct
7 Correct 3 ms 10076 KB Output is correct
8 Correct 2 ms 10076 KB Output is correct
9 Correct 2 ms 7772 KB Output is correct
10 Correct 2 ms 7772 KB Output is correct
11 Correct 2 ms 7772 KB Output is correct
12 Correct 2 ms 7772 KB Output is correct
13 Correct 2 ms 7772 KB Output is correct
14 Correct 2 ms 7772 KB Output is correct
15 Correct 2 ms 7772 KB Output is correct
16 Correct 2 ms 7772 KB Output is correct
17 Correct 2 ms 7772 KB Output is correct
18 Correct 2 ms 7772 KB Output is correct
19 Correct 2 ms 7768 KB Output is correct
20 Correct 2 ms 7768 KB Output is correct
21 Correct 2 ms 7900 KB Output is correct
22 Correct 3 ms 7772 KB Output is correct
23 Correct 2 ms 7772 KB Output is correct
24 Correct 2 ms 7772 KB Output is correct
25 Correct 2 ms 7772 KB Output is correct
26 Correct 2 ms 7772 KB Output is correct
27 Correct 2 ms 7872 KB Output is correct
28 Correct 2 ms 7772 KB Output is correct
29 Correct 2 ms 7768 KB Output is correct
30 Correct 439 ms 81492 KB Output is correct
31 Correct 254 ms 78660 KB Output is correct
32 Correct 392 ms 82948 KB Output is correct
33 Correct 328 ms 80468 KB Output is correct
34 Correct 234 ms 79688 KB Output is correct
35 Correct 223 ms 80208 KB Output is correct
36 Correct 183 ms 80492 KB Output is correct
37 Correct 508 ms 86068 KB Output is correct
38 Correct 259 ms 82512 KB Output is correct
39 Correct 403 ms 81348 KB Output is correct
40 Correct 242 ms 78276 KB Output is correct
41 Correct 158 ms 79012 KB Output is correct
42 Correct 173 ms 79192 KB Output is correct
43 Correct 160 ms 78964 KB Output is correct
44 Correct 165 ms 78932 KB Output is correct
45 Correct 173 ms 79936 KB Output is correct
46 Correct 2 ms 7772 KB Output is correct
47 Correct 2 ms 7772 KB Output is correct
48 Correct 2 ms 7772 KB Output is correct
49 Correct 2 ms 7812 KB Output is correct
50 Correct 2 ms 7772 KB Output is correct
51 Correct 2 ms 8024 KB Output is correct
52 Correct 407 ms 81452 KB Output is correct
53 Correct 253 ms 78160 KB Output is correct
54 Correct 400 ms 89600 KB Output is correct
55 Correct 327 ms 85216 KB Output is correct
56 Correct 231 ms 85332 KB Output is correct
57 Correct 216 ms 85072 KB Output is correct
58 Correct 178 ms 85956 KB Output is correct
59 Correct 539 ms 89232 KB Output is correct
60 Correct 272 ms 88748 KB Output is correct
61 Correct 399 ms 85804 KB Output is correct
62 Correct 254 ms 84416 KB Output is correct
63 Correct 2 ms 7772 KB Output is correct
64 Correct 2 ms 7772 KB Output is correct
65 Correct 3 ms 8284 KB Output is correct
66 Correct 2 ms 7848 KB Output is correct
67 Correct 2 ms 7772 KB Output is correct
68 Correct 2 ms 7916 KB Output is correct
69 Correct 2 ms 7904 KB Output is correct
70 Correct 2 ms 7772 KB Output is correct
71 Correct 2 ms 7772 KB Output is correct
72 Correct 2 ms 7772 KB Output is correct
73 Correct 2 ms 7772 KB Output is correct
74 Correct 2 ms 8020 KB Output is correct
75 Correct 2 ms 7772 KB Output is correct
76 Correct 2 ms 7772 KB Output is correct
77 Correct 2 ms 7772 KB Output is correct
78 Correct 2 ms 7772 KB Output is correct
79 Correct 546 ms 85256 KB Output is correct
80 Correct 603 ms 86652 KB Output is correct
81 Correct 465 ms 86544 KB Output is correct
82 Correct 365 ms 82880 KB Output is correct
83 Correct 256 ms 83024 KB Output is correct
84 Correct 237 ms 83552 KB Output is correct
85 Correct 188 ms 83652 KB Output is correct
86 Correct 566 ms 86120 KB Output is correct
87 Correct 584 ms 87380 KB Output is correct
88 Correct 411 ms 83028 KB Output is correct
89 Correct 404 ms 82556 KB Output is correct
90 Correct 308 ms 84088 KB Output is correct
91 Correct 317 ms 84592 KB Output is correct
92 Correct 2 ms 7772 KB Output is correct
93 Correct 2 ms 7772 KB Output is correct
94 Correct 2 ms 7772 KB Output is correct
95 Correct 2 ms 7920 KB Output is correct
96 Correct 2 ms 7772 KB Output is correct
97 Correct 2 ms 7772 KB Output is correct
98 Correct 552 ms 92636 KB Output is correct
99 Correct 576 ms 90060 KB Output is correct
100 Correct 466 ms 91132 KB Output is correct
101 Correct 375 ms 88616 KB Output is correct
102 Correct 269 ms 88660 KB Output is correct
103 Correct 261 ms 88580 KB Output is correct
104 Correct 193 ms 88684 KB Output is correct
105 Correct 544 ms 93524 KB Output is correct
106 Correct 587 ms 92544 KB Output is correct
107 Correct 422 ms 89304 KB Output is correct
108 Correct 402 ms 87792 KB Output is correct
109 Correct 312 ms 88656 KB Output is correct
110 Correct 313 ms 88964 KB Output is correct
111 Correct 2 ms 7772 KB Output is correct
112 Correct 2 ms 7772 KB Output is correct
113 Correct 2 ms 7772 KB Output is correct
114 Correct 2 ms 7772 KB Output is correct
115 Correct 2 ms 7816 KB Output is correct
116 Correct 439 ms 88024 KB Output is correct
117 Correct 444 ms 90192 KB Output is correct
118 Correct 489 ms 94432 KB Output is correct
119 Correct 408 ms 90192 KB Output is correct
120 Correct 301 ms 89668 KB Output is correct
121 Correct 289 ms 90452 KB Output is correct
122 Correct 213 ms 90824 KB Output is correct
123 Correct 549 ms 93672 KB Output is correct
124 Correct 647 ms 92868 KB Output is correct
125 Correct 440 ms 88912 KB Output is correct
126 Correct 476 ms 90176 KB Output is correct
127 Correct 503 ms 90704 KB Output is correct
128 Correct 426 ms 91476 KB Output is correct
129 Correct 445 ms 91984 KB Output is correct