Submission #892225

# Submission time Handle Problem Language Result Execution time Memory
892225 2023-12-25T05:02:34 Z vjudge1 Sprinkler (JOI22_sprinkler) C++17
41 / 100
276 ms 43092 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][5];
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,q;
	ll a,b,c;
	cin>>n>>k;
	for(i=0;i<=n;i++)val[i][1]=val[i][2]=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;
	if(n<=1000 && q<=1000){
		for(i=0;i<q;i++){
			cin>>t;
			if(t==1){
				cin>>a>>b>>c;
				dfs(a,0,c,0,b);
			}else{
				cin>>a;
				cout<<h[a]<<endl;
			}
		}
		return;
	}
	for(i=0;i<q;i++){
		cin>>t;
		if(t==1){
			cin>>a>>b>>c;
			if(b==1){
				val[a][1]*=c;
				val[a][1]%=k;
				h[a]*=c;
				h[a]%=k;
				h[p[a]]*=c;
				h[p[a]]%=k;
			}else if(b==2){
				val[a][2]*=c;
				val[a][2]%=k;
				if(p[a]!=0){
					val[p[a]][1]*=c;
					val[p[a]][1]%=k;
					h[p[a]]*=c;
					h[p[a]]%=k;
				}else {
					h[a]*=c;
					h[a]%=k;
				}
				h[p[p[a]]]*=c;
				h[p[p[a]]]%=k;
			}else{
				h[a]*=c;
				h[a]%=k;
			}
		}else{
			cin>>a;
			cout<<h[a]*val[p[a]][2]%k*val[p[a]][1]%k*val[p[p[a]]][2]%k<<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);}
      |                                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 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 2 ms 7256 KB Output is correct
5 Correct 4 ms 7512 KB Output is correct
6 Correct 5 ms 7260 KB Output is correct
7 Correct 6 ms 7260 KB Output is correct
8 Correct 6 ms 7260 KB Output is correct
9 Correct 2 ms 7000 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 7000 KB Output is correct
26 Correct 2 ms 7004 KB Output is correct
27 Correct 3 ms 7004 KB Output is correct
28 Correct 2 ms 7004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7004 KB Output is correct
2 Correct 222 ms 31516 KB Output is correct
3 Correct 247 ms 32844 KB Output is correct
4 Correct 214 ms 37896 KB Output is correct
5 Correct 213 ms 33364 KB Output is correct
6 Correct 199 ms 32984 KB Output is correct
7 Correct 189 ms 33620 KB Output is correct
8 Correct 207 ms 33716 KB Output is correct
9 Correct 210 ms 41296 KB Output is correct
10 Correct 225 ms 40132 KB Output is correct
11 Correct 207 ms 33480 KB Output is correct
12 Correct 216 ms 32848 KB Output is correct
13 Correct 156 ms 34756 KB Output is correct
14 Correct 163 ms 36032 KB Output is correct
15 Correct 159 ms 35256 KB Output is correct
16 Correct 158 ms 35908 KB Output is correct
17 Correct 188 ms 36344 KB Output is correct
18 Correct 2 ms 7000 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
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7004 KB Output is correct
2 Correct 222 ms 31516 KB Output is correct
3 Correct 247 ms 32844 KB Output is correct
4 Correct 214 ms 37896 KB Output is correct
5 Correct 213 ms 33364 KB Output is correct
6 Correct 199 ms 32984 KB Output is correct
7 Correct 189 ms 33620 KB Output is correct
8 Correct 207 ms 33716 KB Output is correct
9 Correct 210 ms 41296 KB Output is correct
10 Correct 225 ms 40132 KB Output is correct
11 Correct 207 ms 33480 KB Output is correct
12 Correct 216 ms 32848 KB Output is correct
13 Correct 156 ms 34756 KB Output is correct
14 Correct 163 ms 36032 KB Output is correct
15 Correct 159 ms 35256 KB Output is correct
16 Correct 158 ms 35908 KB Output is correct
17 Correct 188 ms 36344 KB Output is correct
18 Correct 2 ms 7000 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 199 ms 35112 KB Output is correct
25 Correct 202 ms 35664 KB Output is correct
26 Correct 276 ms 43092 KB Output is correct
27 Correct 211 ms 35444 KB Output is correct
28 Correct 189 ms 35432 KB Output is correct
29 Correct 219 ms 35280 KB Output is correct
30 Correct 158 ms 36080 KB Output is correct
31 Correct 246 ms 40272 KB Output is correct
32 Correct 229 ms 42944 KB Output is correct
33 Correct 245 ms 35100 KB Output is correct
34 Correct 214 ms 35820 KB Output is correct
35 Correct 2 ms 7004 KB Output is correct
36 Correct 2 ms 7004 KB Output is correct
37 Correct 2 ms 7232 KB Output is correct
38 Correct 3 ms 7004 KB Output is correct
39 Correct 3 ms 7244 KB Output is correct
40 Correct 2 ms 7012 KB Output is correct
41 Correct 2 ms 7152 KB Output is correct
42 Correct 2 ms 7000 KB Output is correct
43 Correct 2 ms 7000 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 7232 KB Output is correct
49 Correct 3 ms 7004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7004 KB Output is correct
2 Incorrect 210 ms 38740 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7004 KB Output is correct
2 Incorrect 246 ms 36112 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 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 2 ms 7256 KB Output is correct
5 Correct 4 ms 7512 KB Output is correct
6 Correct 5 ms 7260 KB Output is correct
7 Correct 6 ms 7260 KB Output is correct
8 Correct 6 ms 7260 KB Output is correct
9 Correct 2 ms 7000 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 7000 KB Output is correct
26 Correct 2 ms 7004 KB Output is correct
27 Correct 3 ms 7004 KB Output is correct
28 Correct 2 ms 7004 KB Output is correct
29 Correct 2 ms 7004 KB Output is correct
30 Correct 222 ms 31516 KB Output is correct
31 Correct 247 ms 32844 KB Output is correct
32 Correct 214 ms 37896 KB Output is correct
33 Correct 213 ms 33364 KB Output is correct
34 Correct 199 ms 32984 KB Output is correct
35 Correct 189 ms 33620 KB Output is correct
36 Correct 207 ms 33716 KB Output is correct
37 Correct 210 ms 41296 KB Output is correct
38 Correct 225 ms 40132 KB Output is correct
39 Correct 207 ms 33480 KB Output is correct
40 Correct 216 ms 32848 KB Output is correct
41 Correct 156 ms 34756 KB Output is correct
42 Correct 163 ms 36032 KB Output is correct
43 Correct 159 ms 35256 KB Output is correct
44 Correct 158 ms 35908 KB Output is correct
45 Correct 188 ms 36344 KB Output is correct
46 Correct 2 ms 7000 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
50 Correct 2 ms 7004 KB Output is correct
51 Correct 2 ms 7004 KB Output is correct
52 Correct 199 ms 35112 KB Output is correct
53 Correct 202 ms 35664 KB Output is correct
54 Correct 276 ms 43092 KB Output is correct
55 Correct 211 ms 35444 KB Output is correct
56 Correct 189 ms 35432 KB Output is correct
57 Correct 219 ms 35280 KB Output is correct
58 Correct 158 ms 36080 KB Output is correct
59 Correct 246 ms 40272 KB Output is correct
60 Correct 229 ms 42944 KB Output is correct
61 Correct 245 ms 35100 KB Output is correct
62 Correct 214 ms 35820 KB Output is correct
63 Correct 2 ms 7004 KB Output is correct
64 Correct 2 ms 7004 KB Output is correct
65 Correct 2 ms 7232 KB Output is correct
66 Correct 3 ms 7004 KB Output is correct
67 Correct 3 ms 7244 KB Output is correct
68 Correct 2 ms 7012 KB Output is correct
69 Correct 2 ms 7152 KB Output is correct
70 Correct 2 ms 7000 KB Output is correct
71 Correct 2 ms 7000 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 7232 KB Output is correct
77 Correct 3 ms 7004 KB Output is correct
78 Correct 2 ms 7004 KB Output is correct
79 Incorrect 210 ms 38740 KB Output isn't correct
80 Halted 0 ms 0 KB -