이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <bits/stdc++.h>
#define N 400005
#define M 50005
#define K 30
#define X 10
using namespace std;
struct node{
int to;
long long val;
};
struct node2{
int to;
long long sum;
long long maxi;
};
node sp[M][X][K];
node2 sp2[N][K];
vector<int> numbers;
int sz;
int n;
bool subtask4 = 0;
bool subtask2 = 1;
vector<int> s,p,w,l;
void init(int n_, vector<int> s_, vector<int> p_, vector<int> w_, vector<int> l_) {
n = n_;
s = s_;
p = p_;
w = w_;
l = l_;
for(int i = 0;i<n;i++){
subtask2 &= (s[i] == p[i]);
numbers.push_back(s[i]);
}
sort(numbers.begin(),numbers.end());
numbers.resize(unique(numbers.begin(),numbers.end())-numbers.begin());
sz = numbers.size();
if(sz <= 5 && n <= 50000)subtask4 = 1;
if(subtask4){
for(int x = 0;x<=sz;x++){
sp[n][x][0].to = n;
sp[n][x][0].val = 0;
for(int i = 0;i<n;i++){
int num = upper_bound(numbers.begin(),numbers.end(),s[i]) - numbers.begin();
if(num <= x){
sp[i][x][0].to = w[i];
sp[i][x][0].val = s[i];
}
else{
sp[i][x][0].to = l[i];
sp[i][x][0].val = p[i];
}
}
for(int j = 1;j<K;j++){
for(int i = 0;i<=n;i++){
sp[i][x][j].val = sp[i][x][j-1].val + sp[sp[i][x][j-1].to][x][j-1].val;
sp[i][x][j].to = sp[sp[i][x][j-1].to][x][j-1].to;
}
}
}
}
if(subtask2){
for(int i = 0;i<n;i++){
sp2[i][0].to = w[i];
sp2[i][0].sum = s[i];
sp2[i][0].maxi = s[i];
}
sp2[n][0].to = n;
sp2[n][0].sum = 0;
sp2[n][0].maxi = 0;
for(int j = 1;j<K;j++){
for(int i = 0;i<=n;i++){
sp2[i][j].to = sp2[sp2[i][j-1].to][j-1].to;
sp2[i][j].sum = sp2[i][j-1].sum + sp2[sp2[i][j-1].to][j-1].sum;
sp2[i][j].maxi = max(sp2[i][j-1].maxi,sp2[sp2[i][j-1].to][j-1].maxi - sp2[i][j-1].sum);
}
}
}
return;
}
long long simulate(int x, int z) {
long long pw = z;
int now = upper_bound(numbers.begin(),numbers.end(),pw) - numbers.begin();
if(subtask2){
while(x != n){
for(int i = K-1;i>=0;i--){
if(sp2[x][i].maxi <= pw){
pw += sp2[x][i].sum;
x = sp2[x][i].to;
}
}
if(x != n){
pw += p[x];
x = l[x];
}
}
return pw;
}
if(subtask4){
while(x != n){
//cout << now << " " << x << " " << pw << endl;
if(now == sz){
pw += sp[x][now][K-1].val;
x = sp[x][now][K-1].to;
assert(x == n);
}
else{
for(int i = K-1;i>=0;i--){
if(sp[x][now][i].val + pw < numbers[now]){
pw += sp[x][now][i].val;
x = sp[x][now][i].to;
}
}
pw += sp[x][now][0].val;
x = sp[x][now][0].to;
while(now != sz && pw >= numbers[now])
now++;
}
}
return pw;
}
while(x != n){
if(s[x] <= pw){
pw += s[x];
x = w[x];
}
else{
pw += p[x];
x = l[x];
}
}
return pw;
}
# | 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... |