답안 #776501

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
776501 2023-07-08T02:49:28 Z marvinthang Sprinkler (JOI22_sprinkler) C++17
100 / 100
635 ms 62668 KB
/*************************************
*    author: marvinthang             *
*    created: 08.07.2023 09:40:27    *
*************************************/

#include <bits/stdc++.h>

using namespace std;

#define                  fi  first
#define                  se  second
#define                left  ___left
#define               right  ___right
#define                TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define             MASK(i)  (1LL << (i))
#define           BIT(x, i)  ((x) >> (i) & 1)
#define  __builtin_popcount  __builtin_popcountll
#define              ALL(v)  (v).begin(), (v).end()
#define           REP(i, n)  for (int i = 0, _n = (n); i < _n; ++i)
#define          REPD(i, n)  for (int i = (n); i--; )
#define        FOR(i, a, b)  for (int i = (a), _b = (b); i < _b; ++i) 
#define       FORD(i, b, a)  for (int i = (b), _a = (a); --i >= _a; ) 
#define       FORE(i, a, b)  for (int i = (a), _b = (b); i <= _b; ++i) 
#define      FORDE(i, b, a)  for (int i = (b), _a = (a); i >= _a; --i) 
#define        scan_op(...)  istream & operator >> (istream &in, __VA_ARGS__ &u)
#define       print_op(...)  ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#ifdef LOCAL
    #include "debug.h"
#else
    #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
    #define DB(...) 23
    #define db(...) 23
    #define debug(...) 23
#endif

template <class U, class V> scan_op(pair <U, V>)  { return in >> u.first >> u.second; }
template <class T> scan_op(vector <T>)  { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> print_op(pair <U, V>)  { return out << '(' << u.first << ", " << u.second << ')'; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")";  else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }

// end of template

const int MAX = 2e5 + 5;
const int MAXD = 41;

int N, Q, L, H[MAX];
vector <int> adj[MAX];

void init(void) {
	cin >> N >> L;
	FOR(i, 1, N) {
		int u, v; cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	FORE(i, 1, N) cin >> H[i];
	cin >> Q;
}

int par[MAX];

void dfs(int u) {
	for (int v: adj[u]) if (v != par[u]) {
		par[v] = u;
		dfs(v);
	}
}

int mul[MAX][MAXD];

void __mul(int &a, int b) {
	a = 1LL * a * b % L;
}

void process(void) {
	FORE(i, 1, N) REP(d, MAXD) mul[i][d] = 1;
	dfs(1);
	while (Q--) {
		int op, x;
		cin >> op >> x;
		if (op == 1) {
			int d, w; cin >> d >> w;
			while (d && x != 1) {
				__mul(mul[x][d], w);
				__mul(mul[x][d - 1], w);
				--d;
				x = par[x];
			}
			REPD(i, d + 1) __mul(mul[x][i], w);
		} else {
			int res = H[x];
			REP(i, MAXD) {
				__mul(res, mul[x][i]);
				x = par[x];
				if (!x) break;
			}
			cout << res << '\n';
		}
	}
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); // cout.tie(nullptr);
	file("sprinkler");
	init();
	process();
	cerr << "Time elapsed: " << TIME << " s.\n";
	return (0^0);
}

Compilation message

sprinkler.cpp: In function 'int main()':
sprinkler.cpp:30:61: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:106:2: note: in expansion of macro 'file'
  106 |  file("sprinkler");
      |  ^~~~
sprinkler.cpp:30:94: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:106:2: note: in expansion of macro 'file'
  106 |  file("sprinkler");
      |  ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 5032 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 3 ms 5204 KB Output is correct
6 Correct 3 ms 5204 KB Output is correct
7 Correct 3 ms 5180 KB Output is correct
8 Correct 3 ms 5204 KB Output is correct
9 Correct 4 ms 5052 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 5048 KB Output is correct
13 Correct 2 ms 5044 KB Output is correct
14 Correct 2 ms 5052 KB Output is correct
15 Correct 2 ms 5000 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5052 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 5044 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 5040 KB Output is correct
25 Correct 3 ms 5048 KB Output is correct
26 Correct 4 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 2 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5036 KB Output is correct
2 Correct 456 ms 56752 KB Output is correct
3 Correct 282 ms 57244 KB Output is correct
4 Correct 393 ms 60796 KB Output is correct
5 Correct 338 ms 57064 KB Output is correct
6 Correct 279 ms 56640 KB Output is correct
7 Correct 262 ms 57492 KB Output is correct
8 Correct 210 ms 57748 KB Output is correct
9 Correct 495 ms 62528 KB Output is correct
10 Correct 282 ms 62584 KB Output is correct
11 Correct 409 ms 56792 KB Output is correct
12 Correct 276 ms 57296 KB Output is correct
13 Correct 217 ms 57516 KB Output is correct
14 Correct 179 ms 58028 KB Output is correct
15 Correct 178 ms 57336 KB Output is correct
16 Correct 217 ms 57936 KB Output is correct
17 Correct 190 ms 58316 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5036 KB Output is correct
2 Correct 456 ms 56752 KB Output is correct
3 Correct 282 ms 57244 KB Output is correct
4 Correct 393 ms 60796 KB Output is correct
5 Correct 338 ms 57064 KB Output is correct
6 Correct 279 ms 56640 KB Output is correct
7 Correct 262 ms 57492 KB Output is correct
8 Correct 210 ms 57748 KB Output is correct
9 Correct 495 ms 62528 KB Output is correct
10 Correct 282 ms 62584 KB Output is correct
11 Correct 409 ms 56792 KB Output is correct
12 Correct 276 ms 57296 KB Output is correct
13 Correct 217 ms 57516 KB Output is correct
14 Correct 179 ms 58028 KB Output is correct
15 Correct 178 ms 57336 KB Output is correct
16 Correct 217 ms 57936 KB Output is correct
17 Correct 190 ms 58316 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 401 ms 56776 KB Output is correct
25 Correct 258 ms 57344 KB Output is correct
26 Correct 424 ms 62664 KB Output is correct
27 Correct 377 ms 56900 KB Output is correct
28 Correct 262 ms 57232 KB Output is correct
29 Correct 260 ms 56812 KB Output is correct
30 Correct 209 ms 57840 KB Output is correct
31 Correct 503 ms 60924 KB Output is correct
32 Correct 294 ms 62644 KB Output is correct
33 Correct 407 ms 56700 KB Output is correct
34 Correct 262 ms 57304 KB Output is correct
35 Correct 2 ms 4948 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 2 ms 4948 KB Output is correct
38 Correct 2 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 3 ms 4948 KB Output is correct
41 Correct 5 ms 4948 KB Output is correct
42 Correct 2 ms 4948 KB Output is correct
43 Correct 2 ms 4948 KB Output is correct
44 Correct 2 ms 4948 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 5044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 543 ms 59732 KB Output is correct
3 Correct 597 ms 59052 KB Output is correct
4 Correct 491 ms 58840 KB Output is correct
5 Correct 374 ms 54092 KB Output is correct
6 Correct 274 ms 54220 KB Output is correct
7 Correct 266 ms 54344 KB Output is correct
8 Correct 209 ms 54836 KB Output is correct
9 Correct 523 ms 57956 KB Output is correct
10 Correct 593 ms 59808 KB Output is correct
11 Correct 452 ms 53652 KB Output is correct
12 Correct 437 ms 54512 KB Output is correct
13 Correct 346 ms 55500 KB Output is correct
14 Correct 325 ms 55900 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 544 ms 60380 KB Output is correct
3 Correct 635 ms 58136 KB Output is correct
4 Correct 473 ms 59080 KB Output is correct
5 Correct 373 ms 55684 KB Output is correct
6 Correct 288 ms 55788 KB Output is correct
7 Correct 263 ms 55528 KB Output is correct
8 Correct 208 ms 55872 KB Output is correct
9 Correct 550 ms 61964 KB Output is correct
10 Correct 597 ms 60588 KB Output is correct
11 Correct 424 ms 56420 KB Output is correct
12 Correct 441 ms 54860 KB Output is correct
13 Correct 357 ms 55660 KB Output is correct
14 Correct 334 ms 56148 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 5044 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5044 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 5032 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 3 ms 5204 KB Output is correct
6 Correct 3 ms 5204 KB Output is correct
7 Correct 3 ms 5180 KB Output is correct
8 Correct 3 ms 5204 KB Output is correct
9 Correct 4 ms 5052 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 5048 KB Output is correct
13 Correct 2 ms 5044 KB Output is correct
14 Correct 2 ms 5052 KB Output is correct
15 Correct 2 ms 5000 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5052 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 5044 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 5040 KB Output is correct
25 Correct 3 ms 5048 KB Output is correct
26 Correct 4 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 2 ms 4948 KB Output is correct
29 Correct 3 ms 5036 KB Output is correct
30 Correct 456 ms 56752 KB Output is correct
31 Correct 282 ms 57244 KB Output is correct
32 Correct 393 ms 60796 KB Output is correct
33 Correct 338 ms 57064 KB Output is correct
34 Correct 279 ms 56640 KB Output is correct
35 Correct 262 ms 57492 KB Output is correct
36 Correct 210 ms 57748 KB Output is correct
37 Correct 495 ms 62528 KB Output is correct
38 Correct 282 ms 62584 KB Output is correct
39 Correct 409 ms 56792 KB Output is correct
40 Correct 276 ms 57296 KB Output is correct
41 Correct 217 ms 57516 KB Output is correct
42 Correct 179 ms 58028 KB Output is correct
43 Correct 178 ms 57336 KB Output is correct
44 Correct 217 ms 57936 KB Output is correct
45 Correct 190 ms 58316 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 2 ms 4948 KB Output is correct
49 Correct 2 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 401 ms 56776 KB Output is correct
53 Correct 258 ms 57344 KB Output is correct
54 Correct 424 ms 62664 KB Output is correct
55 Correct 377 ms 56900 KB Output is correct
56 Correct 262 ms 57232 KB Output is correct
57 Correct 260 ms 56812 KB Output is correct
58 Correct 209 ms 57840 KB Output is correct
59 Correct 503 ms 60924 KB Output is correct
60 Correct 294 ms 62644 KB Output is correct
61 Correct 407 ms 56700 KB Output is correct
62 Correct 262 ms 57304 KB Output is correct
63 Correct 2 ms 4948 KB Output is correct
64 Correct 3 ms 4948 KB Output is correct
65 Correct 2 ms 4948 KB Output is correct
66 Correct 2 ms 4948 KB Output is correct
67 Correct 3 ms 4948 KB Output is correct
68 Correct 3 ms 4948 KB Output is correct
69 Correct 5 ms 4948 KB Output is correct
70 Correct 2 ms 4948 KB Output is correct
71 Correct 2 ms 4948 KB Output is correct
72 Correct 2 ms 4948 KB Output is correct
73 Correct 3 ms 4948 KB Output is correct
74 Correct 3 ms 4948 KB Output is correct
75 Correct 3 ms 5076 KB Output is correct
76 Correct 3 ms 4948 KB Output is correct
77 Correct 3 ms 5044 KB Output is correct
78 Correct 3 ms 4948 KB Output is correct
79 Correct 543 ms 59732 KB Output is correct
80 Correct 597 ms 59052 KB Output is correct
81 Correct 491 ms 58840 KB Output is correct
82 Correct 374 ms 54092 KB Output is correct
83 Correct 274 ms 54220 KB Output is correct
84 Correct 266 ms 54344 KB Output is correct
85 Correct 209 ms 54836 KB Output is correct
86 Correct 523 ms 57956 KB Output is correct
87 Correct 593 ms 59808 KB Output is correct
88 Correct 452 ms 53652 KB Output is correct
89 Correct 437 ms 54512 KB Output is correct
90 Correct 346 ms 55500 KB Output is correct
91 Correct 325 ms 55900 KB Output is correct
92 Correct 2 ms 4948 KB Output is correct
93 Correct 2 ms 4948 KB Output is correct
94 Correct 3 ms 4948 KB Output is correct
95 Correct 3 ms 4948 KB Output is correct
96 Correct 2 ms 4948 KB Output is correct
97 Correct 2 ms 4948 KB Output is correct
98 Correct 544 ms 60380 KB Output is correct
99 Correct 635 ms 58136 KB Output is correct
100 Correct 473 ms 59080 KB Output is correct
101 Correct 373 ms 55684 KB Output is correct
102 Correct 288 ms 55788 KB Output is correct
103 Correct 263 ms 55528 KB Output is correct
104 Correct 208 ms 55872 KB Output is correct
105 Correct 550 ms 61964 KB Output is correct
106 Correct 597 ms 60588 KB Output is correct
107 Correct 424 ms 56420 KB Output is correct
108 Correct 441 ms 54860 KB Output is correct
109 Correct 357 ms 55660 KB Output is correct
110 Correct 334 ms 56148 KB Output is correct
111 Correct 2 ms 4948 KB Output is correct
112 Correct 2 ms 5044 KB Output is correct
113 Correct 3 ms 4948 KB Output is correct
114 Correct 3 ms 5044 KB Output is correct
115 Correct 2 ms 4948 KB Output is correct
116 Correct 420 ms 54868 KB Output is correct
117 Correct 513 ms 57348 KB Output is correct
118 Correct 471 ms 62668 KB Output is correct
119 Correct 406 ms 57036 KB Output is correct
120 Correct 321 ms 56696 KB Output is correct
121 Correct 337 ms 57440 KB Output is correct
122 Correct 234 ms 57816 KB Output is correct
123 Correct 542 ms 61512 KB Output is correct
124 Correct 626 ms 60640 KB Output is correct
125 Correct 438 ms 55952 KB Output is correct
126 Correct 486 ms 57324 KB Output is correct
127 Correct 514 ms 57864 KB Output is correct
128 Correct 438 ms 58444 KB Output is correct
129 Correct 450 ms 58972 KB Output is correct