답안 #568468

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
568468 2022-05-25T14:04:39 Z dantoh000 Sprinkler (JOI22_sprinkler) C++14
100 / 100
1255 ms 102600 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,l,q;
vector<int> G[200005];
int p[200005];
int h[200005][50];
void dfs(int u){
    for (auto v : G[u]){
        if (v == p[u]) continue;
        p[v] = u;
        dfs(v);
    }
}
void up(int x, int d, int w){
    ///printf("update %lld of %lld\n",d,x);
    int cur = x;
    while (cur != 1 && d >= 0){
        ///printf("%lld child of %lld\n",d,cur);
        ///printf("%lld child of %lld\n",d-1,cur);
        h[cur][d] = (h[cur][d]*w)%l;
        if (d) h[cur][d-1] = (h[cur][d-1]*w)%l;
        cur = p[cur];
        d--;
    }
    if (cur == 1){
        while (d >= 0){
            ///printf("%lld child of %lld\n",d,1);
            h[1][d] = (h[1][d]*w)%l;
            d--;
        }
    }
}
int qu(int x){
    ///printf("query %lld\n",x);
    int cur = x;
    int d = 0;
    int ret = 1;
    for (d = 0; d <= 40 && cur != 1; d++){
        ///printf("adding %lld child of %lld\n",d,cur);
        ret = (ret*h[cur][d])%l;
        cur = p[cur];
    }
    ///printf("adding %lld child of %lld\n",d,1);
    if (cur == 1 && d <= 40) ret = (ret*h[1][d])%l;
    return ret;
}
main(){
    scanf("%lld%lld",&n,&l);
    for (int i = 0,a,b; i < n-1; i++){
        scanf("%lld%lld",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    p[1] = -1;
    dfs(1);
    for (int i = 1; i <= n; i++) for (int j = 1; j <= 40; j++) h[i][j] = 1;
    for (int i = 1; i <= n; i++){
        scanf("%lld",&h[i][0]);
    }
    scanf("%lld",&q);
    for (int i = 0,t; i < q; i++){
        scanf("%lld",&t);
        if (t == 1){
            int x,d,w;
            scanf("%lld%lld%lld",&x,&d,&w);
            up(x,d,w);
        }
        else {
            int x;
            scanf("%lld",&x);
            printf("%lld\n",qu(x));
        }
    }

}

Compilation message

sprinkler.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   48 | main(){
      | ^~~~
sprinkler.cpp: In function 'int main()':
sprinkler.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf("%lld%lld",&n,&l);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
sprinkler.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         scanf("%lld%lld",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
sprinkler.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         scanf("%lld",&h[i][0]);
      |         ~~~~~^~~~~~~~~~~~~~~~~
sprinkler.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |     scanf("%lld",&q);
      |     ~~~~~^~~~~~~~~~~
sprinkler.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         scanf("%lld",&t);
      |         ~~~~~^~~~~~~~~~~
sprinkler.cpp:66:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |             scanf("%lld%lld%lld",&x,&d,&w);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:71:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |             scanf("%lld",&x);
      |             ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 5 ms 5464 KB Output is correct
5 Correct 4 ms 5424 KB Output is correct
6 Correct 4 ms 5480 KB Output is correct
7 Correct 4 ms 5460 KB Output is correct
8 Correct 6 ms 5396 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5016 KB Output is correct
17 Correct 3 ms 5016 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5016 KB Output is correct
20 Correct 4 ms 5012 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 4 ms 5008 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 5008 KB Output is correct
26 Correct 4 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 4 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 671 ms 95944 KB Output is correct
3 Correct 474 ms 95540 KB Output is correct
4 Correct 701 ms 99276 KB Output is correct
5 Correct 534 ms 96744 KB Output is correct
6 Correct 408 ms 96848 KB Output is correct
7 Correct 456 ms 97316 KB Output is correct
8 Correct 336 ms 97288 KB Output is correct
9 Correct 731 ms 102600 KB Output is correct
10 Correct 484 ms 99376 KB Output is correct
11 Correct 677 ms 98428 KB Output is correct
12 Correct 404 ms 95200 KB Output is correct
13 Correct 311 ms 95808 KB Output is correct
14 Correct 307 ms 95864 KB Output is correct
15 Correct 296 ms 93752 KB Output is correct
16 Correct 297 ms 95488 KB Output is correct
17 Correct 341 ms 96124 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5008 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 671 ms 95944 KB Output is correct
3 Correct 474 ms 95540 KB Output is correct
4 Correct 701 ms 99276 KB Output is correct
5 Correct 534 ms 96744 KB Output is correct
6 Correct 408 ms 96848 KB Output is correct
7 Correct 456 ms 97316 KB Output is correct
8 Correct 336 ms 97288 KB Output is correct
9 Correct 731 ms 102600 KB Output is correct
10 Correct 484 ms 99376 KB Output is correct
11 Correct 677 ms 98428 KB Output is correct
12 Correct 404 ms 95200 KB Output is correct
13 Correct 311 ms 95808 KB Output is correct
14 Correct 307 ms 95864 KB Output is correct
15 Correct 296 ms 93752 KB Output is correct
16 Correct 297 ms 95488 KB Output is correct
17 Correct 341 ms 96124 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5008 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 708 ms 98504 KB Output is correct
25 Correct 488 ms 95476 KB Output is correct
26 Correct 643 ms 100868 KB Output is correct
27 Correct 619 ms 96820 KB Output is correct
28 Correct 458 ms 96740 KB Output is correct
29 Correct 458 ms 96852 KB Output is correct
30 Correct 365 ms 97204 KB Output is correct
31 Correct 771 ms 101032 KB Output is correct
32 Correct 513 ms 99284 KB Output is correct
33 Correct 677 ms 98196 KB Output is correct
34 Correct 423 ms 95440 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 4 ms 5036 KB Output is correct
37 Correct 3 ms 5016 KB Output is correct
38 Correct 5 ms 4948 KB Output is correct
39 Correct 5 ms 5076 KB Output is correct
40 Correct 3 ms 5008 KB Output is correct
41 Correct 5 ms 4948 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 3 ms 5016 KB Output is correct
44 Correct 3 ms 4948 KB Output is correct
45 Correct 3 ms 5012 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 5 ms 4948 KB Output is correct
49 Correct 4 ms 5008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 742 ms 97524 KB Output is correct
3 Correct 1030 ms 95468 KB Output is correct
4 Correct 780 ms 95980 KB Output is correct
5 Correct 716 ms 94300 KB Output is correct
6 Correct 516 ms 94480 KB Output is correct
7 Correct 414 ms 94700 KB Output is correct
8 Correct 358 ms 94840 KB Output is correct
9 Correct 827 ms 97500 KB Output is correct
10 Correct 890 ms 97880 KB Output is correct
11 Correct 702 ms 94672 KB Output is correct
12 Correct 742 ms 94068 KB Output is correct
13 Correct 514 ms 94904 KB Output is correct
14 Correct 487 ms 95820 KB Output is correct
15 Correct 3 ms 5008 KB Output is correct
16 Correct 4 ms 5004 KB Output is correct
17 Correct 4 ms 4948 KB Output is correct
18 Correct 4 ms 5012 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 872 ms 98564 KB Output is correct
3 Correct 942 ms 96460 KB Output is correct
4 Correct 743 ms 98000 KB Output is correct
5 Correct 634 ms 95908 KB Output is correct
6 Correct 530 ms 96144 KB Output is correct
7 Correct 439 ms 96036 KB Output is correct
8 Correct 329 ms 96220 KB Output is correct
9 Correct 820 ms 101328 KB Output is correct
10 Correct 906 ms 98268 KB Output is correct
11 Correct 764 ms 97280 KB Output is correct
12 Correct 760 ms 94156 KB Output is correct
13 Correct 532 ms 94920 KB Output is correct
14 Correct 521 ms 95584 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 4 ms 5016 KB Output is correct
17 Correct 4 ms 4948 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 5 ms 5464 KB Output is correct
5 Correct 4 ms 5424 KB Output is correct
6 Correct 4 ms 5480 KB Output is correct
7 Correct 4 ms 5460 KB Output is correct
8 Correct 6 ms 5396 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5016 KB Output is correct
17 Correct 3 ms 5016 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5016 KB Output is correct
20 Correct 4 ms 5012 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 4 ms 5008 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 5008 KB Output is correct
26 Correct 4 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 4 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 671 ms 95944 KB Output is correct
31 Correct 474 ms 95540 KB Output is correct
32 Correct 701 ms 99276 KB Output is correct
33 Correct 534 ms 96744 KB Output is correct
34 Correct 408 ms 96848 KB Output is correct
35 Correct 456 ms 97316 KB Output is correct
36 Correct 336 ms 97288 KB Output is correct
37 Correct 731 ms 102600 KB Output is correct
38 Correct 484 ms 99376 KB Output is correct
39 Correct 677 ms 98428 KB Output is correct
40 Correct 404 ms 95200 KB Output is correct
41 Correct 311 ms 95808 KB Output is correct
42 Correct 307 ms 95864 KB Output is correct
43 Correct 296 ms 93752 KB Output is correct
44 Correct 297 ms 95488 KB Output is correct
45 Correct 341 ms 96124 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 5008 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 708 ms 98504 KB Output is correct
53 Correct 488 ms 95476 KB Output is correct
54 Correct 643 ms 100868 KB Output is correct
55 Correct 619 ms 96820 KB Output is correct
56 Correct 458 ms 96740 KB Output is correct
57 Correct 458 ms 96852 KB Output is correct
58 Correct 365 ms 97204 KB Output is correct
59 Correct 771 ms 101032 KB Output is correct
60 Correct 513 ms 99284 KB Output is correct
61 Correct 677 ms 98196 KB Output is correct
62 Correct 423 ms 95440 KB Output is correct
63 Correct 3 ms 4948 KB Output is correct
64 Correct 4 ms 5036 KB Output is correct
65 Correct 3 ms 5016 KB Output is correct
66 Correct 5 ms 4948 KB Output is correct
67 Correct 5 ms 5076 KB Output is correct
68 Correct 3 ms 5008 KB Output is correct
69 Correct 5 ms 4948 KB Output is correct
70 Correct 3 ms 4948 KB Output is correct
71 Correct 3 ms 5016 KB Output is correct
72 Correct 3 ms 4948 KB Output is correct
73 Correct 3 ms 5012 KB Output is correct
74 Correct 3 ms 4948 KB Output is correct
75 Correct 3 ms 4948 KB Output is correct
76 Correct 5 ms 4948 KB Output is correct
77 Correct 4 ms 5008 KB Output is correct
78 Correct 4 ms 4948 KB Output is correct
79 Correct 742 ms 97524 KB Output is correct
80 Correct 1030 ms 95468 KB Output is correct
81 Correct 780 ms 95980 KB Output is correct
82 Correct 716 ms 94300 KB Output is correct
83 Correct 516 ms 94480 KB Output is correct
84 Correct 414 ms 94700 KB Output is correct
85 Correct 358 ms 94840 KB Output is correct
86 Correct 827 ms 97500 KB Output is correct
87 Correct 890 ms 97880 KB Output is correct
88 Correct 702 ms 94672 KB Output is correct
89 Correct 742 ms 94068 KB Output is correct
90 Correct 514 ms 94904 KB Output is correct
91 Correct 487 ms 95820 KB Output is correct
92 Correct 3 ms 5008 KB Output is correct
93 Correct 4 ms 5004 KB Output is correct
94 Correct 4 ms 4948 KB Output is correct
95 Correct 4 ms 5012 KB Output is correct
96 Correct 4 ms 4948 KB Output is correct
97 Correct 4 ms 4948 KB Output is correct
98 Correct 872 ms 98564 KB Output is correct
99 Correct 942 ms 96460 KB Output is correct
100 Correct 743 ms 98000 KB Output is correct
101 Correct 634 ms 95908 KB Output is correct
102 Correct 530 ms 96144 KB Output is correct
103 Correct 439 ms 96036 KB Output is correct
104 Correct 329 ms 96220 KB Output is correct
105 Correct 820 ms 101328 KB Output is correct
106 Correct 906 ms 98268 KB Output is correct
107 Correct 764 ms 97280 KB Output is correct
108 Correct 760 ms 94156 KB Output is correct
109 Correct 532 ms 94920 KB Output is correct
110 Correct 521 ms 95584 KB Output is correct
111 Correct 4 ms 4948 KB Output is correct
112 Correct 4 ms 5016 KB Output is correct
113 Correct 4 ms 4948 KB Output is correct
114 Correct 4 ms 4948 KB Output is correct
115 Correct 4 ms 4948 KB Output is correct
116 Correct 886 ms 95188 KB Output is correct
117 Correct 1075 ms 94388 KB Output is correct
118 Correct 903 ms 99872 KB Output is correct
119 Correct 827 ms 95920 KB Output is correct
120 Correct 574 ms 95840 KB Output is correct
121 Correct 584 ms 96448 KB Output is correct
122 Correct 423 ms 96312 KB Output is correct
123 Correct 1094 ms 100400 KB Output is correct
124 Correct 1255 ms 96812 KB Output is correct
125 Correct 858 ms 96624 KB Output is correct
126 Correct 1165 ms 94356 KB Output is correct
127 Correct 1139 ms 94268 KB Output is correct
128 Correct 725 ms 94932 KB Output is correct
129 Correct 778 ms 95692 KB Output is correct