#include <bits/stdc++.h>
using namespace std;
long long L;
long long arr[200005];
int inv[200005];
int ord[200005];
struct node{
int s,e;
long long v;
long long lazy;
node *l,*r;
node (int _s, int _e){
s = _s; e = _e;
if (s==e){
v = arr[inv[s]];
}
else{
l = new node(s,(s+e)/2);
r = new node((s+e)/2+1,e);
}
lazy = 1;
}
void proc(){
if (lazy==1){
return;
}
v *= lazy;
v %= L;
if (s==e) {
lazy = 1;
return;
}
l->lazy *= lazy;
l->lazy %= L;
r->lazy *= lazy;
r->lazy %= L;
lazy = 1;
}
void add(int a, int b, long long val){
if (b<a) return;
proc();
if (a<=s && e<=b){
lazy *= val;
lazy %= L;
proc();
return;
}
if (b<=(s+e)/2){
l->add(a,b,val);
}
else if (a>(s+e)/2){
r->add(a,b,val);
}
else{
l->add(a,b,val);
r->add(a,b,val);
}
l->proc();
r->proc();
}
long long qu(int pos){
proc();
if (s==e) return v;
if (pos<=(s+e)/2) return l->qu(pos);
else return r->qu(pos);
}
}*root;
int cur = 1;
bool vis[200005];
int p[200005];
vector<int> adjl[200005];
int minch[200005][45];
int maxch[200005][45];
int main(){
int n;
scanf("%d%lld",&n,&L);
memset(minch,-1,sizeof(minch));
for (int x = 0; x<n-1; x++){
int a,b;
scanf("%d%d",&a,&b);
adjl[a].push_back(b);
adjl[b].push_back(a);
}
for (int x = 1; x<=n; x++){
scanf("%lld",&arr[x]);
}
queue<int> q;
p[1] = 0;
q.push(1);
while (!q.empty()){
int nd = q.front();
q.pop();
if (vis[nd]){
continue;
}
vis[nd] = true;
ord[nd] = cur++;
inv[ord[nd]] = nd;
for (auto x : adjl[nd]){
if (!vis[x]){
p[x] = nd;
q.push(x);
}
}
}
for (int x = 1; x<=n; x++){
int c = x;
for (int y = 0; y<=40; y++){
if (c!=0){
//printf("thing %d %d = %d\n",c,y,ord[x]);
if (minch[c][y]==-1) minch[c][y] = ord[x];
minch[c][y] = min(minch[c][y],ord[x]);
maxch[c][y] = max(maxch[c][y],ord[x]);
}
c = p[c];
}
}
root = new node(1,n);
int Q;
scanf("%d",&Q);
while (Q--){
int type;
scanf("%d",&type);
if (type==1){
int a,b;
long long c;
scanf("%d%d%lld",&a,&b,&c);
int ex1,ex2;
for (int x = 0; x<=b; x++){
//printf("a = %d, x = %d\n",a,x);
if (minch[a][x]==-1) break;
//printf("add %d %d\n",minch[a][x],maxch[a][x]);
root->add(minch[a][x],maxch[a][x],c);
}
for (int y = 1; y<=b; y++){
int ch = a;
a = p[a];
if (a==0) break;
for (int x = 0; x<=b-y; x++){
if (minch[a][x]==-1) break;
if (x==0 || minch[ch][x-1]==-1){
//printf("addd %d %d\n",minch[a][x],maxch[a][x]);
root->add(minch[a][x],maxch[a][x],c);
}
else{
//printf("a a = %d, x = %d\n",a,x);
if (minch[a][x]==-1) break;
//printf("add %d %d\n",minch[a][x],minch[ch][x-1]-1);
root->add(minch[a][x],minch[ch][x-1]-1,c);
//printf("add %d %d\n",maxch[ch][x-1]+1,maxch[a][x]);
root->add(maxch[ch][x-1]+1,maxch[a][x],c);
}
}
}
}
else{
int a;
scanf("%d",&a);
printf("%lld\n",root->qu(ord[a]));
}
}
}
Compilation message
sprinkler.cpp: In function 'int main()':
sprinkler.cpp:133:17: warning: unused variable 'ex1' [-Wunused-variable]
133 | int ex1,ex2;
| ^~~
sprinkler.cpp:133:21: warning: unused variable 'ex2' [-Wunused-variable]
133 | int ex1,ex2;
| ^~~
sprinkler.cpp:81:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | scanf("%d%lld",&n,&L);
| ~~~~~^~~~~~~~~~~~~~~~
sprinkler.cpp:85:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | scanf("%d%d",&a,&b);
| ~~~~~^~~~~~~~~~~~~~
sprinkler.cpp:90:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
90 | scanf("%lld",&arr[x]);
| ~~~~~^~~~~~~~~~~~~~~~
sprinkler.cpp:125:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
125 | scanf("%d",&Q);
| ~~~~~^~~~~~~~~
sprinkler.cpp:128:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
128 | scanf("%d",&type);
| ~~~~~^~~~~~~~~~~~
sprinkler.cpp:132:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
132 | scanf("%d%d%lld",&a,&b,&c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:165:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
165 | scanf("%d",&a);
| ~~~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
40212 KB |
Output is correct |
2 |
Correct |
19 ms |
40244 KB |
Output is correct |
3 |
Correct |
18 ms |
40148 KB |
Output is correct |
4 |
Correct |
21 ms |
40536 KB |
Output is correct |
5 |
Correct |
29 ms |
40532 KB |
Output is correct |
6 |
Correct |
24 ms |
40524 KB |
Output is correct |
7 |
Correct |
22 ms |
40520 KB |
Output is correct |
8 |
Correct |
18 ms |
40532 KB |
Output is correct |
9 |
Correct |
23 ms |
40164 KB |
Output is correct |
10 |
Correct |
17 ms |
40232 KB |
Output is correct |
11 |
Correct |
17 ms |
40268 KB |
Output is correct |
12 |
Correct |
17 ms |
40248 KB |
Output is correct |
13 |
Correct |
17 ms |
40160 KB |
Output is correct |
14 |
Correct |
17 ms |
40160 KB |
Output is correct |
15 |
Correct |
16 ms |
40228 KB |
Output is correct |
16 |
Correct |
16 ms |
40208 KB |
Output is correct |
17 |
Correct |
16 ms |
40212 KB |
Output is correct |
18 |
Correct |
16 ms |
40148 KB |
Output is correct |
19 |
Correct |
21 ms |
40244 KB |
Output is correct |
20 |
Correct |
21 ms |
40148 KB |
Output is correct |
21 |
Correct |
17 ms |
40148 KB |
Output is correct |
22 |
Correct |
18 ms |
40196 KB |
Output is correct |
23 |
Correct |
19 ms |
40192 KB |
Output is correct |
24 |
Correct |
21 ms |
40200 KB |
Output is correct |
25 |
Correct |
20 ms |
40220 KB |
Output is correct |
26 |
Correct |
21 ms |
40196 KB |
Output is correct |
27 |
Correct |
19 ms |
40248 KB |
Output is correct |
28 |
Correct |
17 ms |
40188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
40184 KB |
Output is correct |
2 |
Correct |
963 ms |
110596 KB |
Output is correct |
3 |
Correct |
1454 ms |
107448 KB |
Output is correct |
4 |
Correct |
950 ms |
108756 KB |
Output is correct |
5 |
Correct |
967 ms |
108992 KB |
Output is correct |
6 |
Correct |
810 ms |
109104 KB |
Output is correct |
7 |
Correct |
761 ms |
108756 KB |
Output is correct |
8 |
Correct |
627 ms |
109436 KB |
Output is correct |
9 |
Correct |
838 ms |
110272 KB |
Output is correct |
10 |
Correct |
1199 ms |
107256 KB |
Output is correct |
11 |
Correct |
811 ms |
110532 KB |
Output is correct |
12 |
Correct |
1275 ms |
107460 KB |
Output is correct |
13 |
Correct |
753 ms |
108008 KB |
Output is correct |
14 |
Correct |
787 ms |
107772 KB |
Output is correct |
15 |
Correct |
751 ms |
106612 KB |
Output is correct |
16 |
Correct |
793 ms |
108016 KB |
Output is correct |
17 |
Correct |
882 ms |
108668 KB |
Output is correct |
18 |
Correct |
17 ms |
40156 KB |
Output is correct |
19 |
Correct |
18 ms |
40148 KB |
Output is correct |
20 |
Correct |
17 ms |
40216 KB |
Output is correct |
21 |
Correct |
17 ms |
40228 KB |
Output is correct |
22 |
Correct |
20 ms |
40156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
40184 KB |
Output is correct |
2 |
Correct |
963 ms |
110596 KB |
Output is correct |
3 |
Correct |
1454 ms |
107448 KB |
Output is correct |
4 |
Correct |
950 ms |
108756 KB |
Output is correct |
5 |
Correct |
967 ms |
108992 KB |
Output is correct |
6 |
Correct |
810 ms |
109104 KB |
Output is correct |
7 |
Correct |
761 ms |
108756 KB |
Output is correct |
8 |
Correct |
627 ms |
109436 KB |
Output is correct |
9 |
Correct |
838 ms |
110272 KB |
Output is correct |
10 |
Correct |
1199 ms |
107256 KB |
Output is correct |
11 |
Correct |
811 ms |
110532 KB |
Output is correct |
12 |
Correct |
1275 ms |
107460 KB |
Output is correct |
13 |
Correct |
753 ms |
108008 KB |
Output is correct |
14 |
Correct |
787 ms |
107772 KB |
Output is correct |
15 |
Correct |
751 ms |
106612 KB |
Output is correct |
16 |
Correct |
793 ms |
108016 KB |
Output is correct |
17 |
Correct |
882 ms |
108668 KB |
Output is correct |
18 |
Correct |
17 ms |
40156 KB |
Output is correct |
19 |
Correct |
18 ms |
40148 KB |
Output is correct |
20 |
Correct |
17 ms |
40216 KB |
Output is correct |
21 |
Correct |
17 ms |
40228 KB |
Output is correct |
22 |
Correct |
20 ms |
40156 KB |
Output is correct |
23 |
Correct |
21 ms |
40148 KB |
Output is correct |
24 |
Correct |
811 ms |
110520 KB |
Output is correct |
25 |
Correct |
1749 ms |
107308 KB |
Output is correct |
26 |
Correct |
1034 ms |
108344 KB |
Output is correct |
27 |
Correct |
1037 ms |
108780 KB |
Output is correct |
28 |
Correct |
912 ms |
108884 KB |
Output is correct |
29 |
Correct |
878 ms |
108876 KB |
Output is correct |
30 |
Correct |
799 ms |
109632 KB |
Output is correct |
31 |
Correct |
851 ms |
110120 KB |
Output is correct |
32 |
Correct |
1345 ms |
106940 KB |
Output is correct |
33 |
Correct |
866 ms |
110140 KB |
Output is correct |
34 |
Correct |
1710 ms |
107080 KB |
Output is correct |
35 |
Correct |
16 ms |
40216 KB |
Output is correct |
36 |
Correct |
18 ms |
40192 KB |
Output is correct |
37 |
Correct |
17 ms |
40268 KB |
Output is correct |
38 |
Correct |
19 ms |
40220 KB |
Output is correct |
39 |
Correct |
19 ms |
40240 KB |
Output is correct |
40 |
Correct |
21 ms |
40196 KB |
Output is correct |
41 |
Correct |
19 ms |
40264 KB |
Output is correct |
42 |
Correct |
17 ms |
40228 KB |
Output is correct |
43 |
Correct |
17 ms |
40148 KB |
Output is correct |
44 |
Correct |
16 ms |
40220 KB |
Output is correct |
45 |
Correct |
19 ms |
40220 KB |
Output is correct |
46 |
Correct |
17 ms |
40144 KB |
Output is correct |
47 |
Correct |
17 ms |
40148 KB |
Output is correct |
48 |
Correct |
19 ms |
40220 KB |
Output is correct |
49 |
Correct |
17 ms |
40276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
40212 KB |
Output is correct |
2 |
Correct |
1814 ms |
107332 KB |
Output is correct |
3 |
Execution timed out |
4053 ms |
106540 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
40148 KB |
Output is correct |
2 |
Correct |
1875 ms |
110652 KB |
Output is correct |
3 |
Execution timed out |
4017 ms |
106880 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
40212 KB |
Output is correct |
2 |
Correct |
19 ms |
40244 KB |
Output is correct |
3 |
Correct |
18 ms |
40148 KB |
Output is correct |
4 |
Correct |
21 ms |
40536 KB |
Output is correct |
5 |
Correct |
29 ms |
40532 KB |
Output is correct |
6 |
Correct |
24 ms |
40524 KB |
Output is correct |
7 |
Correct |
22 ms |
40520 KB |
Output is correct |
8 |
Correct |
18 ms |
40532 KB |
Output is correct |
9 |
Correct |
23 ms |
40164 KB |
Output is correct |
10 |
Correct |
17 ms |
40232 KB |
Output is correct |
11 |
Correct |
17 ms |
40268 KB |
Output is correct |
12 |
Correct |
17 ms |
40248 KB |
Output is correct |
13 |
Correct |
17 ms |
40160 KB |
Output is correct |
14 |
Correct |
17 ms |
40160 KB |
Output is correct |
15 |
Correct |
16 ms |
40228 KB |
Output is correct |
16 |
Correct |
16 ms |
40208 KB |
Output is correct |
17 |
Correct |
16 ms |
40212 KB |
Output is correct |
18 |
Correct |
16 ms |
40148 KB |
Output is correct |
19 |
Correct |
21 ms |
40244 KB |
Output is correct |
20 |
Correct |
21 ms |
40148 KB |
Output is correct |
21 |
Correct |
17 ms |
40148 KB |
Output is correct |
22 |
Correct |
18 ms |
40196 KB |
Output is correct |
23 |
Correct |
19 ms |
40192 KB |
Output is correct |
24 |
Correct |
21 ms |
40200 KB |
Output is correct |
25 |
Correct |
20 ms |
40220 KB |
Output is correct |
26 |
Correct |
21 ms |
40196 KB |
Output is correct |
27 |
Correct |
19 ms |
40248 KB |
Output is correct |
28 |
Correct |
17 ms |
40188 KB |
Output is correct |
29 |
Correct |
17 ms |
40184 KB |
Output is correct |
30 |
Correct |
963 ms |
110596 KB |
Output is correct |
31 |
Correct |
1454 ms |
107448 KB |
Output is correct |
32 |
Correct |
950 ms |
108756 KB |
Output is correct |
33 |
Correct |
967 ms |
108992 KB |
Output is correct |
34 |
Correct |
810 ms |
109104 KB |
Output is correct |
35 |
Correct |
761 ms |
108756 KB |
Output is correct |
36 |
Correct |
627 ms |
109436 KB |
Output is correct |
37 |
Correct |
838 ms |
110272 KB |
Output is correct |
38 |
Correct |
1199 ms |
107256 KB |
Output is correct |
39 |
Correct |
811 ms |
110532 KB |
Output is correct |
40 |
Correct |
1275 ms |
107460 KB |
Output is correct |
41 |
Correct |
753 ms |
108008 KB |
Output is correct |
42 |
Correct |
787 ms |
107772 KB |
Output is correct |
43 |
Correct |
751 ms |
106612 KB |
Output is correct |
44 |
Correct |
793 ms |
108016 KB |
Output is correct |
45 |
Correct |
882 ms |
108668 KB |
Output is correct |
46 |
Correct |
17 ms |
40156 KB |
Output is correct |
47 |
Correct |
18 ms |
40148 KB |
Output is correct |
48 |
Correct |
17 ms |
40216 KB |
Output is correct |
49 |
Correct |
17 ms |
40228 KB |
Output is correct |
50 |
Correct |
20 ms |
40156 KB |
Output is correct |
51 |
Correct |
21 ms |
40148 KB |
Output is correct |
52 |
Correct |
811 ms |
110520 KB |
Output is correct |
53 |
Correct |
1749 ms |
107308 KB |
Output is correct |
54 |
Correct |
1034 ms |
108344 KB |
Output is correct |
55 |
Correct |
1037 ms |
108780 KB |
Output is correct |
56 |
Correct |
912 ms |
108884 KB |
Output is correct |
57 |
Correct |
878 ms |
108876 KB |
Output is correct |
58 |
Correct |
799 ms |
109632 KB |
Output is correct |
59 |
Correct |
851 ms |
110120 KB |
Output is correct |
60 |
Correct |
1345 ms |
106940 KB |
Output is correct |
61 |
Correct |
866 ms |
110140 KB |
Output is correct |
62 |
Correct |
1710 ms |
107080 KB |
Output is correct |
63 |
Correct |
16 ms |
40216 KB |
Output is correct |
64 |
Correct |
18 ms |
40192 KB |
Output is correct |
65 |
Correct |
17 ms |
40268 KB |
Output is correct |
66 |
Correct |
19 ms |
40220 KB |
Output is correct |
67 |
Correct |
19 ms |
40240 KB |
Output is correct |
68 |
Correct |
21 ms |
40196 KB |
Output is correct |
69 |
Correct |
19 ms |
40264 KB |
Output is correct |
70 |
Correct |
17 ms |
40228 KB |
Output is correct |
71 |
Correct |
17 ms |
40148 KB |
Output is correct |
72 |
Correct |
16 ms |
40220 KB |
Output is correct |
73 |
Correct |
19 ms |
40220 KB |
Output is correct |
74 |
Correct |
17 ms |
40144 KB |
Output is correct |
75 |
Correct |
17 ms |
40148 KB |
Output is correct |
76 |
Correct |
19 ms |
40220 KB |
Output is correct |
77 |
Correct |
17 ms |
40276 KB |
Output is correct |
78 |
Correct |
16 ms |
40212 KB |
Output is correct |
79 |
Correct |
1814 ms |
107332 KB |
Output is correct |
80 |
Execution timed out |
4053 ms |
106540 KB |
Time limit exceeded |
81 |
Halted |
0 ms |
0 KB |
- |