이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
typedef long long ll;
#define F first
#define S second
#define mk make_pair
typedef pair <int, int> pii;
const int N = 400023, LG = 24, L2 = 10, K = 4;
int s[N], p[N], o[N], l[N], n;
long long m[N], a[N];
pair <int, pii> nx[LG][N][L2];
const ll INF = 1e18;
void init(int nn, std::vector<int> ss, std::vector<int> pp, std::vector<int> ww, std::vector<int> ll) {
n = nn;
for (int i = 0; i < n; i++) {
s[i] = ss[i];
p[i] = pp[i];
o[i] = ww[i];
l[i] = ll[i];
}
m[n] = 0;
a[n] = 0;
l[n] = n;
o[n] = n;
s[n] = 0;
for (int i = n - 1; i >= 0; i--) {
a[i] = a[o[i]] + s[i];
m[i] = max((long long)s[i], m[o[i]] - s[i]);
}
for (int w = 0; w < LG; w++) {
for (int i = 0; i <= n; i++) {
if (i < n && s[i] <= (1 << w)) {
nx[w][i][0].F = o[i];
nx[w][i][0].S.F = 1e8;
nx[w][i][0].S.S = s[i];
} else {
nx[w][i][0].F = l[i];
nx[w][i][0].S.F = s[i] - 1;
nx[w][i][0].S.S = p[i];
}
}
for (int j = 1; j < L2; j++) {
for (int i = 0; i <= n; i++) {
nx[w][i][j].S.S = nx[w][i][j - 1].S.S;
nx[w][i][j].S.F = nx[w][i][j - 1].S.F;
nx[w][i][j].F = nx[w][i][j - 1].F;
for (int k = 0; k < K; k++) {
int y = nx[w][i][j].F;
nx[w][i][j].F = nx[w][y][j - 1].F;
int wef = nx[w][y][j - 1].S.F - nx[w][i][j].S.S;
if (wef < 0)
wef = -1;
nx[w][i][j].S.F = min (nx[w][i][j].S.F, wef);
nx[w][i][j].S.S = min ({(int)1e9, nx[w][i][j].S.S + nx[w][y][j - 1].S.S});
}
}
}
}
return;
}
pair <int, long long> findd (int w, int x, ll z) {
if (z <= nx[w][x][L2 - 1].S.F) {
z += nx[w][x][L2 - 1].S.S;
x = nx[w][x][L2 - 1].F;
}
for (int i = L2 - 1; i >= 0; i--) {
for (int k = 0; k < K; k++) {
if (z <= nx[w][x][i].S.F) {
z += nx[w][x][i].S.S;
x = nx[w][x][i].F;
}
}
}
return {x, z};
}
ll ans (int x, ll z) {
if (z >= m[x])
return z + a[x];
int l = 0;
while ((1 << l) < s[x])
l++;
pair <int, ll> pp = findd (l, x, z);
x = pp.F;
z = pp.S;
return ans (x, z);
}
long long simulate(int x, int z) {
pair <int, ll> pp = findd (0, x, z);
x = pp.F;
z = pp.S;
ll w = ans (x, z);
return w;
}
# | 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... |