#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 || a==-1) return;
//if (s==1 && e==4) printf("add %d %d\n",a,b);
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);
for (int x = 0; x<=b; x++){
//printf("x = %d\n",x);
root->add(minch[a][b-x],maxch[a][b-x],c);
if (b-x!=0) root->add(minch[a][b-x-1],maxch[a][b-x-1],c);
a = p[a];
if (a==0){
a = 1;
b--;
}
}
}
else{
int a;
scanf("%d",&a);
printf("%lld\n",root->qu(ord[a]));
}
}
}
Compilation message
sprinkler.cpp: In function 'int main()':
sprinkler.cpp:82:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | scanf("%d%lld",&n,&L);
| ~~~~~^~~~~~~~~~~~~~~~
sprinkler.cpp:86:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
86 | scanf("%d%d",&a,&b);
| ~~~~~^~~~~~~~~~~~~~
sprinkler.cpp:91:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
91 | scanf("%lld",&arr[x]);
| ~~~~~^~~~~~~~~~~~~~~~
sprinkler.cpp:126:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
126 | scanf("%d",&Q);
| ~~~~~^~~~~~~~~
sprinkler.cpp:129:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
129 | scanf("%d",&type);
| ~~~~~^~~~~~~~~~~~
sprinkler.cpp:133:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
133 | scanf("%d%d%lld",&a,&b,&c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:149:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
149 | scanf("%d",&a);
| ~~~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
40148 KB |
Output is correct |
2 |
Correct |
17 ms |
40172 KB |
Output is correct |
3 |
Correct |
17 ms |
40148 KB |
Output is correct |
4 |
Correct |
20 ms |
40580 KB |
Output is correct |
5 |
Correct |
20 ms |
40540 KB |
Output is correct |
6 |
Correct |
20 ms |
40552 KB |
Output is correct |
7 |
Correct |
20 ms |
40640 KB |
Output is correct |
8 |
Correct |
20 ms |
40532 KB |
Output is correct |
9 |
Correct |
18 ms |
40148 KB |
Output is correct |
10 |
Correct |
18 ms |
40136 KB |
Output is correct |
11 |
Correct |
18 ms |
40164 KB |
Output is correct |
12 |
Correct |
17 ms |
40236 KB |
Output is correct |
13 |
Correct |
17 ms |
40148 KB |
Output is correct |
14 |
Correct |
17 ms |
40248 KB |
Output is correct |
15 |
Correct |
16 ms |
40148 KB |
Output is correct |
16 |
Correct |
17 ms |
40220 KB |
Output is correct |
17 |
Correct |
19 ms |
40148 KB |
Output is correct |
18 |
Correct |
18 ms |
40264 KB |
Output is correct |
19 |
Correct |
17 ms |
40148 KB |
Output is correct |
20 |
Correct |
18 ms |
40252 KB |
Output is correct |
21 |
Correct |
17 ms |
40148 KB |
Output is correct |
22 |
Correct |
20 ms |
40148 KB |
Output is correct |
23 |
Correct |
21 ms |
40220 KB |
Output is correct |
24 |
Correct |
21 ms |
40208 KB |
Output is correct |
25 |
Correct |
19 ms |
40148 KB |
Output is correct |
26 |
Correct |
18 ms |
40204 KB |
Output is correct |
27 |
Correct |
18 ms |
40236 KB |
Output is correct |
28 |
Correct |
17 ms |
40148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
40264 KB |
Output is correct |
2 |
Correct |
815 ms |
108132 KB |
Output is correct |
3 |
Correct |
1327 ms |
105080 KB |
Output is correct |
4 |
Correct |
954 ms |
106600 KB |
Output is correct |
5 |
Correct |
937 ms |
106704 KB |
Output is correct |
6 |
Correct |
817 ms |
106632 KB |
Output is correct |
7 |
Correct |
778 ms |
107008 KB |
Output is correct |
8 |
Correct |
594 ms |
107400 KB |
Output is correct |
9 |
Correct |
828 ms |
108108 KB |
Output is correct |
10 |
Correct |
1224 ms |
104904 KB |
Output is correct |
11 |
Correct |
882 ms |
108156 KB |
Output is correct |
12 |
Correct |
1269 ms |
105080 KB |
Output is correct |
13 |
Correct |
780 ms |
105616 KB |
Output is correct |
14 |
Correct |
787 ms |
105676 KB |
Output is correct |
15 |
Correct |
751 ms |
105632 KB |
Output is correct |
16 |
Correct |
751 ms |
105792 KB |
Output is correct |
17 |
Correct |
954 ms |
106184 KB |
Output is correct |
18 |
Correct |
19 ms |
40156 KB |
Output is correct |
19 |
Correct |
18 ms |
40172 KB |
Output is correct |
20 |
Correct |
18 ms |
40168 KB |
Output is correct |
21 |
Correct |
18 ms |
40148 KB |
Output is correct |
22 |
Correct |
18 ms |
40156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
40264 KB |
Output is correct |
2 |
Correct |
815 ms |
108132 KB |
Output is correct |
3 |
Correct |
1327 ms |
105080 KB |
Output is correct |
4 |
Correct |
954 ms |
106600 KB |
Output is correct |
5 |
Correct |
937 ms |
106704 KB |
Output is correct |
6 |
Correct |
817 ms |
106632 KB |
Output is correct |
7 |
Correct |
778 ms |
107008 KB |
Output is correct |
8 |
Correct |
594 ms |
107400 KB |
Output is correct |
9 |
Correct |
828 ms |
108108 KB |
Output is correct |
10 |
Correct |
1224 ms |
104904 KB |
Output is correct |
11 |
Correct |
882 ms |
108156 KB |
Output is correct |
12 |
Correct |
1269 ms |
105080 KB |
Output is correct |
13 |
Correct |
780 ms |
105616 KB |
Output is correct |
14 |
Correct |
787 ms |
105676 KB |
Output is correct |
15 |
Correct |
751 ms |
105632 KB |
Output is correct |
16 |
Correct |
751 ms |
105792 KB |
Output is correct |
17 |
Correct |
954 ms |
106184 KB |
Output is correct |
18 |
Correct |
19 ms |
40156 KB |
Output is correct |
19 |
Correct |
18 ms |
40172 KB |
Output is correct |
20 |
Correct |
18 ms |
40168 KB |
Output is correct |
21 |
Correct |
18 ms |
40148 KB |
Output is correct |
22 |
Correct |
18 ms |
40156 KB |
Output is correct |
23 |
Correct |
17 ms |
40224 KB |
Output is correct |
24 |
Correct |
849 ms |
108244 KB |
Output is correct |
25 |
Correct |
1615 ms |
105220 KB |
Output is correct |
26 |
Correct |
1085 ms |
106588 KB |
Output is correct |
27 |
Correct |
1022 ms |
106588 KB |
Output is correct |
28 |
Correct |
924 ms |
106768 KB |
Output is correct |
29 |
Correct |
840 ms |
106860 KB |
Output is correct |
30 |
Correct |
638 ms |
107328 KB |
Output is correct |
31 |
Correct |
896 ms |
108136 KB |
Output is correct |
32 |
Correct |
1407 ms |
104992 KB |
Output is correct |
33 |
Correct |
861 ms |
108108 KB |
Output is correct |
34 |
Correct |
1652 ms |
105156 KB |
Output is correct |
35 |
Correct |
17 ms |
40188 KB |
Output is correct |
36 |
Correct |
20 ms |
40264 KB |
Output is correct |
37 |
Correct |
18 ms |
40176 KB |
Output is correct |
38 |
Correct |
21 ms |
40260 KB |
Output is correct |
39 |
Correct |
18 ms |
40144 KB |
Output is correct |
40 |
Correct |
18 ms |
40148 KB |
Output is correct |
41 |
Correct |
23 ms |
40260 KB |
Output is correct |
42 |
Correct |
21 ms |
40124 KB |
Output is correct |
43 |
Correct |
21 ms |
40236 KB |
Output is correct |
44 |
Correct |
17 ms |
40252 KB |
Output is correct |
45 |
Correct |
17 ms |
40176 KB |
Output is correct |
46 |
Correct |
17 ms |
40148 KB |
Output is correct |
47 |
Correct |
17 ms |
40232 KB |
Output is correct |
48 |
Correct |
17 ms |
40268 KB |
Output is correct |
49 |
Correct |
17 ms |
40148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
40148 KB |
Output is correct |
2 |
Correct |
1705 ms |
105692 KB |
Output is correct |
3 |
Execution timed out |
4070 ms |
104720 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
40148 KB |
Output is correct |
2 |
Correct |
1712 ms |
108084 KB |
Output is correct |
3 |
Execution timed out |
4077 ms |
104816 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
40148 KB |
Output is correct |
2 |
Correct |
17 ms |
40172 KB |
Output is correct |
3 |
Correct |
17 ms |
40148 KB |
Output is correct |
4 |
Correct |
20 ms |
40580 KB |
Output is correct |
5 |
Correct |
20 ms |
40540 KB |
Output is correct |
6 |
Correct |
20 ms |
40552 KB |
Output is correct |
7 |
Correct |
20 ms |
40640 KB |
Output is correct |
8 |
Correct |
20 ms |
40532 KB |
Output is correct |
9 |
Correct |
18 ms |
40148 KB |
Output is correct |
10 |
Correct |
18 ms |
40136 KB |
Output is correct |
11 |
Correct |
18 ms |
40164 KB |
Output is correct |
12 |
Correct |
17 ms |
40236 KB |
Output is correct |
13 |
Correct |
17 ms |
40148 KB |
Output is correct |
14 |
Correct |
17 ms |
40248 KB |
Output is correct |
15 |
Correct |
16 ms |
40148 KB |
Output is correct |
16 |
Correct |
17 ms |
40220 KB |
Output is correct |
17 |
Correct |
19 ms |
40148 KB |
Output is correct |
18 |
Correct |
18 ms |
40264 KB |
Output is correct |
19 |
Correct |
17 ms |
40148 KB |
Output is correct |
20 |
Correct |
18 ms |
40252 KB |
Output is correct |
21 |
Correct |
17 ms |
40148 KB |
Output is correct |
22 |
Correct |
20 ms |
40148 KB |
Output is correct |
23 |
Correct |
21 ms |
40220 KB |
Output is correct |
24 |
Correct |
21 ms |
40208 KB |
Output is correct |
25 |
Correct |
19 ms |
40148 KB |
Output is correct |
26 |
Correct |
18 ms |
40204 KB |
Output is correct |
27 |
Correct |
18 ms |
40236 KB |
Output is correct |
28 |
Correct |
17 ms |
40148 KB |
Output is correct |
29 |
Correct |
17 ms |
40264 KB |
Output is correct |
30 |
Correct |
815 ms |
108132 KB |
Output is correct |
31 |
Correct |
1327 ms |
105080 KB |
Output is correct |
32 |
Correct |
954 ms |
106600 KB |
Output is correct |
33 |
Correct |
937 ms |
106704 KB |
Output is correct |
34 |
Correct |
817 ms |
106632 KB |
Output is correct |
35 |
Correct |
778 ms |
107008 KB |
Output is correct |
36 |
Correct |
594 ms |
107400 KB |
Output is correct |
37 |
Correct |
828 ms |
108108 KB |
Output is correct |
38 |
Correct |
1224 ms |
104904 KB |
Output is correct |
39 |
Correct |
882 ms |
108156 KB |
Output is correct |
40 |
Correct |
1269 ms |
105080 KB |
Output is correct |
41 |
Correct |
780 ms |
105616 KB |
Output is correct |
42 |
Correct |
787 ms |
105676 KB |
Output is correct |
43 |
Correct |
751 ms |
105632 KB |
Output is correct |
44 |
Correct |
751 ms |
105792 KB |
Output is correct |
45 |
Correct |
954 ms |
106184 KB |
Output is correct |
46 |
Correct |
19 ms |
40156 KB |
Output is correct |
47 |
Correct |
18 ms |
40172 KB |
Output is correct |
48 |
Correct |
18 ms |
40168 KB |
Output is correct |
49 |
Correct |
18 ms |
40148 KB |
Output is correct |
50 |
Correct |
18 ms |
40156 KB |
Output is correct |
51 |
Correct |
17 ms |
40224 KB |
Output is correct |
52 |
Correct |
849 ms |
108244 KB |
Output is correct |
53 |
Correct |
1615 ms |
105220 KB |
Output is correct |
54 |
Correct |
1085 ms |
106588 KB |
Output is correct |
55 |
Correct |
1022 ms |
106588 KB |
Output is correct |
56 |
Correct |
924 ms |
106768 KB |
Output is correct |
57 |
Correct |
840 ms |
106860 KB |
Output is correct |
58 |
Correct |
638 ms |
107328 KB |
Output is correct |
59 |
Correct |
896 ms |
108136 KB |
Output is correct |
60 |
Correct |
1407 ms |
104992 KB |
Output is correct |
61 |
Correct |
861 ms |
108108 KB |
Output is correct |
62 |
Correct |
1652 ms |
105156 KB |
Output is correct |
63 |
Correct |
17 ms |
40188 KB |
Output is correct |
64 |
Correct |
20 ms |
40264 KB |
Output is correct |
65 |
Correct |
18 ms |
40176 KB |
Output is correct |
66 |
Correct |
21 ms |
40260 KB |
Output is correct |
67 |
Correct |
18 ms |
40144 KB |
Output is correct |
68 |
Correct |
18 ms |
40148 KB |
Output is correct |
69 |
Correct |
23 ms |
40260 KB |
Output is correct |
70 |
Correct |
21 ms |
40124 KB |
Output is correct |
71 |
Correct |
21 ms |
40236 KB |
Output is correct |
72 |
Correct |
17 ms |
40252 KB |
Output is correct |
73 |
Correct |
17 ms |
40176 KB |
Output is correct |
74 |
Correct |
17 ms |
40148 KB |
Output is correct |
75 |
Correct |
17 ms |
40232 KB |
Output is correct |
76 |
Correct |
17 ms |
40268 KB |
Output is correct |
77 |
Correct |
17 ms |
40148 KB |
Output is correct |
78 |
Correct |
17 ms |
40148 KB |
Output is correct |
79 |
Correct |
1705 ms |
105692 KB |
Output is correct |
80 |
Execution timed out |
4070 ms |
104720 KB |
Time limit exceeded |
81 |
Halted |
0 ms |
0 KB |
- |