Submission #589098

# Submission time Handle Problem Language Result Execution time Memory
589098 2022-07-04T09:20:46 Z Red_Inside Sprinkler (JOI22_sprinkler) C++17
41 / 100
4000 ms 80796 KB
//
#include <bits/stdc++.h>
 
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
#define all(v) v.begin(), v.end()
#define ld long double
#define ull unsigned long long
 
using namespace std;
const int maxn=2e5+100,LOG=17, mod=1e9+7;
int block = 320, timer = 0;
const ld EPS = 1e-18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
#define bt(i) (1 << (i))
//#define int ll
const int inf=1e9+10;
#define y1 yy
#define prev pre
#define pii pair <int, int>
 
int n, q, anc[maxn], tin[maxn], tout[maxn], deep[maxn], sz[maxn];
ll L, h[maxn];
vector <int> edge[maxn];
vector <pii> vec[maxn];
vector <ll> t[maxn];
 
void dfs(int v, int pred = -1)
{
	tin[v] = ++timer;
	vec[deep[v]].pb({tin[v], v});
	for(auto to : edge[v])
	{
		if(to == pred) continue;
		deep[to] = deep[v] + 1;
		anc[to] = v;
		dfs(to, v);
	}
	tout[v] = timer;
}
 
void push(int v, int tn)
{
	t[tn][v * 2] = t[tn][v * 2] * t[tn][v] % L;
	t[tn][v * 2 + 1] = t[tn][v * 2 + 1] * t[tn][v] % L;
	t[tn][v] = 1;
}
 
void upd(int v, int tl, int tr, int l, int r, ll w, int tn)
{
	if(l <= tl && tr <= r)
	{
		t[tn][v] = t[tn][v] * w % L;
		return;
	}
	if(l > tr || r < tl) return;
	push(v, tn);
	upd(v * 2, tl, (tl + tr) / 2, l, r, w, tn);
	upd(v * 2 + 1, (tl + tr) / 2 + 1, tr, l, r, w, tn);
}
 
ll get(int v, int tl, int tr, int pos, int tn)
{
	if(tl == tr) return t[tn][v];
	push(v, tn);
	if(pos <= (tl + tr) / 2) return get(v * 2, tl, (tl + tr) / 2, pos, tn);
	return get(v * 2 + 1, (tl + tr) / 2 + 1, tr, pos, tn);
}
 
void update(int x, ll w, int d)
{
	if(d < 0) return;
	if(sz[deep[x] + d] == 0) return;
//	cout << "UPDATE " << x << " " << w << " " << d << " " << tin[x] << " " << tout[x] << endl;
//	cout << "VECTOR\n";
//	for(auto i : vec[deep[x] + d]) cout << "   " << i.f << " " << i.s << endl;
	int L = lower_bound(all(vec[deep[x] + d]), mp(tin[x], 0)) - vec[deep[x] + d].begin() + 1;
	int R = upper_bound(all(vec[deep[x] + d]), mp(tout[x], inf)) - vec[deep[x] + d].begin();
	upd(1, 1, sz[deep[x] + d], L, R, w, deep[x] + d);
}
 
main()
{
	IOS
	cin >> n >> L;
	forn(1, i, n - 1)
	{
		int l, r;
		cin >> l >> r;
		edge[l].pb(r);
		edge[r].pb(l);
	}
	forn(1, i, n) cin >> h[i];
	deep[1] = 1;
	dfs(1);
	forn(1, i, n)
	{
		sz[i] = vec[i].size();
		t[i].assign(sz[i] * 4 + 10, 1);
//		build(1, 1, sz[i], i);
	}
	cin >> q;
	forn(1, i, q)
	{
		int ty;
		cin >> ty;
		if(ty == 1)
		{
			int x, d;
			ll w;
			cin >> x >> d >> w;
			vector <int> ancs;
			int v = x;
			forn(0, iter, d)
			{
				ancs.pb(v);
				v = anc[v];
				if(v == 0) break;
			}
			forn(-d, a, d)
			{
				int b = (d + a) / 2;
				if(ancs.size() > b)
				{
//					cout << "START UPDATE " << ancs[b] << " " << a << " " << b << endl;
					update(ancs[b], w, b - a);
				}
				else
				{
//					cout << "START UPDATE " << ancs.back() << " " << a << " " << b << endl;
					update(ancs.back(), w, (int)ancs.size() - 1 - a);
				}
			}
		}
		else
		{
			int x;
			cin >> x;
			int pos = lower_bound(all(vec[deep[x]]), mp(tin[x], x)) - vec[deep[x]].begin() + 1;
			ll ans = h[x] * get(1, 1, sz[deep[x]], pos, deep[x]) % L;
//			cout << h[x] << " " << get(1, 1, sz[deep[x]], pos, deep[x]) << endl;
			cout << ans << "\n";
		}
	}
}

Compilation message

sprinkler.cpp:92:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   92 | main()
      | ^~~~
sprinkler.cpp: In function 'int main()':
sprinkler.cpp:133:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  133 |     if(ancs.size() > b)
      |        ~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 12 ms 14432 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 9 ms 14668 KB Output is correct
5 Correct 13 ms 14676 KB Output is correct
6 Correct 9 ms 14704 KB Output is correct
7 Correct 9 ms 14676 KB Output is correct
8 Correct 9 ms 14704 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 8 ms 14412 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 8 ms 14456 KB Output is correct
13 Correct 8 ms 14440 KB Output is correct
14 Correct 10 ms 14420 KB Output is correct
15 Correct 10 ms 14584 KB Output is correct
16 Correct 8 ms 14436 KB Output is correct
17 Correct 8 ms 14436 KB Output is correct
18 Correct 8 ms 14420 KB Output is correct
19 Correct 8 ms 14396 KB Output is correct
20 Correct 8 ms 14420 KB Output is correct
21 Correct 8 ms 14420 KB Output is correct
22 Correct 10 ms 14548 KB Output is correct
23 Correct 8 ms 14376 KB Output is correct
24 Correct 10 ms 14432 KB Output is correct
25 Correct 9 ms 14420 KB Output is correct
26 Correct 8 ms 14436 KB Output is correct
27 Correct 8 ms 14420 KB Output is correct
28 Correct 10 ms 14424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14456 KB Output is correct
2 Correct 468 ms 59320 KB Output is correct
3 Correct 785 ms 56168 KB Output is correct
4 Correct 481 ms 69200 KB Output is correct
5 Correct 568 ms 57516 KB Output is correct
6 Correct 732 ms 56924 KB Output is correct
7 Correct 634 ms 57128 KB Output is correct
8 Correct 531 ms 57512 KB Output is correct
9 Correct 421 ms 77004 KB Output is correct
10 Correct 542 ms 73028 KB Output is correct
11 Correct 485 ms 58116 KB Output is correct
12 Correct 892 ms 56088 KB Output is correct
13 Correct 396 ms 55876 KB Output is correct
14 Correct 678 ms 55968 KB Output is correct
15 Correct 804 ms 55936 KB Output is correct
16 Correct 886 ms 55836 KB Output is correct
17 Correct 951 ms 56552 KB Output is correct
18 Correct 10 ms 14436 KB Output is correct
19 Correct 11 ms 14436 KB Output is correct
20 Correct 10 ms 14420 KB Output is correct
21 Correct 9 ms 14436 KB Output is correct
22 Correct 10 ms 14440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14456 KB Output is correct
2 Correct 468 ms 59320 KB Output is correct
3 Correct 785 ms 56168 KB Output is correct
4 Correct 481 ms 69200 KB Output is correct
5 Correct 568 ms 57516 KB Output is correct
6 Correct 732 ms 56924 KB Output is correct
7 Correct 634 ms 57128 KB Output is correct
8 Correct 531 ms 57512 KB Output is correct
9 Correct 421 ms 77004 KB Output is correct
10 Correct 542 ms 73028 KB Output is correct
11 Correct 485 ms 58116 KB Output is correct
12 Correct 892 ms 56088 KB Output is correct
13 Correct 396 ms 55876 KB Output is correct
14 Correct 678 ms 55968 KB Output is correct
15 Correct 804 ms 55936 KB Output is correct
16 Correct 886 ms 55836 KB Output is correct
17 Correct 951 ms 56552 KB Output is correct
18 Correct 10 ms 14436 KB Output is correct
19 Correct 11 ms 14436 KB Output is correct
20 Correct 10 ms 14420 KB Output is correct
21 Correct 9 ms 14436 KB Output is correct
22 Correct 10 ms 14440 KB Output is correct
23 Correct 9 ms 14436 KB Output is correct
24 Correct 549 ms 59176 KB Output is correct
25 Correct 1190 ms 60920 KB Output is correct
26 Correct 499 ms 80796 KB Output is correct
27 Correct 650 ms 62860 KB Output is correct
28 Correct 774 ms 62508 KB Output is correct
29 Correct 877 ms 62416 KB Output is correct
30 Correct 525 ms 62740 KB Output is correct
31 Correct 431 ms 77116 KB Output is correct
32 Correct 594 ms 78276 KB Output is correct
33 Correct 469 ms 64732 KB Output is correct
34 Correct 1123 ms 60828 KB Output is correct
35 Correct 8 ms 14480 KB Output is correct
36 Correct 7 ms 14428 KB Output is correct
37 Correct 8 ms 14392 KB Output is correct
38 Correct 8 ms 14420 KB Output is correct
39 Correct 8 ms 14420 KB Output is correct
40 Correct 8 ms 14408 KB Output is correct
41 Correct 7 ms 14420 KB Output is correct
42 Correct 7 ms 14432 KB Output is correct
43 Correct 7 ms 14416 KB Output is correct
44 Correct 8 ms 14420 KB Output is correct
45 Correct 8 ms 14420 KB Output is correct
46 Correct 8 ms 14420 KB Output is correct
47 Correct 7 ms 14420 KB Output is correct
48 Correct 8 ms 14476 KB Output is correct
49 Correct 8 ms 14400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14428 KB Output is correct
2 Correct 670 ms 74420 KB Output is correct
3 Correct 2606 ms 69168 KB Output is correct
4 Correct 1171 ms 70756 KB Output is correct
5 Correct 3444 ms 56044 KB Output is correct
6 Correct 1984 ms 55792 KB Output is correct
7 Correct 1175 ms 55732 KB Output is correct
8 Correct 440 ms 55964 KB Output is correct
9 Correct 681 ms 68932 KB Output is correct
10 Correct 2340 ms 72428 KB Output is correct
11 Correct 1451 ms 56476 KB Output is correct
12 Execution timed out 4080 ms 55520 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 642 ms 68632 KB Output is correct
3 Correct 2796 ms 62684 KB Output is correct
4 Correct 1131 ms 66044 KB Output is correct
5 Correct 3377 ms 55612 KB Output is correct
6 Correct 1806 ms 57248 KB Output is correct
7 Correct 1319 ms 56976 KB Output is correct
8 Correct 465 ms 57356 KB Output is correct
9 Correct 730 ms 76596 KB Output is correct
10 Correct 2614 ms 73468 KB Output is correct
11 Correct 1686 ms 59132 KB Output is correct
12 Execution timed out 4016 ms 55056 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 12 ms 14432 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 9 ms 14668 KB Output is correct
5 Correct 13 ms 14676 KB Output is correct
6 Correct 9 ms 14704 KB Output is correct
7 Correct 9 ms 14676 KB Output is correct
8 Correct 9 ms 14704 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 8 ms 14412 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 8 ms 14456 KB Output is correct
13 Correct 8 ms 14440 KB Output is correct
14 Correct 10 ms 14420 KB Output is correct
15 Correct 10 ms 14584 KB Output is correct
16 Correct 8 ms 14436 KB Output is correct
17 Correct 8 ms 14436 KB Output is correct
18 Correct 8 ms 14420 KB Output is correct
19 Correct 8 ms 14396 KB Output is correct
20 Correct 8 ms 14420 KB Output is correct
21 Correct 8 ms 14420 KB Output is correct
22 Correct 10 ms 14548 KB Output is correct
23 Correct 8 ms 14376 KB Output is correct
24 Correct 10 ms 14432 KB Output is correct
25 Correct 9 ms 14420 KB Output is correct
26 Correct 8 ms 14436 KB Output is correct
27 Correct 8 ms 14420 KB Output is correct
28 Correct 10 ms 14424 KB Output is correct
29 Correct 8 ms 14456 KB Output is correct
30 Correct 468 ms 59320 KB Output is correct
31 Correct 785 ms 56168 KB Output is correct
32 Correct 481 ms 69200 KB Output is correct
33 Correct 568 ms 57516 KB Output is correct
34 Correct 732 ms 56924 KB Output is correct
35 Correct 634 ms 57128 KB Output is correct
36 Correct 531 ms 57512 KB Output is correct
37 Correct 421 ms 77004 KB Output is correct
38 Correct 542 ms 73028 KB Output is correct
39 Correct 485 ms 58116 KB Output is correct
40 Correct 892 ms 56088 KB Output is correct
41 Correct 396 ms 55876 KB Output is correct
42 Correct 678 ms 55968 KB Output is correct
43 Correct 804 ms 55936 KB Output is correct
44 Correct 886 ms 55836 KB Output is correct
45 Correct 951 ms 56552 KB Output is correct
46 Correct 10 ms 14436 KB Output is correct
47 Correct 11 ms 14436 KB Output is correct
48 Correct 10 ms 14420 KB Output is correct
49 Correct 9 ms 14436 KB Output is correct
50 Correct 10 ms 14440 KB Output is correct
51 Correct 9 ms 14436 KB Output is correct
52 Correct 549 ms 59176 KB Output is correct
53 Correct 1190 ms 60920 KB Output is correct
54 Correct 499 ms 80796 KB Output is correct
55 Correct 650 ms 62860 KB Output is correct
56 Correct 774 ms 62508 KB Output is correct
57 Correct 877 ms 62416 KB Output is correct
58 Correct 525 ms 62740 KB Output is correct
59 Correct 431 ms 77116 KB Output is correct
60 Correct 594 ms 78276 KB Output is correct
61 Correct 469 ms 64732 KB Output is correct
62 Correct 1123 ms 60828 KB Output is correct
63 Correct 8 ms 14480 KB Output is correct
64 Correct 7 ms 14428 KB Output is correct
65 Correct 8 ms 14392 KB Output is correct
66 Correct 8 ms 14420 KB Output is correct
67 Correct 8 ms 14420 KB Output is correct
68 Correct 8 ms 14408 KB Output is correct
69 Correct 7 ms 14420 KB Output is correct
70 Correct 7 ms 14432 KB Output is correct
71 Correct 7 ms 14416 KB Output is correct
72 Correct 8 ms 14420 KB Output is correct
73 Correct 8 ms 14420 KB Output is correct
74 Correct 8 ms 14420 KB Output is correct
75 Correct 7 ms 14420 KB Output is correct
76 Correct 8 ms 14476 KB Output is correct
77 Correct 8 ms 14400 KB Output is correct
78 Correct 8 ms 14428 KB Output is correct
79 Correct 670 ms 74420 KB Output is correct
80 Correct 2606 ms 69168 KB Output is correct
81 Correct 1171 ms 70756 KB Output is correct
82 Correct 3444 ms 56044 KB Output is correct
83 Correct 1984 ms 55792 KB Output is correct
84 Correct 1175 ms 55732 KB Output is correct
85 Correct 440 ms 55964 KB Output is correct
86 Correct 681 ms 68932 KB Output is correct
87 Correct 2340 ms 72428 KB Output is correct
88 Correct 1451 ms 56476 KB Output is correct
89 Execution timed out 4080 ms 55520 KB Time limit exceeded
90 Halted 0 ms 0 KB -