Submission #633899

# Submission time Handle Problem Language Result Execution time Memory
633899 2022-08-23T12:10:33 Z IWTIM Sprinkler (JOI22_sprinkler) C++14
100 / 100
829 ms 190516 KB
# include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = long double; // or double, if TL is tight
using str = string; // yay python! 
 
// pairs
using pii = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;
#define mp make_pair
#define f first
#define s second
 
#define tcT template<class T
#define tcTU tcT, class U
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>; 
tcT, size_t SZ> using AR = array<T,SZ>; 
using vi = V<int>;
using vb = V<bool>;
using vl = V<ll>;
using vd = V<db>;
using vs = V<str>;
using vpi = V<pii>;
using vpl = V<pl>;
using vpd = V<pd>;
 
// vectors
// oops size(x), rbegin(x), rend(x) need C++17
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend() 
#define sor(x) sort(all(x)) 
#define rsz resize
#define ins insert 
#define pb push_back
#define eb emplace_back
#define ft front()
#define bk back()
 
#define lb lower_bound
#define ub upper_bound
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define rep(a) F0R(_,a)
#define each(a,x) for (auto& a: x)
const int MOD = 998244353;
const int MX = 2e5+5;
const ll BIG = 1e18; // not too close to LLONG_MAX
const db PI = acos((db)-1);
const int dx[4]{1,0,-1,0}, dy[4]{0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;
struct DSU {
	vi e; void init(int N) { e = vi(N,-1); }
	int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); } 
	bool sameSet(int a, int b) { return get(a) == get(b); }
	int size(int x) { return -e[get(x)]; }
	bool unite(int x, int y) { // union by size
		x = get(x), y = get(y); if (x == y) return 0;
		if (e[x] > e[y]) swap(x,y);
		e[x] += e[y]; e[y] = x; return 1;
	}
};
/*
inline namespace Helpers {
	//////////// is_iterable
	// https://stackoverflow.com/questions/13830158/check-if-a-variable-type-is-iterable
	// this gets used only when we can call begin() and end() on that type
	tcT, class = void> struct is_iterable : false_type {};
	tcT> struct is_iterable<T, void_t<decltype(begin(declval<T>())),
	                                  decltype(end(declval<T>()))
	                                 >
	                       > : true_type {};
	tcT> constexpr bool is_iterable_v = is_iterable<T>::value;
 
	//////////// is_readable
	tcT, class = void> struct is_readable : false_type {};
	tcT> struct is_readable<T,
	        typename std::enable_if_t<
	            is_same_v<decltype(cin >> declval<T&>()), istream&>
	        >
	    > : true_type {};
	tcT> constexpr bool is_readable_v = is_readable<T>::value;
 
	//////////// is_printable
	// // https://nafe.es/posts/2020-02-29-is-printable/
	tcT, class = void> struct is_printable : false_type {};
	tcT> struct is_printable<T,
	        typename std::enable_if_t<
	            is_same_v<decltype(cout << declval<T>()), ostream&>
	        >
	    > : true_type {};
	tcT> constexpr bool is_printable_v = is_printable<T>::value;
}*/
using ll = long long;
using db = long double; // or double, if TL is tight
using str = string; // yay python! 
 
// pairs
using pii = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;
#define mp make_pair
#define f first
#define s second
 
#define tcT template<class T
#define tcTU tcT, class U
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>; 
tcT, size_t SZ> using AR = array<T,SZ>; 
using vi = V<int>;
using vb = V<bool>;
using vl = V<ll>;
using vd = V<db>;
using vs = V<str>;
using vpi = V<pii>;
using vpl = V<pl>;
using vpd = V<pd>;
 
// vectors
// oops size(x), rbegin(x), rend(x) need C++17
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend() 
#define sor(x) sort(all(x)) 
#define rsz resize
#define ins insert 
#define pb push_back
#define eb emplace_back
#define ft front()
#define bk back()
 
#define lb lower_bound
#define ub upper_bound
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define rep(a) F0R(_,a)
#define each(a,x) for (auto& a: x)
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;
 
/*
inline namespace Helpers {
	//////////// is_iterable
	// https://stackoverflow.com/questions/13830158/check-if-a-variable-type-is-iterable
	// this gets used only when we can call begin() and end() on that type
	tcT, class = void> struct is_iterable : false_type {};
	tcT> struct is_iterable<T, void_t<decltype(begin(declval<T>())),
	                                  decltype(end(declval<T>()))
	                                 >
	                       > : true_type {};
	tcT> constexpr bool is_iterable_v = is_iterable<T>::value;
 
	//////////// is_readable
	tcT, class = void> struct is_readable : false_type {};
	tcT> struct is_readable<T,
	        typename std::enable_if_t<
	            is_same_v<decltype(cin >> declval<T&>()), istream&>
	        >
	    > : true_type {};
	tcT> constexpr bool is_readable_v = is_readable<T>::value;
 
	//////////// is_printable
	// // https://nafe.es/posts/2020-02-29-is-printable/
	tcT, class = void> struct is_printable : false_type {};
	tcT> struct is_printable<T,
	        typename std::enable_if_t<
	            is_same_v<decltype(cout << declval<T>()), ostream&>
	        >
	    > : true_type {};
	tcT> constexpr bool is_printable_v = is_printable<T>::value;
}*/
#define int long long
#define pii pair <int, int>
const int N = 3e5 + 5;
int t,n,a[N], par[N],h[N],mul[N][100],mod;
vector <int> v[N];
void dfs(int a, int p) {
	par[a] = p;
	for (int to : v[a]) {
		if (to == p) continue;
		dfs(to,a);
	}
}
main() {
    std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>n>>mod;
    for (int i = 1; i <= n - 1; i++) {
    	int a, b;
    	cin>>a>>b;
    	v[a].pb(b);
    	v[b].pb(a);
	}
	for (int i = 1; i <= n; i++) {
		cin>>h[i];
		for (int j = 0; j <= 40; j++) mul[i][j] = 1;
	}
	dfs(1,0);
	int q;
	cin>>q;
	while (q--) {
		int ty;
		cin>>ty;
		if (ty == 1) {
			int vert, d, mult;
			cin>>vert>>d>>mult;
			while (d >= 0 && vert != 0) {
				mul[vert][d] = (mul[vert][d] * mult) % mod;
				d--; 
				vert = par[vert];
			}
		}
		else {
			int vert;
			cin>>vert;
			int cur = h[vert]; int curver = vert;
			for (int i = 0; i <= 40; i++) {
				cur = (cur * mul[curver][i])%mod; if (i < 40) cur = (cur * mul[curver][i + 1]) % mod;
				curver = par[curver];
				if (curver == 0) { 
					for (int j = i + 2; j <= 40; j++) cur = (mul[1][j] * cur) % mod;
					break;
				}
			}
			cout<<cur<<"\n";
		}
	}
}

Compilation message

sprinkler.cpp:193:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  193 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7284 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 5 ms 8148 KB Output is correct
5 Correct 5 ms 8276 KB Output is correct
6 Correct 5 ms 8164 KB Output is correct
7 Correct 5 ms 8160 KB Output is correct
8 Correct 5 ms 8276 KB Output is correct
9 Correct 4 ms 7396 KB Output is correct
10 Correct 5 ms 7380 KB Output is correct
11 Correct 5 ms 7516 KB Output is correct
12 Correct 5 ms 7380 KB Output is correct
13 Correct 5 ms 7388 KB Output is correct
14 Correct 5 ms 7380 KB Output is correct
15 Correct 4 ms 7396 KB Output is correct
16 Correct 4 ms 7380 KB Output is correct
17 Correct 4 ms 7392 KB Output is correct
18 Correct 4 ms 7380 KB Output is correct
19 Correct 4 ms 7380 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 4 ms 7380 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
23 Correct 4 ms 7388 KB Output is correct
24 Correct 5 ms 7388 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct
26 Correct 4 ms 7380 KB Output is correct
27 Correct 4 ms 7476 KB Output is correct
28 Correct 4 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7320 KB Output is correct
2 Correct 651 ms 177956 KB Output is correct
3 Correct 420 ms 186668 KB Output is correct
4 Correct 580 ms 188752 KB Output is correct
5 Correct 515 ms 186444 KB Output is correct
6 Correct 471 ms 186028 KB Output is correct
7 Correct 416 ms 186952 KB Output is correct
8 Correct 342 ms 187076 KB Output is correct
9 Correct 778 ms 190388 KB Output is correct
10 Correct 464 ms 190376 KB Output is correct
11 Correct 672 ms 186060 KB Output is correct
12 Correct 401 ms 186620 KB Output is correct
13 Correct 299 ms 186708 KB Output is correct
14 Correct 280 ms 187164 KB Output is correct
15 Correct 308 ms 186392 KB Output is correct
16 Correct 291 ms 187000 KB Output is correct
17 Correct 297 ms 187704 KB Output is correct
18 Correct 4 ms 7388 KB Output is correct
19 Correct 5 ms 7364 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 5 ms 7396 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7320 KB Output is correct
2 Correct 651 ms 177956 KB Output is correct
3 Correct 420 ms 186668 KB Output is correct
4 Correct 580 ms 188752 KB Output is correct
5 Correct 515 ms 186444 KB Output is correct
6 Correct 471 ms 186028 KB Output is correct
7 Correct 416 ms 186952 KB Output is correct
8 Correct 342 ms 187076 KB Output is correct
9 Correct 778 ms 190388 KB Output is correct
10 Correct 464 ms 190376 KB Output is correct
11 Correct 672 ms 186060 KB Output is correct
12 Correct 401 ms 186620 KB Output is correct
13 Correct 299 ms 186708 KB Output is correct
14 Correct 280 ms 187164 KB Output is correct
15 Correct 308 ms 186392 KB Output is correct
16 Correct 291 ms 187000 KB Output is correct
17 Correct 297 ms 187704 KB Output is correct
18 Correct 4 ms 7388 KB Output is correct
19 Correct 5 ms 7364 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 5 ms 7396 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
23 Correct 4 ms 7384 KB Output is correct
24 Correct 650 ms 186120 KB Output is correct
25 Correct 435 ms 186832 KB Output is correct
26 Correct 559 ms 190500 KB Output is correct
27 Correct 560 ms 186412 KB Output is correct
28 Correct 423 ms 186592 KB Output is correct
29 Correct 377 ms 186316 KB Output is correct
30 Correct 354 ms 187192 KB Output is correct
31 Correct 730 ms 188876 KB Output is correct
32 Correct 455 ms 190516 KB Output is correct
33 Correct 829 ms 186152 KB Output is correct
34 Correct 407 ms 186680 KB Output is correct
35 Correct 4 ms 7380 KB Output is correct
36 Correct 4 ms 7380 KB Output is correct
37 Correct 4 ms 7380 KB Output is correct
38 Correct 5 ms 7400 KB Output is correct
39 Correct 5 ms 7380 KB Output is correct
40 Correct 4 ms 7380 KB Output is correct
41 Correct 5 ms 7508 KB Output is correct
42 Correct 6 ms 7420 KB Output is correct
43 Correct 4 ms 7380 KB Output is correct
44 Correct 4 ms 7380 KB Output is correct
45 Correct 5 ms 7316 KB Output is correct
46 Correct 4 ms 7384 KB Output is correct
47 Correct 4 ms 7380 KB Output is correct
48 Correct 4 ms 7380 KB Output is correct
49 Correct 4 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 788 ms 179620 KB Output is correct
3 Correct 686 ms 177504 KB Output is correct
4 Correct 726 ms 178060 KB Output is correct
5 Correct 553 ms 174680 KB Output is correct
6 Correct 406 ms 174920 KB Output is correct
7 Correct 397 ms 175152 KB Output is correct
8 Correct 311 ms 175208 KB Output is correct
9 Correct 771 ms 177968 KB Output is correct
10 Correct 698 ms 178492 KB Output is correct
11 Correct 654 ms 175368 KB Output is correct
12 Correct 662 ms 174412 KB Output is correct
13 Correct 422 ms 175232 KB Output is correct
14 Correct 459 ms 176248 KB Output is correct
15 Correct 5 ms 7380 KB Output is correct
16 Correct 4 ms 7380 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 4 ms 7380 KB Output is correct
19 Correct 4 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 736 ms 180480 KB Output is correct
3 Correct 729 ms 186044 KB Output is correct
4 Correct 633 ms 187084 KB Output is correct
5 Correct 593 ms 184968 KB Output is correct
6 Correct 463 ms 185164 KB Output is correct
7 Correct 440 ms 185072 KB Output is correct
8 Correct 341 ms 185064 KB Output is correct
9 Correct 715 ms 189660 KB Output is correct
10 Correct 726 ms 188256 KB Output is correct
11 Correct 651 ms 185692 KB Output is correct
12 Correct 665 ms 184316 KB Output is correct
13 Correct 467 ms 184956 KB Output is correct
14 Correct 467 ms 185888 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 4 ms 7392 KB Output is correct
17 Correct 5 ms 7380 KB Output is correct
18 Correct 4 ms 7384 KB Output is correct
19 Correct 4 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7284 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 5 ms 8148 KB Output is correct
5 Correct 5 ms 8276 KB Output is correct
6 Correct 5 ms 8164 KB Output is correct
7 Correct 5 ms 8160 KB Output is correct
8 Correct 5 ms 8276 KB Output is correct
9 Correct 4 ms 7396 KB Output is correct
10 Correct 5 ms 7380 KB Output is correct
11 Correct 5 ms 7516 KB Output is correct
12 Correct 5 ms 7380 KB Output is correct
13 Correct 5 ms 7388 KB Output is correct
14 Correct 5 ms 7380 KB Output is correct
15 Correct 4 ms 7396 KB Output is correct
16 Correct 4 ms 7380 KB Output is correct
17 Correct 4 ms 7392 KB Output is correct
18 Correct 4 ms 7380 KB Output is correct
19 Correct 4 ms 7380 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 4 ms 7380 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
23 Correct 4 ms 7388 KB Output is correct
24 Correct 5 ms 7388 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct
26 Correct 4 ms 7380 KB Output is correct
27 Correct 4 ms 7476 KB Output is correct
28 Correct 4 ms 7380 KB Output is correct
29 Correct 4 ms 7320 KB Output is correct
30 Correct 651 ms 177956 KB Output is correct
31 Correct 420 ms 186668 KB Output is correct
32 Correct 580 ms 188752 KB Output is correct
33 Correct 515 ms 186444 KB Output is correct
34 Correct 471 ms 186028 KB Output is correct
35 Correct 416 ms 186952 KB Output is correct
36 Correct 342 ms 187076 KB Output is correct
37 Correct 778 ms 190388 KB Output is correct
38 Correct 464 ms 190376 KB Output is correct
39 Correct 672 ms 186060 KB Output is correct
40 Correct 401 ms 186620 KB Output is correct
41 Correct 299 ms 186708 KB Output is correct
42 Correct 280 ms 187164 KB Output is correct
43 Correct 308 ms 186392 KB Output is correct
44 Correct 291 ms 187000 KB Output is correct
45 Correct 297 ms 187704 KB Output is correct
46 Correct 4 ms 7388 KB Output is correct
47 Correct 5 ms 7364 KB Output is correct
48 Correct 4 ms 7380 KB Output is correct
49 Correct 5 ms 7396 KB Output is correct
50 Correct 4 ms 7380 KB Output is correct
51 Correct 4 ms 7384 KB Output is correct
52 Correct 650 ms 186120 KB Output is correct
53 Correct 435 ms 186832 KB Output is correct
54 Correct 559 ms 190500 KB Output is correct
55 Correct 560 ms 186412 KB Output is correct
56 Correct 423 ms 186592 KB Output is correct
57 Correct 377 ms 186316 KB Output is correct
58 Correct 354 ms 187192 KB Output is correct
59 Correct 730 ms 188876 KB Output is correct
60 Correct 455 ms 190516 KB Output is correct
61 Correct 829 ms 186152 KB Output is correct
62 Correct 407 ms 186680 KB Output is correct
63 Correct 4 ms 7380 KB Output is correct
64 Correct 4 ms 7380 KB Output is correct
65 Correct 4 ms 7380 KB Output is correct
66 Correct 5 ms 7400 KB Output is correct
67 Correct 5 ms 7380 KB Output is correct
68 Correct 4 ms 7380 KB Output is correct
69 Correct 5 ms 7508 KB Output is correct
70 Correct 6 ms 7420 KB Output is correct
71 Correct 4 ms 7380 KB Output is correct
72 Correct 4 ms 7380 KB Output is correct
73 Correct 5 ms 7316 KB Output is correct
74 Correct 4 ms 7384 KB Output is correct
75 Correct 4 ms 7380 KB Output is correct
76 Correct 4 ms 7380 KB Output is correct
77 Correct 4 ms 7380 KB Output is correct
78 Correct 4 ms 7380 KB Output is correct
79 Correct 788 ms 179620 KB Output is correct
80 Correct 686 ms 177504 KB Output is correct
81 Correct 726 ms 178060 KB Output is correct
82 Correct 553 ms 174680 KB Output is correct
83 Correct 406 ms 174920 KB Output is correct
84 Correct 397 ms 175152 KB Output is correct
85 Correct 311 ms 175208 KB Output is correct
86 Correct 771 ms 177968 KB Output is correct
87 Correct 698 ms 178492 KB Output is correct
88 Correct 654 ms 175368 KB Output is correct
89 Correct 662 ms 174412 KB Output is correct
90 Correct 422 ms 175232 KB Output is correct
91 Correct 459 ms 176248 KB Output is correct
92 Correct 5 ms 7380 KB Output is correct
93 Correct 4 ms 7380 KB Output is correct
94 Correct 4 ms 7380 KB Output is correct
95 Correct 4 ms 7380 KB Output is correct
96 Correct 4 ms 7380 KB Output is correct
97 Correct 4 ms 7380 KB Output is correct
98 Correct 736 ms 180480 KB Output is correct
99 Correct 729 ms 186044 KB Output is correct
100 Correct 633 ms 187084 KB Output is correct
101 Correct 593 ms 184968 KB Output is correct
102 Correct 463 ms 185164 KB Output is correct
103 Correct 440 ms 185072 KB Output is correct
104 Correct 341 ms 185064 KB Output is correct
105 Correct 715 ms 189660 KB Output is correct
106 Correct 726 ms 188256 KB Output is correct
107 Correct 651 ms 185692 KB Output is correct
108 Correct 665 ms 184316 KB Output is correct
109 Correct 467 ms 184956 KB Output is correct
110 Correct 467 ms 185888 KB Output is correct
111 Correct 4 ms 7380 KB Output is correct
112 Correct 4 ms 7392 KB Output is correct
113 Correct 5 ms 7380 KB Output is correct
114 Correct 4 ms 7384 KB Output is correct
115 Correct 4 ms 7380 KB Output is correct
116 Correct 649 ms 184200 KB Output is correct
117 Correct 723 ms 186768 KB Output is correct
118 Correct 680 ms 190460 KB Output is correct
119 Correct 594 ms 186580 KB Output is correct
120 Correct 463 ms 186116 KB Output is correct
121 Correct 484 ms 186948 KB Output is correct
122 Correct 372 ms 187120 KB Output is correct
123 Correct 757 ms 189352 KB Output is correct
124 Correct 740 ms 188620 KB Output is correct
125 Correct 651 ms 185288 KB Output is correct
126 Correct 699 ms 186684 KB Output is correct
127 Correct 749 ms 187224 KB Output is correct
128 Correct 465 ms 187908 KB Output is correct
129 Correct 549 ms 188680 KB Output is correct