답안 #615504

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
615504 2022-07-31T09:57:16 Z 장태환(#8493) Sprinkler (JOI22_sprinkler) C++17
41 / 100
4000 ms 68164 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
int N, L;
int qs, qe, n;
struct st
{
	vector<long long>r;
	int treeN;
	void init(int cnt)
	{
		for (treeN = 1; treeN < cnt; treeN *= 2);
		r.resize(2 * treeN + 1, 1);
	}
	void upd(int s, int e, int i = 1)
	{
		if (s > qe || qs > e)
			return;
		if (qs <= s && e <= qe)
		{
			r[i] *= n;
			if (r[i] >= L)
				r[i] %= L;
			return;
		}
		upd(s, (s + e) / 2, i * 2);
		upd((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 c;
vector<int>li[201000];
vector<pair<int, int>>dl[200100];
vector<int>dl2[200100];
void dfs(int n, int p = 0)
{
	st[n] = ++c;
	dl[d[n]].push_back({ st[n],n });
	dl2[d[n]].push_back(st[n]);
	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);
	}
	en[n] = c;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.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 = lower_bound(dl2[j].begin(), dl2[j].end(), st[cp]) - dl2[j].begin();
				if (lp != dl2[j].size() && dl2[j][lp] <= en[cp])
				{
					int rp = lower_bound(dl2[j].begin() + lp, dl2[j].end(), en[cp] + 1) - dl2[j].begin() - 1;
					qs = lp;
					qe = rp;
					n = w;
					arr[j].upd(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(int, int)':
sprinkler.cpp:62:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<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:91:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |   for (j = 0; j < dl[i].size(); j++)
      |               ~~^~~~~~~~~~~~~~
sprinkler.cpp:124:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  124 |     if (lp != dl2[j].size() && dl2[j][lp] <= en[cp])
      |         ~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 20736 KB Output is correct
2 Correct 11 ms 20728 KB Output is correct
3 Correct 12 ms 20636 KB Output is correct
4 Correct 12 ms 20904 KB Output is correct
5 Correct 13 ms 20820 KB Output is correct
6 Correct 13 ms 20864 KB Output is correct
7 Correct 13 ms 20820 KB Output is correct
8 Correct 11 ms 20820 KB Output is correct
9 Correct 16 ms 20692 KB Output is correct
10 Correct 12 ms 20692 KB Output is correct
11 Correct 13 ms 20628 KB Output is correct
12 Correct 14 ms 20740 KB Output is correct
13 Correct 14 ms 20696 KB Output is correct
14 Correct 11 ms 20664 KB Output is correct
15 Correct 10 ms 20744 KB Output is correct
16 Correct 13 ms 20692 KB Output is correct
17 Correct 13 ms 20740 KB Output is correct
18 Correct 16 ms 20692 KB Output is correct
19 Correct 12 ms 20692 KB Output is correct
20 Correct 12 ms 20692 KB Output is correct
21 Correct 11 ms 20692 KB Output is correct
22 Correct 10 ms 20692 KB Output is correct
23 Correct 12 ms 20644 KB Output is correct
24 Correct 10 ms 20692 KB Output is correct
25 Correct 13 ms 20748 KB Output is correct
26 Correct 12 ms 20708 KB Output is correct
27 Correct 11 ms 20700 KB Output is correct
28 Correct 11 ms 20692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 20692 KB Output is correct
2 Correct 423 ms 48684 KB Output is correct
3 Correct 602 ms 45656 KB Output is correct
4 Correct 520 ms 58332 KB Output is correct
5 Correct 555 ms 47352 KB Output is correct
6 Correct 546 ms 46460 KB Output is correct
7 Correct 603 ms 46448 KB Output is correct
8 Correct 502 ms 46368 KB Output is correct
9 Correct 598 ms 68164 KB Output is correct
10 Correct 604 ms 63008 KB Output is correct
11 Correct 457 ms 48560 KB Output is correct
12 Correct 722 ms 45712 KB Output is correct
13 Correct 565 ms 45388 KB Output is correct
14 Correct 527 ms 45812 KB Output is correct
15 Correct 548 ms 45560 KB Output is correct
16 Correct 614 ms 45628 KB Output is correct
17 Correct 691 ms 45604 KB Output is correct
18 Correct 16 ms 20692 KB Output is correct
19 Correct 15 ms 20692 KB Output is correct
20 Correct 15 ms 20664 KB Output is correct
21 Correct 15 ms 20692 KB Output is correct
22 Correct 15 ms 20692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 20692 KB Output is correct
2 Correct 423 ms 48684 KB Output is correct
3 Correct 602 ms 45656 KB Output is correct
4 Correct 520 ms 58332 KB Output is correct
5 Correct 555 ms 47352 KB Output is correct
6 Correct 546 ms 46460 KB Output is correct
7 Correct 603 ms 46448 KB Output is correct
8 Correct 502 ms 46368 KB Output is correct
9 Correct 598 ms 68164 KB Output is correct
10 Correct 604 ms 63008 KB Output is correct
11 Correct 457 ms 48560 KB Output is correct
12 Correct 722 ms 45712 KB Output is correct
13 Correct 565 ms 45388 KB Output is correct
14 Correct 527 ms 45812 KB Output is correct
15 Correct 548 ms 45560 KB Output is correct
16 Correct 614 ms 45628 KB Output is correct
17 Correct 691 ms 45604 KB Output is correct
18 Correct 16 ms 20692 KB Output is correct
19 Correct 15 ms 20692 KB Output is correct
20 Correct 15 ms 20664 KB Output is correct
21 Correct 15 ms 20692 KB Output is correct
22 Correct 15 ms 20692 KB Output is correct
23 Correct 11 ms 20692 KB Output is correct
24 Correct 450 ms 48524 KB Output is correct
25 Correct 922 ms 45652 KB Output is correct
26 Correct 625 ms 65428 KB Output is correct
27 Correct 757 ms 47232 KB Output is correct
28 Correct 906 ms 46696 KB Output is correct
29 Correct 808 ms 47064 KB Output is correct
30 Correct 509 ms 46348 KB Output is correct
31 Correct 613 ms 60628 KB Output is correct
32 Correct 804 ms 63032 KB Output is correct
33 Correct 443 ms 48820 KB Output is correct
34 Correct 878 ms 45388 KB Output is correct
35 Correct 15 ms 20620 KB Output is correct
36 Correct 16 ms 20692 KB Output is correct
37 Correct 12 ms 20736 KB Output is correct
38 Correct 13 ms 20692 KB Output is correct
39 Correct 12 ms 20716 KB Output is correct
40 Correct 13 ms 20704 KB Output is correct
41 Correct 14 ms 20712 KB Output is correct
42 Correct 13 ms 20692 KB Output is correct
43 Correct 12 ms 20644 KB Output is correct
44 Correct 14 ms 20648 KB Output is correct
45 Correct 12 ms 20692 KB Output is correct
46 Correct 14 ms 20716 KB Output is correct
47 Correct 15 ms 20644 KB Output is correct
48 Correct 17 ms 20656 KB Output is correct
49 Correct 13 ms 20692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 20692 KB Output is correct
2 Correct 896 ms 65012 KB Output is correct
3 Correct 2421 ms 58404 KB Output is correct
4 Correct 1245 ms 59884 KB Output is correct
5 Correct 2834 ms 45388 KB Output is correct
6 Correct 2011 ms 45052 KB Output is correct
7 Correct 1252 ms 45508 KB Output is correct
8 Correct 566 ms 44724 KB Output is correct
9 Correct 846 ms 58072 KB Output is correct
10 Correct 2438 ms 62408 KB Output is correct
11 Correct 1406 ms 46160 KB Output is correct
12 Execution timed out 4062 ms 45136 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 20736 KB Output is correct
2 Correct 883 ms 59748 KB Output is correct
3 Correct 3335 ms 53076 KB Output is correct
4 Correct 1140 ms 56964 KB Output is correct
5 Correct 2763 ms 47176 KB Output is correct
6 Correct 2246 ms 46824 KB Output is correct
7 Correct 1581 ms 45960 KB Output is correct
8 Correct 390 ms 46144 KB Output is correct
9 Correct 662 ms 66312 KB Output is correct
10 Correct 1959 ms 63356 KB Output is correct
11 Correct 1513 ms 48440 KB Output is correct
12 Execution timed out 4062 ms 45332 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 20736 KB Output is correct
2 Correct 11 ms 20728 KB Output is correct
3 Correct 12 ms 20636 KB Output is correct
4 Correct 12 ms 20904 KB Output is correct
5 Correct 13 ms 20820 KB Output is correct
6 Correct 13 ms 20864 KB Output is correct
7 Correct 13 ms 20820 KB Output is correct
8 Correct 11 ms 20820 KB Output is correct
9 Correct 16 ms 20692 KB Output is correct
10 Correct 12 ms 20692 KB Output is correct
11 Correct 13 ms 20628 KB Output is correct
12 Correct 14 ms 20740 KB Output is correct
13 Correct 14 ms 20696 KB Output is correct
14 Correct 11 ms 20664 KB Output is correct
15 Correct 10 ms 20744 KB Output is correct
16 Correct 13 ms 20692 KB Output is correct
17 Correct 13 ms 20740 KB Output is correct
18 Correct 16 ms 20692 KB Output is correct
19 Correct 12 ms 20692 KB Output is correct
20 Correct 12 ms 20692 KB Output is correct
21 Correct 11 ms 20692 KB Output is correct
22 Correct 10 ms 20692 KB Output is correct
23 Correct 12 ms 20644 KB Output is correct
24 Correct 10 ms 20692 KB Output is correct
25 Correct 13 ms 20748 KB Output is correct
26 Correct 12 ms 20708 KB Output is correct
27 Correct 11 ms 20700 KB Output is correct
28 Correct 11 ms 20692 KB Output is correct
29 Correct 12 ms 20692 KB Output is correct
30 Correct 423 ms 48684 KB Output is correct
31 Correct 602 ms 45656 KB Output is correct
32 Correct 520 ms 58332 KB Output is correct
33 Correct 555 ms 47352 KB Output is correct
34 Correct 546 ms 46460 KB Output is correct
35 Correct 603 ms 46448 KB Output is correct
36 Correct 502 ms 46368 KB Output is correct
37 Correct 598 ms 68164 KB Output is correct
38 Correct 604 ms 63008 KB Output is correct
39 Correct 457 ms 48560 KB Output is correct
40 Correct 722 ms 45712 KB Output is correct
41 Correct 565 ms 45388 KB Output is correct
42 Correct 527 ms 45812 KB Output is correct
43 Correct 548 ms 45560 KB Output is correct
44 Correct 614 ms 45628 KB Output is correct
45 Correct 691 ms 45604 KB Output is correct
46 Correct 16 ms 20692 KB Output is correct
47 Correct 15 ms 20692 KB Output is correct
48 Correct 15 ms 20664 KB Output is correct
49 Correct 15 ms 20692 KB Output is correct
50 Correct 15 ms 20692 KB Output is correct
51 Correct 11 ms 20692 KB Output is correct
52 Correct 450 ms 48524 KB Output is correct
53 Correct 922 ms 45652 KB Output is correct
54 Correct 625 ms 65428 KB Output is correct
55 Correct 757 ms 47232 KB Output is correct
56 Correct 906 ms 46696 KB Output is correct
57 Correct 808 ms 47064 KB Output is correct
58 Correct 509 ms 46348 KB Output is correct
59 Correct 613 ms 60628 KB Output is correct
60 Correct 804 ms 63032 KB Output is correct
61 Correct 443 ms 48820 KB Output is correct
62 Correct 878 ms 45388 KB Output is correct
63 Correct 15 ms 20620 KB Output is correct
64 Correct 16 ms 20692 KB Output is correct
65 Correct 12 ms 20736 KB Output is correct
66 Correct 13 ms 20692 KB Output is correct
67 Correct 12 ms 20716 KB Output is correct
68 Correct 13 ms 20704 KB Output is correct
69 Correct 14 ms 20712 KB Output is correct
70 Correct 13 ms 20692 KB Output is correct
71 Correct 12 ms 20644 KB Output is correct
72 Correct 14 ms 20648 KB Output is correct
73 Correct 12 ms 20692 KB Output is correct
74 Correct 14 ms 20716 KB Output is correct
75 Correct 15 ms 20644 KB Output is correct
76 Correct 17 ms 20656 KB Output is correct
77 Correct 13 ms 20692 KB Output is correct
78 Correct 16 ms 20692 KB Output is correct
79 Correct 896 ms 65012 KB Output is correct
80 Correct 2421 ms 58404 KB Output is correct
81 Correct 1245 ms 59884 KB Output is correct
82 Correct 2834 ms 45388 KB Output is correct
83 Correct 2011 ms 45052 KB Output is correct
84 Correct 1252 ms 45508 KB Output is correct
85 Correct 566 ms 44724 KB Output is correct
86 Correct 846 ms 58072 KB Output is correct
87 Correct 2438 ms 62408 KB Output is correct
88 Correct 1406 ms 46160 KB Output is correct
89 Execution timed out 4062 ms 45136 KB Time limit exceeded
90 Halted 0 ms 0 KB -