# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
547314 | 2022-04-10T10:38:39 Z | ToroTN | Sprinkler (JOI22_sprinkler) | C++14 | 1043 ms | 87360 KB |
#include<bits/stdc++.h> using namespace std; int n,l,u_i,v_i,h[200005],t,op,x,d,w,u,p[200005],arr[45],ed,kk,bruh; int prime[200005],phi; long long power[35],inv,cnt,dp[200005][45]; vector<int> v[200005],g; queue<int> q; int main() { scanf("%d%d",&n,&l); bruh=l; phi=l; for(int i=2;i<=100000;i++) { prime[i]=1; } for(int i=2;i<=100000;i++) { if(prime[i]==1) { for(int j=2;i*j<=100000;j++) { prime[i*j]=0; } } } for(int i=2;i<=100000;i++) { if(prime[i]==1) { if(l%i==0) { phi/=i; phi*=(i-1); while(1) { if(bruh%i==0) { bruh/=i; }else { break; } } } } } if(bruh!=1) { phi/=bruh; phi*=(bruh-1); } u=phi-1; for(int i=0;i<=30;i++) { g.push_back(u%2); u/=2; } for(int i=1;i<n;i++) { scanf("%d%d",&u_i,&v_i); v[u_i].push_back(v_i); v[v_i].push_back(u_i); } memset(p,-1,sizeof p); p[1]=0; q.push(1); while(!q.empty()) { u=q.front(); q.pop(); for(int i=0;i<v[u].size();i++) { if(p[v[u][i]]==-1) { p[v[u][i]]=u; q.push(v[u][i]); } } } for(int i=1;i<=n;i++) { scanf("%d",&h[i]); } for(int i=1;i<=n;i++) { for(int j=0;j<=40;j++) { dp[i][j]=1; } } scanf("%d",&t); while(t--) { scanf("%d",&op); if(op==1) { scanf("%d%d%d",&x,&d,&w); power[0]=w; for(int i=1;i<=30;i++) { power[i]=power[i-1]*power[i-1]; power[i]%=l; } inv=1; for(int i=0;i<=30;i++) { if(g[i]==1) { inv*=power[i]; inv%=l; } } u=x; for(int i=d;i>=0;i--) { arr[i]=u; ed=i; u=p[u]; if(u==0) { break; } } for(int i=d;i>=ed;i--) { /*dp[arr[i]][i]*=w; dp[arr[i]][i]%=l; if(i-1>=0&&i+1<=d) { dp[arr[i+1]][i-1]*=inv; dp[arr[i+1]][i-1]%=l; }*/ if(i!=ed) { dp[arr[i]][i]*=w; dp[arr[i]][i]%=l; dp[arr[i]][i-1]*=w; dp[arr[i]][i-1]%=l; }else { for(int j=0;j<=i;j++) { dp[arr[i]][j]*=w; dp[arr[i]][j]%=l; } } } }else { scanf("%d",&x); u=x; cnt=h[x]; for(int i=0;i<=40;i++) { /*for(int j=i;j<=40;j++) { cnt*=dp[u][j]; cnt%=l; }*/ cnt*=dp[u][i]; cnt%=l; u=p[u]; if(u==0) { break; } } printf("%lld\n",cnt); } } } /* 4 7 1 2 2 3 3 4 1 1 1 1 11 1 2 1 2 1 1 0 2 2 1 2 2 2 3 2 4 1 4 10 2 2 1 2 2 2 3 2 4 */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 6100 KB | Output is correct |
2 | Correct | 4 ms | 6196 KB | Output is correct |
3 | Correct | 3 ms | 6100 KB | Output is correct |
4 | Correct | 5 ms | 6484 KB | Output is correct |
5 | Correct | 6 ms | 6588 KB | Output is correct |
6 | Correct | 5 ms | 6484 KB | Output is correct |
7 | Correct | 5 ms | 6484 KB | Output is correct |
8 | Correct | 5 ms | 6484 KB | Output is correct |
9 | Correct | 4 ms | 6100 KB | Output is correct |
10 | Correct | 4 ms | 6100 KB | Output is correct |
11 | Correct | 4 ms | 6100 KB | Output is correct |
12 | Correct | 4 ms | 6100 KB | Output is correct |
13 | Correct | 5 ms | 6204 KB | Output is correct |
14 | Correct | 4 ms | 6100 KB | Output is correct |
15 | Correct | 5 ms | 6124 KB | Output is correct |
16 | Correct | 4 ms | 6140 KB | Output is correct |
17 | Correct | 4 ms | 6176 KB | Output is correct |
18 | Correct | 4 ms | 6156 KB | Output is correct |
19 | Correct | 4 ms | 6100 KB | Output is correct |
20 | Correct | 4 ms | 6100 KB | Output is correct |
21 | Correct | 4 ms | 6100 KB | Output is correct |
22 | Correct | 4 ms | 6100 KB | Output is correct |
23 | Correct | 4 ms | 6100 KB | Output is correct |
24 | Correct | 4 ms | 6100 KB | Output is correct |
25 | Correct | 4 ms | 6100 KB | Output is correct |
26 | Correct | 4 ms | 6100 KB | Output is correct |
27 | Correct | 4 ms | 6100 KB | Output is correct |
28 | Correct | 4 ms | 6100 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 6100 KB | Output is correct |
2 | Correct | 543 ms | 87360 KB | Output is correct |
3 | Correct | 528 ms | 84096 KB | Output is correct |
4 | Correct | 541 ms | 85552 KB | Output is correct |
5 | Correct | 539 ms | 85612 KB | Output is correct |
6 | Correct | 431 ms | 85748 KB | Output is correct |
7 | Correct | 425 ms | 86072 KB | Output is correct |
8 | Correct | 382 ms | 87228 KB | Output is correct |
9 | Correct | 578 ms | 86980 KB | Output is correct |
10 | Correct | 510 ms | 84040 KB | Output is correct |
11 | Correct | 572 ms | 87228 KB | Output is correct |
12 | Correct | 492 ms | 84092 KB | Output is correct |
13 | Correct | 410 ms | 85392 KB | Output is correct |
14 | Correct | 426 ms | 85224 KB | Output is correct |
15 | Correct | 393 ms | 84972 KB | Output is correct |
16 | Correct | 464 ms | 84832 KB | Output is correct |
17 | Correct | 427 ms | 85196 KB | Output is correct |
18 | Correct | 5 ms | 6100 KB | Output is correct |
19 | Correct | 4 ms | 6100 KB | Output is correct |
20 | Correct | 4 ms | 6100 KB | Output is correct |
21 | Correct | 4 ms | 6100 KB | Output is correct |
22 | Correct | 4 ms | 6100 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 6100 KB | Output is correct |
2 | Correct | 543 ms | 87360 KB | Output is correct |
3 | Correct | 528 ms | 84096 KB | Output is correct |
4 | Correct | 541 ms | 85552 KB | Output is correct |
5 | Correct | 539 ms | 85612 KB | Output is correct |
6 | Correct | 431 ms | 85748 KB | Output is correct |
7 | Correct | 425 ms | 86072 KB | Output is correct |
8 | Correct | 382 ms | 87228 KB | Output is correct |
9 | Correct | 578 ms | 86980 KB | Output is correct |
10 | Correct | 510 ms | 84040 KB | Output is correct |
11 | Correct | 572 ms | 87228 KB | Output is correct |
12 | Correct | 492 ms | 84092 KB | Output is correct |
13 | Correct | 410 ms | 85392 KB | Output is correct |
14 | Correct | 426 ms | 85224 KB | Output is correct |
15 | Correct | 393 ms | 84972 KB | Output is correct |
16 | Correct | 464 ms | 84832 KB | Output is correct |
17 | Correct | 427 ms | 85196 KB | Output is correct |
18 | Correct | 5 ms | 6100 KB | Output is correct |
19 | Correct | 4 ms | 6100 KB | Output is correct |
20 | Correct | 4 ms | 6100 KB | Output is correct |
21 | Correct | 4 ms | 6100 KB | Output is correct |
22 | Correct | 4 ms | 6100 KB | Output is correct |
23 | Correct | 3 ms | 6100 KB | Output is correct |
24 | Correct | 543 ms | 87220 KB | Output is correct |
25 | Correct | 538 ms | 84116 KB | Output is correct |
26 | Correct | 553 ms | 85624 KB | Output is correct |
27 | Correct | 511 ms | 85644 KB | Output is correct |
28 | Correct | 438 ms | 85832 KB | Output is correct |
29 | Correct | 420 ms | 85956 KB | Output is correct |
30 | Correct | 375 ms | 87244 KB | Output is correct |
31 | Correct | 621 ms | 87160 KB | Output is correct |
32 | Correct | 506 ms | 84108 KB | Output is correct |
33 | Correct | 545 ms | 87260 KB | Output is correct |
34 | Correct | 490 ms | 84108 KB | Output is correct |
35 | Correct | 4 ms | 6100 KB | Output is correct |
36 | Correct | 4 ms | 6100 KB | Output is correct |
37 | Correct | 4 ms | 6100 KB | Output is correct |
38 | Correct | 4 ms | 6100 KB | Output is correct |
39 | Correct | 4 ms | 6200 KB | Output is correct |
40 | Correct | 4 ms | 6100 KB | Output is correct |
41 | Correct | 4 ms | 6100 KB | Output is correct |
42 | Correct | 4 ms | 6100 KB | Output is correct |
43 | Correct | 4 ms | 6100 KB | Output is correct |
44 | Correct | 4 ms | 6100 KB | Output is correct |
45 | Correct | 5 ms | 6100 KB | Output is correct |
46 | Correct | 4 ms | 6100 KB | Output is correct |
47 | Correct | 4 ms | 6100 KB | Output is correct |
48 | Correct | 4 ms | 6100 KB | Output is correct |
49 | Correct | 4 ms | 6208 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 6100 KB | Output is correct |
2 | Correct | 637 ms | 84616 KB | Output is correct |
3 | Correct | 896 ms | 83840 KB | Output is correct |
4 | Correct | 631 ms | 84124 KB | Output is correct |
5 | Correct | 566 ms | 84168 KB | Output is correct |
6 | Correct | 427 ms | 84276 KB | Output is correct |
7 | Correct | 401 ms | 84476 KB | Output is correct |
8 | Correct | 370 ms | 85696 KB | Output is correct |
9 | Correct | 604 ms | 84684 KB | Output is correct |
10 | Correct | 901 ms | 83800 KB | Output is correct |
11 | Correct | 586 ms | 84368 KB | Output is correct |
12 | Correct | 780 ms | 83836 KB | Output is correct |
13 | Correct | 587 ms | 84732 KB | Output is correct |
14 | Correct | 579 ms | 85068 KB | Output is correct |
15 | Correct | 4 ms | 6100 KB | Output is correct |
16 | Correct | 4 ms | 6100 KB | Output is correct |
17 | Correct | 4 ms | 6100 KB | Output is correct |
18 | Correct | 4 ms | 6100 KB | Output is correct |
19 | Correct | 4 ms | 6100 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 6100 KB | Output is correct |
2 | Correct | 659 ms | 87236 KB | Output is correct |
3 | Correct | 986 ms | 84056 KB | Output is correct |
4 | Correct | 648 ms | 85648 KB | Output is correct |
5 | Correct | 616 ms | 85680 KB | Output is correct |
6 | Correct | 469 ms | 85960 KB | Output is correct |
7 | Correct | 449 ms | 85956 KB | Output is correct |
8 | Correct | 355 ms | 86952 KB | Output is correct |
9 | Correct | 628 ms | 87108 KB | Output is correct |
10 | Correct | 953 ms | 83968 KB | Output is correct |
11 | Correct | 588 ms | 87320 KB | Output is correct |
12 | Correct | 844 ms | 84052 KB | Output is correct |
13 | Correct | 607 ms | 84904 KB | Output is correct |
14 | Correct | 647 ms | 85204 KB | Output is correct |
15 | Correct | 4 ms | 6100 KB | Output is correct |
16 | Correct | 4 ms | 6100 KB | Output is correct |
17 | Correct | 4 ms | 6100 KB | Output is correct |
18 | Correct | 4 ms | 6100 KB | Output is correct |
19 | Correct | 4 ms | 6100 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 6100 KB | Output is correct |
2 | Correct | 4 ms | 6196 KB | Output is correct |
3 | Correct | 3 ms | 6100 KB | Output is correct |
4 | Correct | 5 ms | 6484 KB | Output is correct |
5 | Correct | 6 ms | 6588 KB | Output is correct |
6 | Correct | 5 ms | 6484 KB | Output is correct |
7 | Correct | 5 ms | 6484 KB | Output is correct |
8 | Correct | 5 ms | 6484 KB | Output is correct |
9 | Correct | 4 ms | 6100 KB | Output is correct |
10 | Correct | 4 ms | 6100 KB | Output is correct |
11 | Correct | 4 ms | 6100 KB | Output is correct |
12 | Correct | 4 ms | 6100 KB | Output is correct |
13 | Correct | 5 ms | 6204 KB | Output is correct |
14 | Correct | 4 ms | 6100 KB | Output is correct |
15 | Correct | 5 ms | 6124 KB | Output is correct |
16 | Correct | 4 ms | 6140 KB | Output is correct |
17 | Correct | 4 ms | 6176 KB | Output is correct |
18 | Correct | 4 ms | 6156 KB | Output is correct |
19 | Correct | 4 ms | 6100 KB | Output is correct |
20 | Correct | 4 ms | 6100 KB | Output is correct |
21 | Correct | 4 ms | 6100 KB | Output is correct |
22 | Correct | 4 ms | 6100 KB | Output is correct |
23 | Correct | 4 ms | 6100 KB | Output is correct |
24 | Correct | 4 ms | 6100 KB | Output is correct |
25 | Correct | 4 ms | 6100 KB | Output is correct |
26 | Correct | 4 ms | 6100 KB | Output is correct |
27 | Correct | 4 ms | 6100 KB | Output is correct |
28 | Correct | 4 ms | 6100 KB | Output is correct |
29 | Correct | 3 ms | 6100 KB | Output is correct |
30 | Correct | 543 ms | 87360 KB | Output is correct |
31 | Correct | 528 ms | 84096 KB | Output is correct |
32 | Correct | 541 ms | 85552 KB | Output is correct |
33 | Correct | 539 ms | 85612 KB | Output is correct |
34 | Correct | 431 ms | 85748 KB | Output is correct |
35 | Correct | 425 ms | 86072 KB | Output is correct |
36 | Correct | 382 ms | 87228 KB | Output is correct |
37 | Correct | 578 ms | 86980 KB | Output is correct |
38 | Correct | 510 ms | 84040 KB | Output is correct |
39 | Correct | 572 ms | 87228 KB | Output is correct |
40 | Correct | 492 ms | 84092 KB | Output is correct |
41 | Correct | 410 ms | 85392 KB | Output is correct |
42 | Correct | 426 ms | 85224 KB | Output is correct |
43 | Correct | 393 ms | 84972 KB | Output is correct |
44 | Correct | 464 ms | 84832 KB | Output is correct |
45 | Correct | 427 ms | 85196 KB | Output is correct |
46 | Correct | 5 ms | 6100 KB | Output is correct |
47 | Correct | 4 ms | 6100 KB | Output is correct |
48 | Correct | 4 ms | 6100 KB | Output is correct |
49 | Correct | 4 ms | 6100 KB | Output is correct |
50 | Correct | 4 ms | 6100 KB | Output is correct |
51 | Correct | 3 ms | 6100 KB | Output is correct |
52 | Correct | 543 ms | 87220 KB | Output is correct |
53 | Correct | 538 ms | 84116 KB | Output is correct |
54 | Correct | 553 ms | 85624 KB | Output is correct |
55 | Correct | 511 ms | 85644 KB | Output is correct |
56 | Correct | 438 ms | 85832 KB | Output is correct |
57 | Correct | 420 ms | 85956 KB | Output is correct |
58 | Correct | 375 ms | 87244 KB | Output is correct |
59 | Correct | 621 ms | 87160 KB | Output is correct |
60 | Correct | 506 ms | 84108 KB | Output is correct |
61 | Correct | 545 ms | 87260 KB | Output is correct |
62 | Correct | 490 ms | 84108 KB | Output is correct |
63 | Correct | 4 ms | 6100 KB | Output is correct |
64 | Correct | 4 ms | 6100 KB | Output is correct |
65 | Correct | 4 ms | 6100 KB | Output is correct |
66 | Correct | 4 ms | 6100 KB | Output is correct |
67 | Correct | 4 ms | 6200 KB | Output is correct |
68 | Correct | 4 ms | 6100 KB | Output is correct |
69 | Correct | 4 ms | 6100 KB | Output is correct |
70 | Correct | 4 ms | 6100 KB | Output is correct |
71 | Correct | 4 ms | 6100 KB | Output is correct |
72 | Correct | 4 ms | 6100 KB | Output is correct |
73 | Correct | 5 ms | 6100 KB | Output is correct |
74 | Correct | 4 ms | 6100 KB | Output is correct |
75 | Correct | 4 ms | 6100 KB | Output is correct |
76 | Correct | 4 ms | 6100 KB | Output is correct |
77 | Correct | 4 ms | 6208 KB | Output is correct |
78 | Correct | 4 ms | 6100 KB | Output is correct |
79 | Correct | 637 ms | 84616 KB | Output is correct |
80 | Correct | 896 ms | 83840 KB | Output is correct |
81 | Correct | 631 ms | 84124 KB | Output is correct |
82 | Correct | 566 ms | 84168 KB | Output is correct |
83 | Correct | 427 ms | 84276 KB | Output is correct |
84 | Correct | 401 ms | 84476 KB | Output is correct |
85 | Correct | 370 ms | 85696 KB | Output is correct |
86 | Correct | 604 ms | 84684 KB | Output is correct |
87 | Correct | 901 ms | 83800 KB | Output is correct |
88 | Correct | 586 ms | 84368 KB | Output is correct |
89 | Correct | 780 ms | 83836 KB | Output is correct |
90 | Correct | 587 ms | 84732 KB | Output is correct |
91 | Correct | 579 ms | 85068 KB | Output is correct |
92 | Correct | 4 ms | 6100 KB | Output is correct |
93 | Correct | 4 ms | 6100 KB | Output is correct |
94 | Correct | 4 ms | 6100 KB | Output is correct |
95 | Correct | 4 ms | 6100 KB | Output is correct |
96 | Correct | 4 ms | 6100 KB | Output is correct |
97 | Correct | 3 ms | 6100 KB | Output is correct |
98 | Correct | 659 ms | 87236 KB | Output is correct |
99 | Correct | 986 ms | 84056 KB | Output is correct |
100 | Correct | 648 ms | 85648 KB | Output is correct |
101 | Correct | 616 ms | 85680 KB | Output is correct |
102 | Correct | 469 ms | 85960 KB | Output is correct |
103 | Correct | 449 ms | 85956 KB | Output is correct |
104 | Correct | 355 ms | 86952 KB | Output is correct |
105 | Correct | 628 ms | 87108 KB | Output is correct |
106 | Correct | 953 ms | 83968 KB | Output is correct |
107 | Correct | 588 ms | 87320 KB | Output is correct |
108 | Correct | 844 ms | 84052 KB | Output is correct |
109 | Correct | 607 ms | 84904 KB | Output is correct |
110 | Correct | 647 ms | 85204 KB | Output is correct |
111 | Correct | 4 ms | 6100 KB | Output is correct |
112 | Correct | 4 ms | 6100 KB | Output is correct |
113 | Correct | 4 ms | 6100 KB | Output is correct |
114 | Correct | 4 ms | 6100 KB | Output is correct |
115 | Correct | 4 ms | 6100 KB | Output is correct |
116 | Correct | 633 ms | 85240 KB | Output is correct |
117 | Correct | 983 ms | 83956 KB | Output is correct |
118 | Correct | 695 ms | 85564 KB | Output is correct |
119 | Correct | 637 ms | 85640 KB | Output is correct |
120 | Correct | 494 ms | 85732 KB | Output is correct |
121 | Correct | 505 ms | 86088 KB | Output is correct |
122 | Correct | 404 ms | 87180 KB | Output is correct |
123 | Correct | 644 ms | 87260 KB | Output is correct |
124 | Correct | 1043 ms | 84132 KB | Output is correct |
125 | Correct | 570 ms | 86552 KB | Output is correct |
126 | Correct | 916 ms | 83996 KB | Output is correct |
127 | Correct | 996 ms | 84260 KB | Output is correct |
128 | Correct | 751 ms | 84864 KB | Output is correct |
129 | Correct | 811 ms | 85264 KB | Output is correct |