Submission #629026

# Submission time Handle Problem Language Result Execution time Memory
629026 2022-08-14T03:29:58 Z iomoon191 Sprinkler (JOI22_sprinkler) C++17
3 / 100
221 ms 167592 KB
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a).size()
#define pb push_back
#define fi first
#define se second
#define For(i,a,b) for(int i=(a); i<=(b); ++i)
#define roF(i,a,b) for(int i=(a); i>=(b); --i)
using namespace std;
#ifdef DEBUG__
void dmpr(ostream &os){ os << "\n"; }
template<class T, class... Args>
void dmpr(ostream &os, const T &t, const Args &... args){
	os << t << " ";
	dmpr(os, args...);
}
#define dbg(...) dmpr(cerr, __LINE__, ##__VA_ARGS__)
#else
#define dbg(...) void(0)
#endif
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
typedef long double ld;
const int N=200005;
const int inf=0x3f3f3f3f;
mt19937 rng(random_device {}()); 
int rand(int a){
	return rng()%a;
}
int mod;
struct mint {
    int val;
    mint(){ val = 0; }
    mint(const ll& v) {
        val=(-mod <= v and v < mod) ? v : v%mod;
        if (val < 0) val+=mod;
    }
    friend bool operator==(const mint& a, const mint& b){ return a.val == b.val; }
    friend bool operator!=(const mint& a, const mint& b){ return !(a == b); }
    friend ostream& operator<<(ostream& os, const mint& a){ return os << a.val; }
    friend bool operator<(const mint& a, const mint& b){ return a.val < b.val; }
    mint operator-()const{ return mint(-val); }
    mint& operator+=(const mint& m){ 
    	if((val+=m.val) >= mod) val-=mod; 
    	return *this; 
    }
    mint& operator-=(const mint& m){ 
    	if ((val-=m.val) < 0) val+=mod; 
    	return *this; 
    }
    mint& operator*=(const mint& m){ 
    	val=(ll)val*m.val%mod; 
    	return *this; 
    }
    friend mint ipow(mint a, ll p) {
        mint ans=1; 
        for(; p; p >>= 1, a*=a) if (p&1) ans*=a;
        return ans;
    }
    friend mint inv(const mint& a){ 
    	assert(a.val); 
    	return ipow(a, mod-2); 
    }
    mint& operator /= (const mint& m){ 
    	return (*this) *= inv(m); 
    }
    friend mint operator+(mint a, const mint& b){ return a+=b; }
    friend mint operator-(mint a, const mint& b){ return a-=b; }
    friend mint operator*(mint a, const mint& b){ return a*=b; }
    friend mint operator/(mint a, const mint& b){ return a/=b; }
    operator int64_t() const{ return val; }
};
vi adj[N];
int n, l, par[N], dep[N], zin[N], zout[N], piv;
mint dp[N][45];
void dfs(int x, int p){
	zin[x]=++piv;
	for(auto &i: adj[x]){
		if(i == p) continue;
		dep[i]=dep[x]+1;
		par[i]=x;
		dfs(i, x);
	}
	zout[x]=piv;
}
void rmain(){
	cin >> n >> l;
	mod=l;
	For(i,2,n){
		int u, v; cin >> u>> v;
		adj[v].pb(u);
		adj[u].pb(v);
	}
	For(i,n+1,n+44){
		adj[i].pb(i+1);
		adj[i+1].pb(i);
	}
	adj[1].pb(n+1);
	adj[n+1].pb(1);
	n+=45;
	dfs(n, -1);
	For(i,1,n) For(j,0,40) dp[i][j]=mint(1);
	For(i,1,n-45){
		int x; cin >> x;
		dp[i][0]*=mint(x);
	}
	int q; cin >> q;
	while(q--){
		int t; cin >> t;
		if(t == 1){
			int v, d, w;
			cin >> v >> d >> w;
			vi sk;
			For(i,0,d){
				sk.pb(v);
				v=par[v];
			}
			For(i,0,d){
				if(i < d) dp[sk[i]][d-i-1]*=mint(w);
				dp[sk[i]][d-i]*=mint(w);
			}
		}
		else{
			int v; cin >> v;
			mint res=1;
			For(i,0,40){
				res*=dp[v][i];
				v=par[v];
			}
			cout << res << "\n";
		}
	}
}

signed main(int argc, char *argv[]){
	iostream::sync_with_stdio(0);
	int T=1; 
	while(T--) rmain();
	return 0;
}

Compilation message

sprinkler.cpp:137:8: warning: first argument of 'int main(long long int, char**)' should be 'int' [-Wmain]
  137 | signed main(int argc, char *argv[]){
      |        ^~~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 75476 KB Output is correct
2 Correct 32 ms 75428 KB Output is correct
3 Correct 29 ms 75444 KB Output is correct
4 Correct 29 ms 75592 KB Output is correct
5 Correct 29 ms 75552 KB Output is correct
6 Correct 30 ms 75512 KB Output is correct
7 Correct 30 ms 75476 KB Output is correct
8 Correct 29 ms 75528 KB Output is correct
9 Correct 30 ms 75472 KB Output is correct
10 Correct 30 ms 75460 KB Output is correct
11 Correct 30 ms 75476 KB Output is correct
12 Correct 32 ms 75444 KB Output is correct
13 Correct 31 ms 75468 KB Output is correct
14 Correct 28 ms 75476 KB Output is correct
15 Correct 28 ms 75460 KB Output is correct
16 Correct 30 ms 75488 KB Output is correct
17 Correct 28 ms 75476 KB Output is correct
18 Correct 31 ms 75436 KB Output is correct
19 Correct 32 ms 75432 KB Output is correct
20 Correct 32 ms 75400 KB Output is correct
21 Correct 33 ms 75396 KB Output is correct
22 Correct 29 ms 75424 KB Output is correct
23 Correct 30 ms 75504 KB Output is correct
24 Correct 30 ms 75380 KB Output is correct
25 Correct 35 ms 75468 KB Output is correct
26 Correct 29 ms 75476 KB Output is correct
27 Correct 34 ms 75388 KB Output is correct
28 Correct 34 ms 75396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 75400 KB Output is correct
2 Runtime error 221 ms 167592 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 75400 KB Output is correct
2 Runtime error 221 ms 167592 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 75468 KB Output is correct
2 Runtime error 210 ms 165668 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 75460 KB Output is correct
2 Runtime error 191 ms 165712 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 75476 KB Output is correct
2 Correct 32 ms 75428 KB Output is correct
3 Correct 29 ms 75444 KB Output is correct
4 Correct 29 ms 75592 KB Output is correct
5 Correct 29 ms 75552 KB Output is correct
6 Correct 30 ms 75512 KB Output is correct
7 Correct 30 ms 75476 KB Output is correct
8 Correct 29 ms 75528 KB Output is correct
9 Correct 30 ms 75472 KB Output is correct
10 Correct 30 ms 75460 KB Output is correct
11 Correct 30 ms 75476 KB Output is correct
12 Correct 32 ms 75444 KB Output is correct
13 Correct 31 ms 75468 KB Output is correct
14 Correct 28 ms 75476 KB Output is correct
15 Correct 28 ms 75460 KB Output is correct
16 Correct 30 ms 75488 KB Output is correct
17 Correct 28 ms 75476 KB Output is correct
18 Correct 31 ms 75436 KB Output is correct
19 Correct 32 ms 75432 KB Output is correct
20 Correct 32 ms 75400 KB Output is correct
21 Correct 33 ms 75396 KB Output is correct
22 Correct 29 ms 75424 KB Output is correct
23 Correct 30 ms 75504 KB Output is correct
24 Correct 30 ms 75380 KB Output is correct
25 Correct 35 ms 75468 KB Output is correct
26 Correct 29 ms 75476 KB Output is correct
27 Correct 34 ms 75388 KB Output is correct
28 Correct 34 ms 75396 KB Output is correct
29 Correct 31 ms 75400 KB Output is correct
30 Runtime error 221 ms 167592 KB Execution killed with signal 11
31 Halted 0 ms 0 KB -