답안 #637751

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637751 2022-09-03T06:38:36 Z victor_gao Sprinkler (JOI22_sprinkler) C++17
100 / 100
741 ms 117396 KB
//#pragma GCC optimize("Ofast,unroll-loops,O3")
//#pragma GCC optimize("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native")
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//#pragma pack(1)
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define int long long
#define pii pair<int,int>
#define x first
#define y second
#define N 200015
using namespace std;
//using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> order_multiset;
//typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> order_set;
int cnt[N][55],n,L,fa[N],h[N];
vector<int>g[N];
void dfs(int p,int lp){
    fa[p]=lp;
    for (auto i:g[p]){
        if (i!=lp){
            dfs(i,p);
        }
    }
}
signed main(){
    fast
    cin>>n>>L;
    for (int i=1;i<n;i++){
        int a,b; cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for (int i=1;i<=n;i++){
        cin>>h[i];
    }
    for (int i=0;i<=n;i++){
        for (int j=0;j<=50;j++)
            cnt[i][j]=1;
    }
    dfs(1,0);
    int q; cin>>q;
    while (q--){
        int type,x,d,w; cin>>type;
        if (type==1){
            cin>>x>>d>>w;
            for (int i=0;i<=d;i++){
                cnt[x][d-i]=cnt[x][d-i]*w%L;
                if (x==0) break;
                x=fa[x];
            }
        }
        else {
            cin>>x;
            int ans=h[x];
            for (int i=0;i<=40;i++){
                ans=(ans*cnt[x][i])%L;
                ans=(ans*cnt[x][i+1])%L;
                x=fa[x];
                if (x==0){
                    for (int j=i+1;j<=41;j++)
                        ans=(ans*cnt[x][j])%L;
                    break;
                }
            }
            cout<<ans<<'\n';
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5460 KB Output is correct
5 Correct 4 ms 5452 KB Output is correct
6 Correct 4 ms 5460 KB Output is correct
7 Correct 4 ms 5500 KB Output is correct
8 Correct 4 ms 5560 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 5024 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5076 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 5048 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 3 ms 4948 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 5040 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 5044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 580 ms 105184 KB Output is correct
3 Correct 353 ms 101968 KB Output is correct
4 Correct 495 ms 105808 KB Output is correct
5 Correct 466 ms 103608 KB Output is correct
6 Correct 360 ms 103496 KB Output is correct
7 Correct 355 ms 103868 KB Output is correct
8 Correct 287 ms 104008 KB Output is correct
9 Correct 627 ms 109124 KB Output is correct
10 Correct 365 ms 105752 KB Output is correct
11 Correct 577 ms 105012 KB Output is correct
12 Correct 367 ms 113892 KB Output is correct
13 Correct 254 ms 113840 KB Output is correct
14 Correct 250 ms 114316 KB Output is correct
15 Correct 249 ms 113588 KB Output is correct
16 Correct 248 ms 114212 KB Output is correct
17 Correct 257 ms 114708 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 3 ms 5040 KB Output is correct
21 Correct 3 ms 5048 KB Output is correct
22 Correct 3 ms 5024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 580 ms 105184 KB Output is correct
3 Correct 353 ms 101968 KB Output is correct
4 Correct 495 ms 105808 KB Output is correct
5 Correct 466 ms 103608 KB Output is correct
6 Correct 360 ms 103496 KB Output is correct
7 Correct 355 ms 103868 KB Output is correct
8 Correct 287 ms 104008 KB Output is correct
9 Correct 627 ms 109124 KB Output is correct
10 Correct 365 ms 105752 KB Output is correct
11 Correct 577 ms 105012 KB Output is correct
12 Correct 367 ms 113892 KB Output is correct
13 Correct 254 ms 113840 KB Output is correct
14 Correct 250 ms 114316 KB Output is correct
15 Correct 249 ms 113588 KB Output is correct
16 Correct 248 ms 114212 KB Output is correct
17 Correct 257 ms 114708 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 3 ms 5040 KB Output is correct
21 Correct 3 ms 5048 KB Output is correct
22 Correct 3 ms 5024 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 578 ms 113252 KB Output is correct
25 Correct 369 ms 113824 KB Output is correct
26 Correct 501 ms 117396 KB Output is correct
27 Correct 477 ms 113712 KB Output is correct
28 Correct 368 ms 113884 KB Output is correct
29 Correct 362 ms 113484 KB Output is correct
30 Correct 308 ms 114160 KB Output is correct
31 Correct 664 ms 115744 KB Output is correct
32 Correct 394 ms 117296 KB Output is correct
33 Correct 586 ms 113336 KB Output is correct
34 Correct 372 ms 113832 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 5044 KB Output is correct
37 Correct 4 ms 4984 KB Output is correct
38 Correct 3 ms 5044 KB Output is correct
39 Correct 4 ms 5076 KB Output is correct
40 Correct 3 ms 4948 KB Output is correct
41 Correct 3 ms 4948 KB Output is correct
42 Correct 3 ms 5036 KB Output is correct
43 Correct 3 ms 5036 KB Output is correct
44 Correct 4 ms 5044 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 4 ms 5040 KB Output is correct
49 Correct 3 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 706 ms 106560 KB Output is correct
3 Correct 644 ms 104560 KB Output is correct
4 Correct 580 ms 105180 KB Output is correct
5 Correct 526 ms 102148 KB Output is correct
6 Correct 373 ms 102428 KB Output is correct
7 Correct 356 ms 102596 KB Output is correct
8 Correct 279 ms 102628 KB Output is correct
9 Correct 662 ms 105040 KB Output is correct
10 Correct 638 ms 105400 KB Output is correct
11 Correct 579 ms 102472 KB Output is correct
12 Correct 579 ms 101940 KB Output is correct
13 Correct 384 ms 102748 KB Output is correct
14 Correct 399 ms 103388 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5036 KB Output is correct
2 Correct 661 ms 107656 KB Output is correct
3 Correct 692 ms 113160 KB Output is correct
4 Correct 572 ms 114024 KB Output is correct
5 Correct 561 ms 112324 KB Output is correct
6 Correct 420 ms 112340 KB Output is correct
7 Correct 407 ms 112284 KB Output is correct
8 Correct 327 ms 112308 KB Output is correct
9 Correct 672 ms 116648 KB Output is correct
10 Correct 697 ms 115124 KB Output is correct
11 Correct 638 ms 112888 KB Output is correct
12 Correct 622 ms 111520 KB Output is correct
13 Correct 398 ms 112164 KB Output is correct
14 Correct 424 ms 113040 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5044 KB Output is correct
18 Correct 3 ms 5040 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5460 KB Output is correct
5 Correct 4 ms 5452 KB Output is correct
6 Correct 4 ms 5460 KB Output is correct
7 Correct 4 ms 5500 KB Output is correct
8 Correct 4 ms 5560 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 5024 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5076 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 5048 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 3 ms 4948 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 5040 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 5044 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 580 ms 105184 KB Output is correct
31 Correct 353 ms 101968 KB Output is correct
32 Correct 495 ms 105808 KB Output is correct
33 Correct 466 ms 103608 KB Output is correct
34 Correct 360 ms 103496 KB Output is correct
35 Correct 355 ms 103868 KB Output is correct
36 Correct 287 ms 104008 KB Output is correct
37 Correct 627 ms 109124 KB Output is correct
38 Correct 365 ms 105752 KB Output is correct
39 Correct 577 ms 105012 KB Output is correct
40 Correct 367 ms 113892 KB Output is correct
41 Correct 254 ms 113840 KB Output is correct
42 Correct 250 ms 114316 KB Output is correct
43 Correct 249 ms 113588 KB Output is correct
44 Correct 248 ms 114212 KB Output is correct
45 Correct 257 ms 114708 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 5040 KB Output is correct
49 Correct 3 ms 5048 KB Output is correct
50 Correct 3 ms 5024 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 578 ms 113252 KB Output is correct
53 Correct 369 ms 113824 KB Output is correct
54 Correct 501 ms 117396 KB Output is correct
55 Correct 477 ms 113712 KB Output is correct
56 Correct 368 ms 113884 KB Output is correct
57 Correct 362 ms 113484 KB Output is correct
58 Correct 308 ms 114160 KB Output is correct
59 Correct 664 ms 115744 KB Output is correct
60 Correct 394 ms 117296 KB Output is correct
61 Correct 586 ms 113336 KB Output is correct
62 Correct 372 ms 113832 KB Output is correct
63 Correct 3 ms 4948 KB Output is correct
64 Correct 3 ms 5044 KB Output is correct
65 Correct 4 ms 4984 KB Output is correct
66 Correct 3 ms 5044 KB Output is correct
67 Correct 4 ms 5076 KB Output is correct
68 Correct 3 ms 4948 KB Output is correct
69 Correct 3 ms 4948 KB Output is correct
70 Correct 3 ms 5036 KB Output is correct
71 Correct 3 ms 5036 KB Output is correct
72 Correct 4 ms 5044 KB Output is correct
73 Correct 3 ms 4948 KB Output is correct
74 Correct 3 ms 4948 KB Output is correct
75 Correct 3 ms 5076 KB Output is correct
76 Correct 4 ms 5040 KB Output is correct
77 Correct 3 ms 5076 KB Output is correct
78 Correct 3 ms 4948 KB Output is correct
79 Correct 706 ms 106560 KB Output is correct
80 Correct 644 ms 104560 KB Output is correct
81 Correct 580 ms 105180 KB Output is correct
82 Correct 526 ms 102148 KB Output is correct
83 Correct 373 ms 102428 KB Output is correct
84 Correct 356 ms 102596 KB Output is correct
85 Correct 279 ms 102628 KB Output is correct
86 Correct 662 ms 105040 KB Output is correct
87 Correct 638 ms 105400 KB Output is correct
88 Correct 579 ms 102472 KB Output is correct
89 Correct 579 ms 101940 KB Output is correct
90 Correct 384 ms 102748 KB Output is correct
91 Correct 399 ms 103388 KB Output is correct
92 Correct 3 ms 4948 KB Output is correct
93 Correct 3 ms 4948 KB Output is correct
94 Correct 3 ms 4948 KB Output is correct
95 Correct 3 ms 5076 KB Output is correct
96 Correct 3 ms 4948 KB Output is correct
97 Correct 3 ms 5036 KB Output is correct
98 Correct 661 ms 107656 KB Output is correct
99 Correct 692 ms 113160 KB Output is correct
100 Correct 572 ms 114024 KB Output is correct
101 Correct 561 ms 112324 KB Output is correct
102 Correct 420 ms 112340 KB Output is correct
103 Correct 407 ms 112284 KB Output is correct
104 Correct 327 ms 112308 KB Output is correct
105 Correct 672 ms 116648 KB Output is correct
106 Correct 697 ms 115124 KB Output is correct
107 Correct 638 ms 112888 KB Output is correct
108 Correct 622 ms 111520 KB Output is correct
109 Correct 398 ms 112164 KB Output is correct
110 Correct 424 ms 113040 KB Output is correct
111 Correct 3 ms 4948 KB Output is correct
112 Correct 3 ms 4948 KB Output is correct
113 Correct 3 ms 5044 KB Output is correct
114 Correct 3 ms 5040 KB Output is correct
115 Correct 3 ms 5076 KB Output is correct
116 Correct 661 ms 111544 KB Output is correct
117 Correct 664 ms 113932 KB Output is correct
118 Correct 636 ms 117376 KB Output is correct
119 Correct 602 ms 113716 KB Output is correct
120 Correct 434 ms 113256 KB Output is correct
121 Correct 461 ms 114096 KB Output is correct
122 Correct 338 ms 114180 KB Output is correct
123 Correct 683 ms 116316 KB Output is correct
124 Correct 741 ms 115780 KB Output is correct
125 Correct 730 ms 112568 KB Output is correct
126 Correct 671 ms 113864 KB Output is correct
127 Correct 645 ms 114232 KB Output is correct
128 Correct 425 ms 115056 KB Output is correct
129 Correct 455 ms 115944 KB Output is correct