답안 #892512

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
892512 2023-12-25T13:00:25 Z vjudge1 Sprinkler (JOI22_sprinkler) C++17
100 / 100
614 ms 113524 KB
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define mpa make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define bc back()
#define ar array
#define vll vector<ll> 
using namespace std;/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;*/
template <class _T>
bool chmin(_T &x, const _T &y){
    if(x>y){
        x=y;
        return true;
    }
    return false;
}
template <class _T>
bool chmax(_T &x, const _T &y){
    bool flag=false;
    if (x<y){
        x=y;flag|=true;
    }
    return flag;
}
//#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll inf=2e18+7;
const ll mod=1e9+7;
const ll N=2e5+7;
const ld eps=1e-9;
vector<vll> g(N);
ll h[N];
ll i;
ll n,k,p[N];
ll val[N][50];
void dfs(ll v,ll p,ll w,ll d,ll r){
	h[v]*=w;
	h[v]%=k;
	if(d==r)return;
	for(auto i : g[v]){
		if(i==p)continue;
		dfs(i,v,w,d+1,r);
	}
}
void dfs2(ll v){
	for(auto i : g[v]){
		if(i==p[v])continue;
		p[i]=v;
		dfs2(i);
	}
}
void solve(){
	ll i,j,q;
	ll a,b,c;
	cin>>n>>k;
	for(i=0;i<=n;i++){
		for(j=0;j<=45;j++)val[i][j]=1;
	}
	for(i=1;i<n;i++){
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}
	for(i=1;i<=n;i++)cin>>h[i];
	dfs2(1);
	cin>>q;
	ll t;
	for(i=0;i<q;i++){
		cin>>t;
		if(t==1){
			cin>>a>>b>>c;
			while(p[a] && b){
				val[a][b]*=c;
				val[a][b-1]*=c;
				val[a][b]%=k;
				val[a][b-1]%=k;
				a=p[a];
				b--;
			}
			while(b){
				val[a][b]*=c;
				val[a][b]%=k;
				b--;
			}
			val[a][0]*=c;
			val[a][0]%=k;
		}else{
			cin>>a;
			ll ans=h[a]*val[a][0]%k;
			for(j=1;j<=40;j++){
				a=p[a];
				if(a==0)break;
				ans*=val[a][j];
				ans%=k;
			}
			cout<<ans<<endl;
		}
	}
}	
signed main(){
	start();
    ll t=1;
	//cin>>t;
    while(t--) solve();
    return 0;
}
/*
1
7
1 2
2 3
3 4
4 5
3 6
6 7
2
4 1
5 7






*/

Compilation message

sprinkler.cpp: In function 'void fre(std::string)':
sprinkler.cpp:43:27: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:43:64: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7000 KB Output is correct
2 Correct 2 ms 7004 KB Output is correct
3 Correct 2 ms 7004 KB Output is correct
4 Correct 3 ms 9308 KB Output is correct
5 Correct 4 ms 9308 KB Output is correct
6 Correct 3 ms 9516 KB Output is correct
7 Correct 4 ms 9308 KB Output is correct
8 Correct 3 ms 9308 KB Output is correct
9 Correct 2 ms 7004 KB Output is correct
10 Correct 2 ms 7004 KB Output is correct
11 Correct 2 ms 7004 KB Output is correct
12 Correct 2 ms 7004 KB Output is correct
13 Correct 2 ms 7004 KB Output is correct
14 Correct 2 ms 7004 KB Output is correct
15 Correct 2 ms 7004 KB Output is correct
16 Correct 2 ms 7004 KB Output is correct
17 Correct 2 ms 7004 KB Output is correct
18 Correct 2 ms 7004 KB Output is correct
19 Correct 2 ms 7004 KB Output is correct
20 Correct 2 ms 7004 KB Output is correct
21 Correct 2 ms 7004 KB Output is correct
22 Correct 2 ms 7004 KB Output is correct
23 Correct 2 ms 7004 KB Output is correct
24 Correct 2 ms 7004 KB Output is correct
25 Correct 2 ms 7004 KB Output is correct
26 Correct 2 ms 7004 KB Output is correct
27 Correct 2 ms 7000 KB Output is correct
28 Correct 2 ms 7004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7004 KB Output is correct
2 Correct 390 ms 97420 KB Output is correct
3 Correct 255 ms 94244 KB Output is correct
4 Correct 342 ms 100688 KB Output is correct
5 Correct 334 ms 95688 KB Output is correct
6 Correct 236 ms 95572 KB Output is correct
7 Correct 219 ms 95996 KB Output is correct
8 Correct 196 ms 96328 KB Output is correct
9 Correct 453 ms 105224 KB Output is correct
10 Correct 259 ms 101456 KB Output is correct
11 Correct 346 ms 97360 KB Output is correct
12 Correct 254 ms 106044 KB Output is correct
13 Correct 182 ms 106180 KB Output is correct
14 Correct 175 ms 106428 KB Output is correct
15 Correct 173 ms 105892 KB Output is correct
16 Correct 205 ms 106424 KB Output is correct
17 Correct 181 ms 106972 KB Output is correct
18 Correct 3 ms 7256 KB Output is correct
19 Correct 3 ms 7004 KB Output is correct
20 Correct 2 ms 7004 KB Output is correct
21 Correct 2 ms 7004 KB Output is correct
22 Correct 2 ms 7004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7004 KB Output is correct
2 Correct 390 ms 97420 KB Output is correct
3 Correct 255 ms 94244 KB Output is correct
4 Correct 342 ms 100688 KB Output is correct
5 Correct 334 ms 95688 KB Output is correct
6 Correct 236 ms 95572 KB Output is correct
7 Correct 219 ms 95996 KB Output is correct
8 Correct 196 ms 96328 KB Output is correct
9 Correct 453 ms 105224 KB Output is correct
10 Correct 259 ms 101456 KB Output is correct
11 Correct 346 ms 97360 KB Output is correct
12 Correct 254 ms 106044 KB Output is correct
13 Correct 182 ms 106180 KB Output is correct
14 Correct 175 ms 106428 KB Output is correct
15 Correct 173 ms 105892 KB Output is correct
16 Correct 205 ms 106424 KB Output is correct
17 Correct 181 ms 106972 KB Output is correct
18 Correct 3 ms 7256 KB Output is correct
19 Correct 3 ms 7004 KB Output is correct
20 Correct 2 ms 7004 KB Output is correct
21 Correct 2 ms 7004 KB Output is correct
22 Correct 2 ms 7004 KB Output is correct
23 Correct 1 ms 7004 KB Output is correct
24 Correct 355 ms 105532 KB Output is correct
25 Correct 269 ms 106320 KB Output is correct
26 Correct 349 ms 113524 KB Output is correct
27 Correct 306 ms 105736 KB Output is correct
28 Correct 241 ms 105988 KB Output is correct
29 Correct 229 ms 105908 KB Output is correct
30 Correct 196 ms 106432 KB Output is correct
31 Correct 424 ms 110928 KB Output is correct
32 Correct 272 ms 113392 KB Output is correct
33 Correct 352 ms 105812 KB Output is correct
34 Correct 261 ms 106068 KB Output is correct
35 Correct 2 ms 7000 KB Output is correct
36 Correct 2 ms 7004 KB Output is correct
37 Correct 3 ms 7004 KB Output is correct
38 Correct 2 ms 7108 KB Output is correct
39 Correct 2 ms 7004 KB Output is correct
40 Correct 2 ms 7000 KB Output is correct
41 Correct 2 ms 7004 KB Output is correct
42 Correct 2 ms 7004 KB Output is correct
43 Correct 2 ms 7224 KB Output is correct
44 Correct 2 ms 7004 KB Output is correct
45 Correct 2 ms 7004 KB Output is correct
46 Correct 2 ms 7004 KB Output is correct
47 Correct 2 ms 7004 KB Output is correct
48 Correct 2 ms 7004 KB Output is correct
49 Correct 2 ms 7004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7004 KB Output is correct
2 Correct 446 ms 102556 KB Output is correct
3 Correct 580 ms 100060 KB Output is correct
4 Correct 417 ms 100436 KB Output is correct
5 Correct 326 ms 94224 KB Output is correct
6 Correct 254 ms 94288 KB Output is correct
7 Correct 237 ms 94488 KB Output is correct
8 Correct 193 ms 94720 KB Output is correct
9 Correct 469 ms 99924 KB Output is correct
10 Correct 547 ms 100948 KB Output is correct
11 Correct 373 ms 94524 KB Output is correct
12 Correct 377 ms 93860 KB Output is correct
13 Correct 309 ms 94652 KB Output is correct
14 Correct 307 ms 95572 KB Output is correct
15 Correct 1 ms 7004 KB Output is correct
16 Correct 2 ms 7004 KB Output is correct
17 Correct 2 ms 7004 KB Output is correct
18 Correct 2 ms 7004 KB Output is correct
19 Correct 2 ms 7004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7004 KB Output is correct
2 Correct 472 ms 102164 KB Output is correct
3 Correct 572 ms 107340 KB Output is correct
4 Correct 431 ms 108912 KB Output is correct
5 Correct 370 ms 104488 KB Output is correct
6 Correct 290 ms 104536 KB Output is correct
7 Correct 255 ms 104276 KB Output is correct
8 Correct 205 ms 104364 KB Output is correct
9 Correct 480 ms 112468 KB Output is correct
10 Correct 569 ms 111412 KB Output is correct
11 Correct 404 ms 105148 KB Output is correct
12 Correct 388 ms 103764 KB Output is correct
13 Correct 323 ms 104272 KB Output is correct
14 Correct 328 ms 105328 KB Output is correct
15 Correct 2 ms 7000 KB Output is correct
16 Correct 2 ms 7004 KB Output is correct
17 Correct 2 ms 7008 KB Output is correct
18 Correct 2 ms 7004 KB Output is correct
19 Correct 3 ms 7004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7000 KB Output is correct
2 Correct 2 ms 7004 KB Output is correct
3 Correct 2 ms 7004 KB Output is correct
4 Correct 3 ms 9308 KB Output is correct
5 Correct 4 ms 9308 KB Output is correct
6 Correct 3 ms 9516 KB Output is correct
7 Correct 4 ms 9308 KB Output is correct
8 Correct 3 ms 9308 KB Output is correct
9 Correct 2 ms 7004 KB Output is correct
10 Correct 2 ms 7004 KB Output is correct
11 Correct 2 ms 7004 KB Output is correct
12 Correct 2 ms 7004 KB Output is correct
13 Correct 2 ms 7004 KB Output is correct
14 Correct 2 ms 7004 KB Output is correct
15 Correct 2 ms 7004 KB Output is correct
16 Correct 2 ms 7004 KB Output is correct
17 Correct 2 ms 7004 KB Output is correct
18 Correct 2 ms 7004 KB Output is correct
19 Correct 2 ms 7004 KB Output is correct
20 Correct 2 ms 7004 KB Output is correct
21 Correct 2 ms 7004 KB Output is correct
22 Correct 2 ms 7004 KB Output is correct
23 Correct 2 ms 7004 KB Output is correct
24 Correct 2 ms 7004 KB Output is correct
25 Correct 2 ms 7004 KB Output is correct
26 Correct 2 ms 7004 KB Output is correct
27 Correct 2 ms 7000 KB Output is correct
28 Correct 2 ms 7004 KB Output is correct
29 Correct 1 ms 7004 KB Output is correct
30 Correct 390 ms 97420 KB Output is correct
31 Correct 255 ms 94244 KB Output is correct
32 Correct 342 ms 100688 KB Output is correct
33 Correct 334 ms 95688 KB Output is correct
34 Correct 236 ms 95572 KB Output is correct
35 Correct 219 ms 95996 KB Output is correct
36 Correct 196 ms 96328 KB Output is correct
37 Correct 453 ms 105224 KB Output is correct
38 Correct 259 ms 101456 KB Output is correct
39 Correct 346 ms 97360 KB Output is correct
40 Correct 254 ms 106044 KB Output is correct
41 Correct 182 ms 106180 KB Output is correct
42 Correct 175 ms 106428 KB Output is correct
43 Correct 173 ms 105892 KB Output is correct
44 Correct 205 ms 106424 KB Output is correct
45 Correct 181 ms 106972 KB Output is correct
46 Correct 3 ms 7256 KB Output is correct
47 Correct 3 ms 7004 KB Output is correct
48 Correct 2 ms 7004 KB Output is correct
49 Correct 2 ms 7004 KB Output is correct
50 Correct 2 ms 7004 KB Output is correct
51 Correct 1 ms 7004 KB Output is correct
52 Correct 355 ms 105532 KB Output is correct
53 Correct 269 ms 106320 KB Output is correct
54 Correct 349 ms 113524 KB Output is correct
55 Correct 306 ms 105736 KB Output is correct
56 Correct 241 ms 105988 KB Output is correct
57 Correct 229 ms 105908 KB Output is correct
58 Correct 196 ms 106432 KB Output is correct
59 Correct 424 ms 110928 KB Output is correct
60 Correct 272 ms 113392 KB Output is correct
61 Correct 352 ms 105812 KB Output is correct
62 Correct 261 ms 106068 KB Output is correct
63 Correct 2 ms 7000 KB Output is correct
64 Correct 2 ms 7004 KB Output is correct
65 Correct 3 ms 7004 KB Output is correct
66 Correct 2 ms 7108 KB Output is correct
67 Correct 2 ms 7004 KB Output is correct
68 Correct 2 ms 7000 KB Output is correct
69 Correct 2 ms 7004 KB Output is correct
70 Correct 2 ms 7004 KB Output is correct
71 Correct 2 ms 7224 KB Output is correct
72 Correct 2 ms 7004 KB Output is correct
73 Correct 2 ms 7004 KB Output is correct
74 Correct 2 ms 7004 KB Output is correct
75 Correct 2 ms 7004 KB Output is correct
76 Correct 2 ms 7004 KB Output is correct
77 Correct 2 ms 7004 KB Output is correct
78 Correct 3 ms 7004 KB Output is correct
79 Correct 446 ms 102556 KB Output is correct
80 Correct 580 ms 100060 KB Output is correct
81 Correct 417 ms 100436 KB Output is correct
82 Correct 326 ms 94224 KB Output is correct
83 Correct 254 ms 94288 KB Output is correct
84 Correct 237 ms 94488 KB Output is correct
85 Correct 193 ms 94720 KB Output is correct
86 Correct 469 ms 99924 KB Output is correct
87 Correct 547 ms 100948 KB Output is correct
88 Correct 373 ms 94524 KB Output is correct
89 Correct 377 ms 93860 KB Output is correct
90 Correct 309 ms 94652 KB Output is correct
91 Correct 307 ms 95572 KB Output is correct
92 Correct 1 ms 7004 KB Output is correct
93 Correct 2 ms 7004 KB Output is correct
94 Correct 2 ms 7004 KB Output is correct
95 Correct 2 ms 7004 KB Output is correct
96 Correct 2 ms 7004 KB Output is correct
97 Correct 2 ms 7004 KB Output is correct
98 Correct 472 ms 102164 KB Output is correct
99 Correct 572 ms 107340 KB Output is correct
100 Correct 431 ms 108912 KB Output is correct
101 Correct 370 ms 104488 KB Output is correct
102 Correct 290 ms 104536 KB Output is correct
103 Correct 255 ms 104276 KB Output is correct
104 Correct 205 ms 104364 KB Output is correct
105 Correct 480 ms 112468 KB Output is correct
106 Correct 569 ms 111412 KB Output is correct
107 Correct 404 ms 105148 KB Output is correct
108 Correct 388 ms 103764 KB Output is correct
109 Correct 323 ms 104272 KB Output is correct
110 Correct 328 ms 105328 KB Output is correct
111 Correct 2 ms 7000 KB Output is correct
112 Correct 2 ms 7004 KB Output is correct
113 Correct 2 ms 7008 KB Output is correct
114 Correct 2 ms 7004 KB Output is correct
115 Correct 3 ms 7004 KB Output is correct
116 Correct 404 ms 103444 KB Output is correct
117 Correct 456 ms 106324 KB Output is correct
118 Correct 445 ms 113236 KB Output is correct
119 Correct 376 ms 105792 KB Output is correct
120 Correct 299 ms 105552 KB Output is correct
121 Correct 302 ms 106396 KB Output is correct
122 Correct 220 ms 106412 KB Output is correct
123 Correct 474 ms 112056 KB Output is correct
124 Correct 614 ms 110272 KB Output is correct
125 Correct 400 ms 104760 KB Output is correct
126 Correct 461 ms 106064 KB Output is correct
127 Correct 510 ms 106592 KB Output is correct
128 Correct 429 ms 107092 KB Output is correct
129 Correct 450 ms 108140 KB Output is correct