# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
569646 | jamezzz | Sprinkler (JOI22_sprinkler) | C++17 | 818 ms | 92948 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#define getchar_unlocked getchar
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
#define disc(x) sort(all(x));x.resize(unique(all(x))-x.begin());
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));
#define mod 1000000007
inline int rd(){
int x=0;
char ch=getchar_unlocked();
while(!(ch&16))ch=getchar();//keep reading while current character is whitespace
while(ch&16){//this will break when ‘\n’ or ‘ ‘ is encountered
x=(x<<3)+(x<<1)+(ch&15);
ch=getchar_unlocked();
}
return x;
}
#define maxn 200005
int n,l,q,h[maxn],par[maxn];
ll mult[maxn][45]; //mult[i][j]: at node i, this thing can travel j more
vi AL[maxn];
void dfs(int u){
for(int v:AL[u]){
if(v==par[u])continue;
par[v]=u;
dfs(v);
}
}
int main(){
sf("%d%d",&n,&l);
for(int i=0;i<n-1;++i){
int a,b;sf("%d%d",&a,&b);
AL[a].pb(b);
AL[b].pb(a);
}
for(int i=1;i<=n;++i){
sf("%d",&h[i]);
}
dfs(1);
for(int i=0;i<=n;++i){
for(int j=0;j<=41;++j){
mult[i][j]=1;
}
}
sf("%d",&q);
while(q--){
int t;sf("%d",&t);
if(t==1){
int x,d,w;sf("%d%d%d",&x,&d,&w);
int cur=x;
for(int i=d;i>=0;--i){
mult[cur][i]*=w;
mult[cur][i]%=l;
if(par[cur]==0){
for(int j=i-1;j>=0;--j){
mult[cur][j]*=w;
mult[cur][j]%=l;
}
break;
}
else cur=par[cur];
}
/*
for(int i=1;i<=4;++i){
pf("mult[%d]: ",i);
for(int j=0;j<=4;++j){
pf("%lld ",mult[i][j]);
}
pf("\n");
}
*/
}
else{
int x;sf("%d",&x);
ll ans=h[x];
int cur=x,d=0;
while(d!=40&&cur!=0){
ans*=mult[cur][d];
ans%=l;
if(par[cur]!=0){
ans*=mult[cur][d+1];
ans%=l;
}
cur=par[cur];
++d;
}
pf("%lld\n",ans);
}
}
}
/*
4 7
1 2
2 3
3 4
1
1
1
1
11
1 2 1 2
1 1 0 2
2 1
2 2
2 3
2 4
1 4 10 2
2 1
2 2
2 3
2 4
*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |