답안 #629024

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
629024 2022-08-14T03:24:51 Z iomoon191 Sprinkler (JOI22_sprinkler) C++17
3 / 100
53 ms 84580 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=100005;
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][50];
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+50){
		adj[i].pb(i+1);
		adj[i+1].pb(i);
	}
	adj[1].pb(n+1);
	adj[n+1].pb(1);
	n+=50;
	dfs(n, -1);
	For(i,1,n) For(j,0,45) dp[i][j]=mint(1);
	For(i,1,n-50){
		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,45){
				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[]){
      |        ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 41812 KB Output is correct
2 Correct 16 ms 41812 KB Output is correct
3 Correct 15 ms 41808 KB Output is correct
4 Correct 17 ms 41940 KB Output is correct
5 Correct 17 ms 41832 KB Output is correct
6 Correct 22 ms 41836 KB Output is correct
7 Correct 19 ms 41832 KB Output is correct
8 Correct 17 ms 41832 KB Output is correct
9 Correct 18 ms 41832 KB Output is correct
10 Correct 18 ms 41812 KB Output is correct
11 Correct 20 ms 41736 KB Output is correct
12 Correct 20 ms 41812 KB Output is correct
13 Correct 17 ms 41760 KB Output is correct
14 Correct 18 ms 41824 KB Output is correct
15 Correct 17 ms 41828 KB Output is correct
16 Correct 17 ms 41788 KB Output is correct
17 Correct 17 ms 41812 KB Output is correct
18 Correct 18 ms 41816 KB Output is correct
19 Correct 17 ms 41752 KB Output is correct
20 Correct 22 ms 41812 KB Output is correct
21 Correct 17 ms 41812 KB Output is correct
22 Correct 17 ms 41756 KB Output is correct
23 Correct 19 ms 41808 KB Output is correct
24 Correct 19 ms 41824 KB Output is correct
25 Correct 18 ms 41828 KB Output is correct
26 Correct 18 ms 41812 KB Output is correct
27 Correct 21 ms 41812 KB Output is correct
28 Correct 17 ms 41724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 41756 KB Output is correct
2 Runtime error 50 ms 84580 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 41756 KB Output is correct
2 Runtime error 50 ms 84580 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 41752 KB Output is correct
2 Runtime error 51 ms 84556 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 41776 KB Output is correct
2 Runtime error 53 ms 84576 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 41812 KB Output is correct
2 Correct 16 ms 41812 KB Output is correct
3 Correct 15 ms 41808 KB Output is correct
4 Correct 17 ms 41940 KB Output is correct
5 Correct 17 ms 41832 KB Output is correct
6 Correct 22 ms 41836 KB Output is correct
7 Correct 19 ms 41832 KB Output is correct
8 Correct 17 ms 41832 KB Output is correct
9 Correct 18 ms 41832 KB Output is correct
10 Correct 18 ms 41812 KB Output is correct
11 Correct 20 ms 41736 KB Output is correct
12 Correct 20 ms 41812 KB Output is correct
13 Correct 17 ms 41760 KB Output is correct
14 Correct 18 ms 41824 KB Output is correct
15 Correct 17 ms 41828 KB Output is correct
16 Correct 17 ms 41788 KB Output is correct
17 Correct 17 ms 41812 KB Output is correct
18 Correct 18 ms 41816 KB Output is correct
19 Correct 17 ms 41752 KB Output is correct
20 Correct 22 ms 41812 KB Output is correct
21 Correct 17 ms 41812 KB Output is correct
22 Correct 17 ms 41756 KB Output is correct
23 Correct 19 ms 41808 KB Output is correct
24 Correct 19 ms 41824 KB Output is correct
25 Correct 18 ms 41828 KB Output is correct
26 Correct 18 ms 41812 KB Output is correct
27 Correct 21 ms 41812 KB Output is correct
28 Correct 17 ms 41724 KB Output is correct
29 Correct 17 ms 41756 KB Output is correct
30 Runtime error 50 ms 84580 KB Execution killed with signal 11
31 Halted 0 ms 0 KB -