# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
615413 |
2022-07-31T09:02:33 Z |
장태환(#8493) |
Sprinkler (JOI22_sprinkler) |
C++17 |
|
4000 ms |
401584 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
int N, L;
struct st
{
vector<int>r;
vector<int>lazy;
int treeN;
void init(int cnt)
{
for (treeN = 1; treeN < cnt; treeN *= 2);
r.resize(2 * treeN + 3, 1);
lazy.resize(2 * treeN + 3, 1);
}
void upd(int qs, int qe, int n, int s, int e, int i = 1)
{
if (s > qe || qs > e)
return;
if (qs <= s && e <= qe)
{
r[i] *= n;
r[i] %= L;
return;
}
upd(qs, qe, n, s, (s + e) / 2, i * 2);
upd(qs, qe, n, (s + e) / 2 + 1, e, i * 2 + 1);
}
int ge(int qs, int qe, int n, int i = 1)
{
if (qs == qe)
{
return r[i];
}
int m = (qs + qe) / 2;
if (n > m)
{
return r[i] * ge(m + 1, qe, n, i * 2 + 1) % L;
}
else
{
return r[i] * ge(qs, m, n, i * 2) % L;
}
}
}arr[200100];
int d[201000];
int pos[200100];
int par[200100];
int st[201000];
int en[200100];
int sp[200100][100],ep[200100][100];
int c;
vector<int>li[201000];
vector<pair<int, int>>dl[200100];
void dfs(int n, int p = 0)
{
st[n] = ++c;
dl[d[n]].push_back({ st[n],n });
sp[n][0] = ep[n][0] = dl[d[n]].size()-1;
int i;
for (i = 0; i < li[n].size(); i++)
{
if (li[n][i] == p)
continue;
par[li[n][i]] = n;
d[li[n][i]] = d[n] + 1;
dfs(li[n][i], n);
int j;
for (j = 1; j < 90; j++)
{
sp[n][j] = min(sp[n][j], sp[li[n][i]][j - 1]);
ep[n][j] = max(ep[n][j], ep[li[n][i]][j - 1]);
}
}
en[n] = c;
}
signed main()
{
memset(sp, 10, sizeof(sp));
memset(ep, -10, sizeof(ep));
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> L;
int i;
for (i = 1; i < N; i++)
{
int a, b;
cin >> a >> b;
li[a].push_back(b);
li[b].push_back(a);
}
dfs(1);
for (i = 0; i <= N; i++)
{
arr[i].init(dl[i].size());
int j;
for (j = 0; j < dl[i].size(); j++)
{
pos[dl[i][j].second] = j;
}
}
for (i = 1; i <= N; i++)
{
int a;
cin >> a;
arr[d[i]].r[pos[i] + arr[d[i]].treeN] = a;
}
int Q;
cin >> Q;
while (Q--)
{
int a;
cin >> a;
if (a == 1)
{
int b, c, w;
cin >> b >> c >> w;
int j;
int dp = d[b];
int cp = b;
for (j = dp + c; j >= dp - c; j--)
{
if (j + dp - d[cp] * 2 + 2 <= c && cp != 1)
{
cp = par[cp];
}
if (j < 0)
break;
int lp = sp[cp][j - d[cp]];
int rp = ep[cp][j - d[cp]];
if (lp <= rp)
{
arr[j].upd(lp, rp, w, 0, arr[j].treeN - 1);
}
}
}
else
{
int b;
cin >> b;
cout << arr[d[b]].ge(0, arr[d[b]].treeN - 1, pos[b]) << '\n';
}
}
}
Compilation message
sprinkler.cpp: In function 'void dfs(long long int, long long int)':
sprinkler.cpp:62:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for (i = 0; i < li[n].size(); i++)
| ~~^~~~~~~~~~~~~~
sprinkler.cpp: In function 'int main()':
sprinkler.cpp:98:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
98 | for (j = 0; j < dl[i].size(); j++)
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
334064 KB |
Output is correct |
2 |
Correct |
135 ms |
333948 KB |
Output is correct |
3 |
Correct |
132 ms |
333936 KB |
Output is correct |
4 |
Correct |
123 ms |
334292 KB |
Output is correct |
5 |
Correct |
122 ms |
334184 KB |
Output is correct |
6 |
Correct |
123 ms |
334224 KB |
Output is correct |
7 |
Correct |
154 ms |
334200 KB |
Output is correct |
8 |
Correct |
122 ms |
334220 KB |
Output is correct |
9 |
Correct |
128 ms |
333912 KB |
Output is correct |
10 |
Correct |
124 ms |
333976 KB |
Output is correct |
11 |
Correct |
131 ms |
333912 KB |
Output is correct |
12 |
Correct |
152 ms |
333976 KB |
Output is correct |
13 |
Correct |
121 ms |
333892 KB |
Output is correct |
14 |
Correct |
121 ms |
333952 KB |
Output is correct |
15 |
Correct |
123 ms |
333884 KB |
Output is correct |
16 |
Correct |
128 ms |
333996 KB |
Output is correct |
17 |
Correct |
147 ms |
333896 KB |
Output is correct |
18 |
Correct |
124 ms |
333912 KB |
Output is correct |
19 |
Correct |
124 ms |
333984 KB |
Output is correct |
20 |
Correct |
121 ms |
333928 KB |
Output is correct |
21 |
Correct |
126 ms |
333964 KB |
Output is correct |
22 |
Correct |
142 ms |
334040 KB |
Output is correct |
23 |
Correct |
120 ms |
333908 KB |
Output is correct |
24 |
Correct |
119 ms |
333896 KB |
Output is correct |
25 |
Correct |
122 ms |
333956 KB |
Output is correct |
26 |
Correct |
122 ms |
333988 KB |
Output is correct |
27 |
Correct |
131 ms |
333884 KB |
Output is correct |
28 |
Correct |
127 ms |
333940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
334028 KB |
Output is correct |
2 |
Correct |
684 ms |
385564 KB |
Output is correct |
3 |
Correct |
806 ms |
382864 KB |
Output is correct |
4 |
Correct |
777 ms |
392792 KB |
Output is correct |
5 |
Correct |
727 ms |
384264 KB |
Output is correct |
6 |
Correct |
720 ms |
383060 KB |
Output is correct |
7 |
Correct |
708 ms |
382700 KB |
Output is correct |
8 |
Correct |
635 ms |
382208 KB |
Output is correct |
9 |
Correct |
749 ms |
401584 KB |
Output is correct |
10 |
Correct |
850 ms |
396536 KB |
Output is correct |
11 |
Correct |
626 ms |
385448 KB |
Output is correct |
12 |
Correct |
820 ms |
382652 KB |
Output is correct |
13 |
Correct |
563 ms |
382140 KB |
Output is correct |
14 |
Correct |
637 ms |
383192 KB |
Output is correct |
15 |
Correct |
623 ms |
382004 KB |
Output is correct |
16 |
Correct |
638 ms |
382092 KB |
Output is correct |
17 |
Correct |
670 ms |
381900 KB |
Output is correct |
18 |
Correct |
141 ms |
334068 KB |
Output is correct |
19 |
Correct |
124 ms |
333888 KB |
Output is correct |
20 |
Correct |
136 ms |
333968 KB |
Output is correct |
21 |
Correct |
140 ms |
333992 KB |
Output is correct |
22 |
Correct |
127 ms |
333972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
334028 KB |
Output is correct |
2 |
Correct |
684 ms |
385564 KB |
Output is correct |
3 |
Correct |
806 ms |
382864 KB |
Output is correct |
4 |
Correct |
777 ms |
392792 KB |
Output is correct |
5 |
Correct |
727 ms |
384264 KB |
Output is correct |
6 |
Correct |
720 ms |
383060 KB |
Output is correct |
7 |
Correct |
708 ms |
382700 KB |
Output is correct |
8 |
Correct |
635 ms |
382208 KB |
Output is correct |
9 |
Correct |
749 ms |
401584 KB |
Output is correct |
10 |
Correct |
850 ms |
396536 KB |
Output is correct |
11 |
Correct |
626 ms |
385448 KB |
Output is correct |
12 |
Correct |
820 ms |
382652 KB |
Output is correct |
13 |
Correct |
563 ms |
382140 KB |
Output is correct |
14 |
Correct |
637 ms |
383192 KB |
Output is correct |
15 |
Correct |
623 ms |
382004 KB |
Output is correct |
16 |
Correct |
638 ms |
382092 KB |
Output is correct |
17 |
Correct |
670 ms |
381900 KB |
Output is correct |
18 |
Correct |
141 ms |
334068 KB |
Output is correct |
19 |
Correct |
124 ms |
333888 KB |
Output is correct |
20 |
Correct |
136 ms |
333968 KB |
Output is correct |
21 |
Correct |
140 ms |
333992 KB |
Output is correct |
22 |
Correct |
127 ms |
333972 KB |
Output is correct |
23 |
Correct |
148 ms |
333912 KB |
Output is correct |
24 |
Correct |
703 ms |
385428 KB |
Output is correct |
25 |
Correct |
932 ms |
382324 KB |
Output is correct |
26 |
Correct |
809 ms |
399088 KB |
Output is correct |
27 |
Correct |
786 ms |
383904 KB |
Output is correct |
28 |
Correct |
768 ms |
383312 KB |
Output is correct |
29 |
Correct |
799 ms |
383948 KB |
Output is correct |
30 |
Correct |
664 ms |
382264 KB |
Output is correct |
31 |
Correct |
726 ms |
395084 KB |
Output is correct |
32 |
Correct |
914 ms |
396796 KB |
Output is correct |
33 |
Correct |
673 ms |
385696 KB |
Output is correct |
34 |
Correct |
954 ms |
381884 KB |
Output is correct |
35 |
Correct |
127 ms |
334004 KB |
Output is correct |
36 |
Correct |
141 ms |
334036 KB |
Output is correct |
37 |
Correct |
131 ms |
333908 KB |
Output is correct |
38 |
Correct |
130 ms |
333900 KB |
Output is correct |
39 |
Correct |
124 ms |
333924 KB |
Output is correct |
40 |
Correct |
132 ms |
333892 KB |
Output is correct |
41 |
Correct |
123 ms |
333980 KB |
Output is correct |
42 |
Correct |
134 ms |
333996 KB |
Output is correct |
43 |
Correct |
132 ms |
333932 KB |
Output is correct |
44 |
Correct |
126 ms |
333884 KB |
Output is correct |
45 |
Correct |
120 ms |
333992 KB |
Output is correct |
46 |
Correct |
124 ms |
333964 KB |
Output is correct |
47 |
Correct |
155 ms |
334000 KB |
Output is correct |
48 |
Correct |
126 ms |
333968 KB |
Output is correct |
49 |
Correct |
122 ms |
333896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
334028 KB |
Output is correct |
2 |
Correct |
1062 ms |
398620 KB |
Output is correct |
3 |
Correct |
3904 ms |
392900 KB |
Output is correct |
4 |
Correct |
1681 ms |
394176 KB |
Output is correct |
5 |
Correct |
2099 ms |
382184 KB |
Output is correct |
6 |
Correct |
1411 ms |
381720 KB |
Output is correct |
7 |
Correct |
1087 ms |
382852 KB |
Output is correct |
8 |
Correct |
576 ms |
380892 KB |
Output is correct |
9 |
Correct |
1100 ms |
392740 KB |
Output is correct |
10 |
Correct |
3453 ms |
396272 KB |
Output is correct |
11 |
Correct |
1288 ms |
383380 KB |
Output is correct |
12 |
Execution timed out |
4081 ms |
382216 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
333892 KB |
Output is correct |
2 |
Correct |
1381 ms |
393728 KB |
Output is correct |
3 |
Execution timed out |
4099 ms |
387428 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
334064 KB |
Output is correct |
2 |
Correct |
135 ms |
333948 KB |
Output is correct |
3 |
Correct |
132 ms |
333936 KB |
Output is correct |
4 |
Correct |
123 ms |
334292 KB |
Output is correct |
5 |
Correct |
122 ms |
334184 KB |
Output is correct |
6 |
Correct |
123 ms |
334224 KB |
Output is correct |
7 |
Correct |
154 ms |
334200 KB |
Output is correct |
8 |
Correct |
122 ms |
334220 KB |
Output is correct |
9 |
Correct |
128 ms |
333912 KB |
Output is correct |
10 |
Correct |
124 ms |
333976 KB |
Output is correct |
11 |
Correct |
131 ms |
333912 KB |
Output is correct |
12 |
Correct |
152 ms |
333976 KB |
Output is correct |
13 |
Correct |
121 ms |
333892 KB |
Output is correct |
14 |
Correct |
121 ms |
333952 KB |
Output is correct |
15 |
Correct |
123 ms |
333884 KB |
Output is correct |
16 |
Correct |
128 ms |
333996 KB |
Output is correct |
17 |
Correct |
147 ms |
333896 KB |
Output is correct |
18 |
Correct |
124 ms |
333912 KB |
Output is correct |
19 |
Correct |
124 ms |
333984 KB |
Output is correct |
20 |
Correct |
121 ms |
333928 KB |
Output is correct |
21 |
Correct |
126 ms |
333964 KB |
Output is correct |
22 |
Correct |
142 ms |
334040 KB |
Output is correct |
23 |
Correct |
120 ms |
333908 KB |
Output is correct |
24 |
Correct |
119 ms |
333896 KB |
Output is correct |
25 |
Correct |
122 ms |
333956 KB |
Output is correct |
26 |
Correct |
122 ms |
333988 KB |
Output is correct |
27 |
Correct |
131 ms |
333884 KB |
Output is correct |
28 |
Correct |
127 ms |
333940 KB |
Output is correct |
29 |
Correct |
134 ms |
334028 KB |
Output is correct |
30 |
Correct |
684 ms |
385564 KB |
Output is correct |
31 |
Correct |
806 ms |
382864 KB |
Output is correct |
32 |
Correct |
777 ms |
392792 KB |
Output is correct |
33 |
Correct |
727 ms |
384264 KB |
Output is correct |
34 |
Correct |
720 ms |
383060 KB |
Output is correct |
35 |
Correct |
708 ms |
382700 KB |
Output is correct |
36 |
Correct |
635 ms |
382208 KB |
Output is correct |
37 |
Correct |
749 ms |
401584 KB |
Output is correct |
38 |
Correct |
850 ms |
396536 KB |
Output is correct |
39 |
Correct |
626 ms |
385448 KB |
Output is correct |
40 |
Correct |
820 ms |
382652 KB |
Output is correct |
41 |
Correct |
563 ms |
382140 KB |
Output is correct |
42 |
Correct |
637 ms |
383192 KB |
Output is correct |
43 |
Correct |
623 ms |
382004 KB |
Output is correct |
44 |
Correct |
638 ms |
382092 KB |
Output is correct |
45 |
Correct |
670 ms |
381900 KB |
Output is correct |
46 |
Correct |
141 ms |
334068 KB |
Output is correct |
47 |
Correct |
124 ms |
333888 KB |
Output is correct |
48 |
Correct |
136 ms |
333968 KB |
Output is correct |
49 |
Correct |
140 ms |
333992 KB |
Output is correct |
50 |
Correct |
127 ms |
333972 KB |
Output is correct |
51 |
Correct |
148 ms |
333912 KB |
Output is correct |
52 |
Correct |
703 ms |
385428 KB |
Output is correct |
53 |
Correct |
932 ms |
382324 KB |
Output is correct |
54 |
Correct |
809 ms |
399088 KB |
Output is correct |
55 |
Correct |
786 ms |
383904 KB |
Output is correct |
56 |
Correct |
768 ms |
383312 KB |
Output is correct |
57 |
Correct |
799 ms |
383948 KB |
Output is correct |
58 |
Correct |
664 ms |
382264 KB |
Output is correct |
59 |
Correct |
726 ms |
395084 KB |
Output is correct |
60 |
Correct |
914 ms |
396796 KB |
Output is correct |
61 |
Correct |
673 ms |
385696 KB |
Output is correct |
62 |
Correct |
954 ms |
381884 KB |
Output is correct |
63 |
Correct |
127 ms |
334004 KB |
Output is correct |
64 |
Correct |
141 ms |
334036 KB |
Output is correct |
65 |
Correct |
131 ms |
333908 KB |
Output is correct |
66 |
Correct |
130 ms |
333900 KB |
Output is correct |
67 |
Correct |
124 ms |
333924 KB |
Output is correct |
68 |
Correct |
132 ms |
333892 KB |
Output is correct |
69 |
Correct |
123 ms |
333980 KB |
Output is correct |
70 |
Correct |
134 ms |
333996 KB |
Output is correct |
71 |
Correct |
132 ms |
333932 KB |
Output is correct |
72 |
Correct |
126 ms |
333884 KB |
Output is correct |
73 |
Correct |
120 ms |
333992 KB |
Output is correct |
74 |
Correct |
124 ms |
333964 KB |
Output is correct |
75 |
Correct |
155 ms |
334000 KB |
Output is correct |
76 |
Correct |
126 ms |
333968 KB |
Output is correct |
77 |
Correct |
122 ms |
333896 KB |
Output is correct |
78 |
Correct |
123 ms |
334028 KB |
Output is correct |
79 |
Correct |
1062 ms |
398620 KB |
Output is correct |
80 |
Correct |
3904 ms |
392900 KB |
Output is correct |
81 |
Correct |
1681 ms |
394176 KB |
Output is correct |
82 |
Correct |
2099 ms |
382184 KB |
Output is correct |
83 |
Correct |
1411 ms |
381720 KB |
Output is correct |
84 |
Correct |
1087 ms |
382852 KB |
Output is correct |
85 |
Correct |
576 ms |
380892 KB |
Output is correct |
86 |
Correct |
1100 ms |
392740 KB |
Output is correct |
87 |
Correct |
3453 ms |
396272 KB |
Output is correct |
88 |
Correct |
1288 ms |
383380 KB |
Output is correct |
89 |
Execution timed out |
4081 ms |
382216 KB |
Time limit exceeded |
90 |
Halted |
0 ms |
0 KB |
- |