Submission #854363

# Submission time Handle Problem Language Result Execution time Memory
854363 2023-09-27T06:02:04 Z MilosMilutinovic Sprinkler (JOI22_sprinkler) C++14
100 / 100
651 ms 68144 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> B;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=200200;
int n,q,l,f[N][45],h[N],p[N];
VI g[N];

int ckmul(int a,int b) { return ((ll)a*b)%l; }

void dfs(int x,int pv) {
	p[x]=pv;
	rep(i,0,42) f[x][i]=1;
	for (int y:g[x]) if (y!=pv) dfs(y,x);
}

void add(int x,int d,int w) {
	per(i,0,d+1) {
		f[x][i]=ckmul(f[x][i],w);
		if (i>0&&x!=1) f[x][i-1]=ckmul(f[x][i-1],w);
		x=p[x];
	}
}

int solve(int x) {
	int r=1;
	rep(i,0,42) {
		r=ckmul(r,f[x][i]);
		if (x==1) break;
		x=p[x];
	}
	return r;
}

int main() {
	scanf("%d%d",&n,&l);
	rep(i,1,n) {
		int a,b;
		scanf("%d%d",&a,&b);
		g[a].pb(b); g[b].pb(a);
	}
	rep(i,1,n+1) scanf("%d",&h[i]);
	dfs(1,1);
	rep(i,1,n+1) add(i,0,h[i]);
	scanf("%d",&q);
	while (q--) {
		int op;
		scanf("%d",&op);
		if (op==1) {
			int x,d,w;
			scanf("%d%d%d",&x,&d,&w);
			add(x,d,w);
		} else {
			int x;
			scanf("%d",&x);
			printf("%d\n",solve(x));
		}
	}
}

Compilation message

sprinkler.cpp: In function 'int main()':
sprinkler.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |  scanf("%d%d",&n,&l);
      |  ~~~~~^~~~~~~~~~~~~~
sprinkler.cpp:58:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |   scanf("%d%d",&a,&b);
      |   ~~~~~^~~~~~~~~~~~~~
sprinkler.cpp:61:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |  rep(i,1,n+1) scanf("%d",&h[i]);
      |               ~~~~~^~~~~~~~~~~~
sprinkler.cpp:64:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |  scanf("%d",&q);
      |  ~~~~~^~~~~~~~~
sprinkler.cpp:67:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |   scanf("%d",&op);
      |   ~~~~~^~~~~~~~~~
sprinkler.cpp:70:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |    scanf("%d%d%d",&x,&d,&w);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~
sprinkler.cpp:74:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |    scanf("%d",&x);
      |    ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 7000 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8900 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 6744 KB Output is correct
10 Correct 1 ms 6744 KB Output is correct
11 Correct 2 ms 6792 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 2 ms 7024 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 1 ms 7000 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 1 ms 6748 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6748 KB Output is correct
25 Correct 2 ms 7156 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 2 ms 6748 KB Output is correct
28 Correct 2 ms 6744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 401 ms 59704 KB Output is correct
3 Correct 281 ms 59220 KB Output is correct
4 Correct 414 ms 65020 KB Output is correct
5 Correct 339 ms 59476 KB Output is correct
6 Correct 288 ms 58904 KB Output is correct
7 Correct 272 ms 59732 KB Output is correct
8 Correct 232 ms 60256 KB Output is correct
9 Correct 497 ms 68144 KB Output is correct
10 Correct 299 ms 67668 KB Output is correct
11 Correct 385 ms 59364 KB Output is correct
12 Correct 284 ms 59220 KB Output is correct
13 Correct 207 ms 59960 KB Output is correct
14 Correct 211 ms 59848 KB Output is correct
15 Correct 211 ms 59732 KB Output is correct
16 Correct 222 ms 59788 KB Output is correct
17 Correct 231 ms 60500 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 401 ms 59704 KB Output is correct
3 Correct 281 ms 59220 KB Output is correct
4 Correct 414 ms 65020 KB Output is correct
5 Correct 339 ms 59476 KB Output is correct
6 Correct 288 ms 58904 KB Output is correct
7 Correct 272 ms 59732 KB Output is correct
8 Correct 232 ms 60256 KB Output is correct
9 Correct 497 ms 68144 KB Output is correct
10 Correct 299 ms 67668 KB Output is correct
11 Correct 385 ms 59364 KB Output is correct
12 Correct 284 ms 59220 KB Output is correct
13 Correct 207 ms 59960 KB Output is correct
14 Correct 211 ms 59848 KB Output is correct
15 Correct 211 ms 59732 KB Output is correct
16 Correct 222 ms 59788 KB Output is correct
17 Correct 231 ms 60500 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 389 ms 59512 KB Output is correct
25 Correct 301 ms 59328 KB Output is correct
26 Correct 414 ms 67868 KB Output is correct
27 Correct 344 ms 59648 KB Output is correct
28 Correct 279 ms 59472 KB Output is correct
29 Correct 271 ms 59472 KB Output is correct
30 Correct 227 ms 60128 KB Output is correct
31 Correct 507 ms 65632 KB Output is correct
32 Correct 304 ms 67484 KB Output is correct
33 Correct 392 ms 59940 KB Output is correct
34 Correct 294 ms 59220 KB Output is correct
35 Correct 2 ms 6744 KB Output is correct
36 Correct 2 ms 7004 KB Output is correct
37 Correct 2 ms 6748 KB Output is correct
38 Correct 2 ms 6784 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 1 ms 6744 KB Output is correct
41 Correct 1 ms 6748 KB Output is correct
42 Correct 1 ms 6748 KB Output is correct
43 Correct 1 ms 6748 KB Output is correct
44 Correct 1 ms 6748 KB Output is correct
45 Correct 2 ms 6744 KB Output is correct
46 Correct 2 ms 6748 KB Output is correct
47 Correct 1 ms 6748 KB Output is correct
48 Correct 1 ms 6748 KB Output is correct
49 Correct 2 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 530 ms 65504 KB Output is correct
3 Correct 641 ms 64072 KB Output is correct
4 Correct 520 ms 63732 KB Output is correct
5 Correct 395 ms 56420 KB Output is correct
6 Correct 326 ms 56660 KB Output is correct
7 Correct 296 ms 56688 KB Output is correct
8 Correct 233 ms 57364 KB Output is correct
9 Correct 535 ms 62548 KB Output is correct
10 Correct 630 ms 65224 KB Output is correct
11 Correct 405 ms 56324 KB Output is correct
12 Correct 413 ms 57464 KB Output is correct
13 Correct 362 ms 58136 KB Output is correct
14 Correct 357 ms 58448 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 6744 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6944 KB Output is correct
2 Correct 568 ms 62016 KB Output is correct
3 Correct 630 ms 62164 KB Output is correct
4 Correct 479 ms 63556 KB Output is correct
5 Correct 374 ms 58192 KB Output is correct
6 Correct 335 ms 58632 KB Output is correct
7 Correct 307 ms 58192 KB Output is correct
8 Correct 244 ms 58408 KB Output is correct
9 Correct 530 ms 67276 KB Output is correct
10 Correct 651 ms 65688 KB Output is correct
11 Correct 411 ms 58820 KB Output is correct
12 Correct 413 ms 57556 KB Output is correct
13 Correct 379 ms 58328 KB Output is correct
14 Correct 371 ms 58708 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 7000 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8900 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 6744 KB Output is correct
10 Correct 1 ms 6744 KB Output is correct
11 Correct 2 ms 6792 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 2 ms 7024 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 1 ms 7000 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 1 ms 6748 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6748 KB Output is correct
25 Correct 2 ms 7156 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 2 ms 6748 KB Output is correct
28 Correct 2 ms 6744 KB Output is correct
29 Correct 1 ms 6748 KB Output is correct
30 Correct 401 ms 59704 KB Output is correct
31 Correct 281 ms 59220 KB Output is correct
32 Correct 414 ms 65020 KB Output is correct
33 Correct 339 ms 59476 KB Output is correct
34 Correct 288 ms 58904 KB Output is correct
35 Correct 272 ms 59732 KB Output is correct
36 Correct 232 ms 60256 KB Output is correct
37 Correct 497 ms 68144 KB Output is correct
38 Correct 299 ms 67668 KB Output is correct
39 Correct 385 ms 59364 KB Output is correct
40 Correct 284 ms 59220 KB Output is correct
41 Correct 207 ms 59960 KB Output is correct
42 Correct 211 ms 59848 KB Output is correct
43 Correct 211 ms 59732 KB Output is correct
44 Correct 222 ms 59788 KB Output is correct
45 Correct 231 ms 60500 KB Output is correct
46 Correct 2 ms 6748 KB Output is correct
47 Correct 1 ms 6748 KB Output is correct
48 Correct 2 ms 6748 KB Output is correct
49 Correct 2 ms 6748 KB Output is correct
50 Correct 2 ms 6748 KB Output is correct
51 Correct 1 ms 6748 KB Output is correct
52 Correct 389 ms 59512 KB Output is correct
53 Correct 301 ms 59328 KB Output is correct
54 Correct 414 ms 67868 KB Output is correct
55 Correct 344 ms 59648 KB Output is correct
56 Correct 279 ms 59472 KB Output is correct
57 Correct 271 ms 59472 KB Output is correct
58 Correct 227 ms 60128 KB Output is correct
59 Correct 507 ms 65632 KB Output is correct
60 Correct 304 ms 67484 KB Output is correct
61 Correct 392 ms 59940 KB Output is correct
62 Correct 294 ms 59220 KB Output is correct
63 Correct 2 ms 6744 KB Output is correct
64 Correct 2 ms 7004 KB Output is correct
65 Correct 2 ms 6748 KB Output is correct
66 Correct 2 ms 6784 KB Output is correct
67 Correct 2 ms 6748 KB Output is correct
68 Correct 1 ms 6744 KB Output is correct
69 Correct 1 ms 6748 KB Output is correct
70 Correct 1 ms 6748 KB Output is correct
71 Correct 1 ms 6748 KB Output is correct
72 Correct 1 ms 6748 KB Output is correct
73 Correct 2 ms 6744 KB Output is correct
74 Correct 2 ms 6748 KB Output is correct
75 Correct 1 ms 6748 KB Output is correct
76 Correct 1 ms 6748 KB Output is correct
77 Correct 2 ms 6748 KB Output is correct
78 Correct 2 ms 6748 KB Output is correct
79 Correct 530 ms 65504 KB Output is correct
80 Correct 641 ms 64072 KB Output is correct
81 Correct 520 ms 63732 KB Output is correct
82 Correct 395 ms 56420 KB Output is correct
83 Correct 326 ms 56660 KB Output is correct
84 Correct 296 ms 56688 KB Output is correct
85 Correct 233 ms 57364 KB Output is correct
86 Correct 535 ms 62548 KB Output is correct
87 Correct 630 ms 65224 KB Output is correct
88 Correct 405 ms 56324 KB Output is correct
89 Correct 413 ms 57464 KB Output is correct
90 Correct 362 ms 58136 KB Output is correct
91 Correct 357 ms 58448 KB Output is correct
92 Correct 2 ms 6748 KB Output is correct
93 Correct 2 ms 6748 KB Output is correct
94 Correct 2 ms 6744 KB Output is correct
95 Correct 2 ms 6748 KB Output is correct
96 Correct 2 ms 6748 KB Output is correct
97 Correct 1 ms 6944 KB Output is correct
98 Correct 568 ms 62016 KB Output is correct
99 Correct 630 ms 62164 KB Output is correct
100 Correct 479 ms 63556 KB Output is correct
101 Correct 374 ms 58192 KB Output is correct
102 Correct 335 ms 58632 KB Output is correct
103 Correct 307 ms 58192 KB Output is correct
104 Correct 244 ms 58408 KB Output is correct
105 Correct 530 ms 67276 KB Output is correct
106 Correct 651 ms 65688 KB Output is correct
107 Correct 411 ms 58820 KB Output is correct
108 Correct 413 ms 57556 KB Output is correct
109 Correct 379 ms 58328 KB Output is correct
110 Correct 371 ms 58708 KB Output is correct
111 Correct 2 ms 6748 KB Output is correct
112 Correct 1 ms 6748 KB Output is correct
113 Correct 2 ms 6748 KB Output is correct
114 Correct 2 ms 6748 KB Output is correct
115 Correct 1 ms 6748 KB Output is correct
116 Correct 412 ms 57424 KB Output is correct
117 Correct 474 ms 59244 KB Output is correct
118 Correct 501 ms 66480 KB Output is correct
119 Correct 396 ms 58036 KB Output is correct
120 Correct 337 ms 57684 KB Output is correct
121 Correct 329 ms 58448 KB Output is correct
122 Correct 253 ms 58844 KB Output is correct
123 Correct 555 ms 65884 KB Output is correct
124 Correct 628 ms 63128 KB Output is correct
125 Correct 407 ms 57448 KB Output is correct
126 Correct 503 ms 57752 KB Output is correct
127 Correct 520 ms 58060 KB Output is correct
128 Correct 469 ms 58964 KB Output is correct
129 Correct 480 ms 59472 KB Output is correct