# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
878459 | borisAngelov | Sprinkler (JOI22_sprinkler) | C++17 | 2587 ms | 104812 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
const int maxDepth = 40;
int n, q;
long long mod;
vector<int> g[maxn];
long long height[maxn];
long long lazy[maxn][maxDepth + 5];
int parent[maxn];
void dfs(int node, int par)
{
parent[node] = par;
for (int i = 0; i < g[node].size(); ++i)
{
if (g[node][i] != par)
{
dfs(g[node][i], node);
}
}
}
void update(int node, int dist, long long mult)
{
while (node != -1 && dist >= 0)
{
for (int i = dist; i >= 0; --i)
{
lazy[node][i] *= mult;
lazy[node][i] %= mod;
}
--dist;
node = parent[node];
}
}
long long query(int node)
{
int dist = 0;
long long ans = height[node];
while (node != -1 && dist <= 40)
{
ans = (ans * lazy[node][dist]) % mod;
node = parent[node];
++dist;
}
return ans;
}
void fastIO()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
{
fastIO();
cin >> n >> mod;
for (int i = 1; i <= n - 1; ++i)
{
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
for (int i = 1; i <= n; ++i)
{
cin >> height[i];
}
for (int i = 1; i <= n; ++i)
{
for (int j = 0; j <= maxDepth; ++j)
{
lazy[i][j] = 1;
}
}
dfs(1, -1);
cin >> q;
for (int i = 1; i <= q; ++i)
{
int type;
cin >> type;
if (type == 1)
{
int node, dist, mult;
cin >> node >> dist >> mult;
update(node, dist, mult);
}
else
{
int node;
cin >> node;
cout << query(node) << "\n";
}
}
return 0;
}
컴파일 시 표준 에러 (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... |