# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
615035 |
2022-07-31T06:18:10 Z |
반딧불(#8492) |
Sprinkler (JOI22_sprinkler) |
C++17 |
|
4000 ms |
113136 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD;
struct segTree{
ll tree[800002], lazy[800002];
void init(int i, int l, int r){
tree[i] = 1, lazy[i] = 1;
if(l==r) return;
int m = (l+r)>>1;
init(i*2, l, m);
init(i*2+1, m+1, r);
}
void propagate(int i, int l, int r){
if(l==r) tree[i] = (tree[i] * lazy[i]) % MOD;
if(l!=r) lazy[i*2] = (lazy[i*2] * lazy[i]) % MOD, lazy[i*2+1] = (lazy[i*2+1] * lazy[i]) % MOD;
lazy[i] = 1;
}
void update(int i, int l, int r, int s, int e, ll v){
propagate(i, l, r);
if(r<s || e<l) return;
if(s<=l && r<=e){
lazy[i] = v;
propagate(i, l, r);
return;
}
int m = (l+r)>>1;
update(i*2, l, m, s, e, v);
update(i*2+1, m+1, r, s, e, v);
}
ll query(int i, int l, int r, int x){
propagate(i, l, r);
if(l==r) return tree[i];
int m = (l+r)>>1;
if(x<=m) return query(i*2, l, m, x);
else return query(i*2+1, m+1, r, x);
}
} tree;
int n, q;
vector<int> link[200002];
ll arr[200002];
int in[200002], idx[200002], par[200002], depth[200002], inCnt;
int childL[200002][42], childR[200002][42];
void bfs(int x){
queue<int> que;
que.push(1);
while(!que.empty()){
int x = que.front(); que.pop();
in[x] = ++inCnt;
idx[inCnt] = x;
for(auto y: link[x]){
if(in[y]) continue;
par[y] = x;
depth[y] = depth[x] + 1;
link[y].erase(find(link[y].begin(), link[y].end(), x));
que.push(y);
}
}
}
void dfs(int x, int p=-1){
childL[x][0] = childR[x][0] = in[x];
for(auto y: link[x]){
dfs(y);
for(int i=1; i<=40; i++){
childL[x][i] = min(childL[x][i], childL[y][i-1]);
childR[x][i] = max(childR[x][i], childR[y][i-1]);
}
}
}
int main(){
scanf("%d %lld", &n, &MOD);
for(int i=1; i<n; i++){
int x, y;
scanf("%d %d", &x, &y);
link[x].push_back(y);
link[y].push_back(x);
}
for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
bfs(1);
tree.init(1, 1, n);
for(int i=1; i<=n; i++) tree.update(1, 1, n, in[i], in[i], arr[i]);
for(int i=1; i<=n; i++){
for(int j=0; j<=40; j++){
childL[i][j] = 1e9;
childR[i][j] = -1;
}
}
dfs(1);
scanf("%d", &q);
while(q--){
int qt;
scanf("%d", &qt);
if(qt==1){
int x, d; ll w;
scanf("%d %d %lld", &x, &d, &w);
vector<int> treeL(d+d+1, 1e9), treeR(d+d+1, -1);
for(int cnt=0; cnt<=d; cnt++){
treeL[d+cnt] = childL[x][cnt], treeR[d+cnt] = childR[x][cnt];
}
int up = 0;
for(up=1; up<=d; up++){
if(!par[x]){
up--;
break;
}
x = par[x];
/// ������ �ִ� ����: d-up-up
treeL[d+d-up-up] = min(treeL[d+d-up-up], childL[x][d-up]);
treeR[d+d-up-up] = max(treeR[d+d-up-up], childR[x][d-up]);
if(up==d) break;
/// ������ �ִ� ����: d-up-up-1
treeL[d+d-up-up-1] = min(treeL[d+d-up-up-1], childL[x][d-up-1]);
treeR[d+d-up-up-1] = max(treeR[d+d-up-up-1], childR[x][d-up-1]);
}
for(int cnt=0; cnt+up<=d; cnt++){
treeL[d-up+cnt] = min(treeL[d-up+cnt], childL[x][cnt]);
treeR[d-up+cnt] = max(treeR[d-up+cnt], childR[x][cnt]);
}
for(int i=0; i<=d+d; i++){
if(treeL[i] == 1e9) continue;
tree.update(1, 1, n, treeL[i], treeR[i], w);
}
}
else{
int x;
scanf("%d", &x);
printf("%lld\n", tree.query(1, 1, n, in[x]));
}
}
}
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, &MOD);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
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", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
sprinkler.cpp:89:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
89 | for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
| ~~~~~^~~~~~~~~~~~~~~~~
sprinkler.cpp:101:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
101 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
sprinkler.cpp:104:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
104 | scanf("%d", &qt);
| ~~~~~^~~~~~~~~~~
sprinkler.cpp:107:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
107 | scanf("%d %d %lld", &x, &d, &w);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:139:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
139 | scanf("%d", &x);
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
13 ms |
5460 KB |
Output is correct |
5 |
Correct |
9 ms |
5404 KB |
Output is correct |
6 |
Correct |
8 ms |
5460 KB |
Output is correct |
7 |
Correct |
9 ms |
5516 KB |
Output is correct |
8 |
Correct |
5 ms |
5472 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
5020 KB |
Output is correct |
11 |
Correct |
4 ms |
4948 KB |
Output is correct |
12 |
Correct |
5 ms |
5016 KB |
Output is correct |
13 |
Correct |
4 ms |
5076 KB |
Output is correct |
14 |
Correct |
4 ms |
5092 KB |
Output is correct |
15 |
Correct |
4 ms |
5076 KB |
Output is correct |
16 |
Correct |
5 ms |
5020 KB |
Output is correct |
17 |
Correct |
6 ms |
5028 KB |
Output is correct |
18 |
Correct |
6 ms |
5020 KB |
Output is correct |
19 |
Correct |
4 ms |
5004 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
5 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
4 ms |
5056 KB |
Output is correct |
24 |
Correct |
5 ms |
4948 KB |
Output is correct |
25 |
Correct |
4 ms |
4948 KB |
Output is correct |
26 |
Correct |
5 ms |
5012 KB |
Output is correct |
27 |
Correct |
4 ms |
5020 KB |
Output is correct |
28 |
Correct |
3 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
674 ms |
96964 KB |
Output is correct |
3 |
Correct |
1276 ms |
93872 KB |
Output is correct |
4 |
Correct |
1049 ms |
105244 KB |
Output is correct |
5 |
Correct |
1090 ms |
95252 KB |
Output is correct |
6 |
Correct |
778 ms |
95336 KB |
Output is correct |
7 |
Correct |
839 ms |
95684 KB |
Output is correct |
8 |
Correct |
698 ms |
96788 KB |
Output is correct |
9 |
Correct |
669 ms |
112004 KB |
Output is correct |
10 |
Correct |
1065 ms |
107504 KB |
Output is correct |
11 |
Correct |
604 ms |
96912 KB |
Output is correct |
12 |
Correct |
998 ms |
93724 KB |
Output is correct |
13 |
Correct |
1086 ms |
94072 KB |
Output is correct |
14 |
Correct |
1081 ms |
93068 KB |
Output is correct |
15 |
Correct |
990 ms |
92916 KB |
Output is correct |
16 |
Correct |
1027 ms |
92788 KB |
Output is correct |
17 |
Correct |
1059 ms |
93320 KB |
Output is correct |
18 |
Correct |
3 ms |
5016 KB |
Output is correct |
19 |
Correct |
3 ms |
5076 KB |
Output is correct |
20 |
Correct |
4 ms |
5016 KB |
Output is correct |
21 |
Correct |
3 ms |
5076 KB |
Output is correct |
22 |
Correct |
4 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
674 ms |
96964 KB |
Output is correct |
3 |
Correct |
1276 ms |
93872 KB |
Output is correct |
4 |
Correct |
1049 ms |
105244 KB |
Output is correct |
5 |
Correct |
1090 ms |
95252 KB |
Output is correct |
6 |
Correct |
778 ms |
95336 KB |
Output is correct |
7 |
Correct |
839 ms |
95684 KB |
Output is correct |
8 |
Correct |
698 ms |
96788 KB |
Output is correct |
9 |
Correct |
669 ms |
112004 KB |
Output is correct |
10 |
Correct |
1065 ms |
107504 KB |
Output is correct |
11 |
Correct |
604 ms |
96912 KB |
Output is correct |
12 |
Correct |
998 ms |
93724 KB |
Output is correct |
13 |
Correct |
1086 ms |
94072 KB |
Output is correct |
14 |
Correct |
1081 ms |
93068 KB |
Output is correct |
15 |
Correct |
990 ms |
92916 KB |
Output is correct |
16 |
Correct |
1027 ms |
92788 KB |
Output is correct |
17 |
Correct |
1059 ms |
93320 KB |
Output is correct |
18 |
Correct |
3 ms |
5016 KB |
Output is correct |
19 |
Correct |
3 ms |
5076 KB |
Output is correct |
20 |
Correct |
4 ms |
5016 KB |
Output is correct |
21 |
Correct |
3 ms |
5076 KB |
Output is correct |
22 |
Correct |
4 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
4948 KB |
Output is correct |
24 |
Correct |
635 ms |
95368 KB |
Output is correct |
25 |
Correct |
1268 ms |
97240 KB |
Output is correct |
26 |
Correct |
900 ms |
113136 KB |
Output is correct |
27 |
Correct |
832 ms |
98776 KB |
Output is correct |
28 |
Correct |
805 ms |
98976 KB |
Output is correct |
29 |
Correct |
827 ms |
99012 KB |
Output is correct |
30 |
Correct |
725 ms |
100284 KB |
Output is correct |
31 |
Correct |
683 ms |
110928 KB |
Output is correct |
32 |
Correct |
1373 ms |
111104 KB |
Output is correct |
33 |
Correct |
674 ms |
100436 KB |
Output is correct |
34 |
Correct |
1330 ms |
97404 KB |
Output is correct |
35 |
Correct |
3 ms |
5076 KB |
Output is correct |
36 |
Correct |
4 ms |
5020 KB |
Output is correct |
37 |
Correct |
5 ms |
5076 KB |
Output is correct |
38 |
Correct |
3 ms |
5076 KB |
Output is correct |
39 |
Correct |
4 ms |
5024 KB |
Output is correct |
40 |
Correct |
3 ms |
5040 KB |
Output is correct |
41 |
Correct |
4 ms |
4948 KB |
Output is correct |
42 |
Correct |
3 ms |
4948 KB |
Output is correct |
43 |
Correct |
3 ms |
5012 KB |
Output is correct |
44 |
Correct |
3 ms |
5016 KB |
Output is correct |
45 |
Correct |
3 ms |
4948 KB |
Output is correct |
46 |
Correct |
3 ms |
4972 KB |
Output is correct |
47 |
Correct |
3 ms |
5020 KB |
Output is correct |
48 |
Correct |
3 ms |
5004 KB |
Output is correct |
49 |
Correct |
3 ms |
5012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
1845 ms |
109064 KB |
Output is correct |
3 |
Execution timed out |
4054 ms |
104584 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
1898 ms |
106652 KB |
Output is correct |
3 |
Execution timed out |
4077 ms |
101052 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
13 ms |
5460 KB |
Output is correct |
5 |
Correct |
9 ms |
5404 KB |
Output is correct |
6 |
Correct |
8 ms |
5460 KB |
Output is correct |
7 |
Correct |
9 ms |
5516 KB |
Output is correct |
8 |
Correct |
5 ms |
5472 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
5020 KB |
Output is correct |
11 |
Correct |
4 ms |
4948 KB |
Output is correct |
12 |
Correct |
5 ms |
5016 KB |
Output is correct |
13 |
Correct |
4 ms |
5076 KB |
Output is correct |
14 |
Correct |
4 ms |
5092 KB |
Output is correct |
15 |
Correct |
4 ms |
5076 KB |
Output is correct |
16 |
Correct |
5 ms |
5020 KB |
Output is correct |
17 |
Correct |
6 ms |
5028 KB |
Output is correct |
18 |
Correct |
6 ms |
5020 KB |
Output is correct |
19 |
Correct |
4 ms |
5004 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
5 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
4 ms |
5056 KB |
Output is correct |
24 |
Correct |
5 ms |
4948 KB |
Output is correct |
25 |
Correct |
4 ms |
4948 KB |
Output is correct |
26 |
Correct |
5 ms |
5012 KB |
Output is correct |
27 |
Correct |
4 ms |
5020 KB |
Output is correct |
28 |
Correct |
3 ms |
5076 KB |
Output is correct |
29 |
Correct |
3 ms |
4948 KB |
Output is correct |
30 |
Correct |
674 ms |
96964 KB |
Output is correct |
31 |
Correct |
1276 ms |
93872 KB |
Output is correct |
32 |
Correct |
1049 ms |
105244 KB |
Output is correct |
33 |
Correct |
1090 ms |
95252 KB |
Output is correct |
34 |
Correct |
778 ms |
95336 KB |
Output is correct |
35 |
Correct |
839 ms |
95684 KB |
Output is correct |
36 |
Correct |
698 ms |
96788 KB |
Output is correct |
37 |
Correct |
669 ms |
112004 KB |
Output is correct |
38 |
Correct |
1065 ms |
107504 KB |
Output is correct |
39 |
Correct |
604 ms |
96912 KB |
Output is correct |
40 |
Correct |
998 ms |
93724 KB |
Output is correct |
41 |
Correct |
1086 ms |
94072 KB |
Output is correct |
42 |
Correct |
1081 ms |
93068 KB |
Output is correct |
43 |
Correct |
990 ms |
92916 KB |
Output is correct |
44 |
Correct |
1027 ms |
92788 KB |
Output is correct |
45 |
Correct |
1059 ms |
93320 KB |
Output is correct |
46 |
Correct |
3 ms |
5016 KB |
Output is correct |
47 |
Correct |
3 ms |
5076 KB |
Output is correct |
48 |
Correct |
4 ms |
5016 KB |
Output is correct |
49 |
Correct |
3 ms |
5076 KB |
Output is correct |
50 |
Correct |
4 ms |
5076 KB |
Output is correct |
51 |
Correct |
3 ms |
4948 KB |
Output is correct |
52 |
Correct |
635 ms |
95368 KB |
Output is correct |
53 |
Correct |
1268 ms |
97240 KB |
Output is correct |
54 |
Correct |
900 ms |
113136 KB |
Output is correct |
55 |
Correct |
832 ms |
98776 KB |
Output is correct |
56 |
Correct |
805 ms |
98976 KB |
Output is correct |
57 |
Correct |
827 ms |
99012 KB |
Output is correct |
58 |
Correct |
725 ms |
100284 KB |
Output is correct |
59 |
Correct |
683 ms |
110928 KB |
Output is correct |
60 |
Correct |
1373 ms |
111104 KB |
Output is correct |
61 |
Correct |
674 ms |
100436 KB |
Output is correct |
62 |
Correct |
1330 ms |
97404 KB |
Output is correct |
63 |
Correct |
3 ms |
5076 KB |
Output is correct |
64 |
Correct |
4 ms |
5020 KB |
Output is correct |
65 |
Correct |
5 ms |
5076 KB |
Output is correct |
66 |
Correct |
3 ms |
5076 KB |
Output is correct |
67 |
Correct |
4 ms |
5024 KB |
Output is correct |
68 |
Correct |
3 ms |
5040 KB |
Output is correct |
69 |
Correct |
4 ms |
4948 KB |
Output is correct |
70 |
Correct |
3 ms |
4948 KB |
Output is correct |
71 |
Correct |
3 ms |
5012 KB |
Output is correct |
72 |
Correct |
3 ms |
5016 KB |
Output is correct |
73 |
Correct |
3 ms |
4948 KB |
Output is correct |
74 |
Correct |
3 ms |
4972 KB |
Output is correct |
75 |
Correct |
3 ms |
5020 KB |
Output is correct |
76 |
Correct |
3 ms |
5004 KB |
Output is correct |
77 |
Correct |
3 ms |
5012 KB |
Output is correct |
78 |
Correct |
3 ms |
4948 KB |
Output is correct |
79 |
Correct |
1845 ms |
109064 KB |
Output is correct |
80 |
Execution timed out |
4054 ms |
104584 KB |
Time limit exceeded |
81 |
Halted |
0 ms |
0 KB |
- |