이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
#define n N
#define s S
#define p P
#define w W
#define l L
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second
const int logn = 31;
const int inf = 4e16 + 42;
int n;
vector<int> win_str, lose_str, win_pos, lose_pos;
int k;
vector<vector<vector<int> > > lift_str;
vector<vector<vector<int> > > lift_pos;
map<int, int> conv;
vector<int> val;
void solve() {
for(int i = 0; i < n; i++) {
conv[win_str[i]] = -1;
}
conv[inf] = -1;
k = (int) conv.size();
val.assign(k, 0);
int val_idx = -1;
for(int i = 0; i < k; i++) {
vector<pii > v;
for(const pii &p : conv) {
val_idx++;
v.pb(mp(p.fi, val_idx));
val[val_idx] = p.fi;
}
conv.clear();
for(const pii &p : v) {
conv[p.fi] = p.se;
}
}
lift_str = lift_pos = vector<vector<vector<int> > > (k, vector<vector<int> > (1 + n, vector<int> (logn, 0)));
int minimum_value = 0; // these are already won
for(int cur_idx = 0; cur_idx < k; cur_idx++) {
vector<vector<int> > &cur_lift_str = lift_str[cur_idx];
vector<vector<int> > &cur_lift_pos = lift_pos[cur_idx];
for(int i = 0; i <= n; i++) {
if(win_str[i] <= minimum_value) {
cur_lift_str[i][0] = win_str[i];
cur_lift_pos[i][0] = win_pos[i];
} else {
cur_lift_str[i][0] = lose_str[i];
cur_lift_pos[i][0] = lose_pos[i];
}
}
for(int j = 1; j < logn; j++) {
for(int i = 0; i <= n; i++) {
cur_lift_str[i][j] = cur_lift_str[i][j - 1] + cur_lift_str[cur_lift_pos[i][j - 1]][j - 1];
cur_lift_pos[i][j] = cur_lift_pos[cur_lift_pos[i][j - 1]][j - 1];
}
}
minimum_value = val[cur_idx];
}
//
}
int query(int pos, int strength) {
/*if(strength >= k) {
return strength + cost[pos];
}
for(int j = logn - 1; j >= 0; j--) {
if(strength + lift_str[pos][j] < k) {
strength += lift_str[pos][j];
pos = lift_pos[pos][j];
}
}
strength += lift_str[pos][0];
pos = lift_pos[pos][0];
return strength + cost[pos];*/
for(int cur_idx = 0; cur_idx < k; cur_idx++) {
if(strength >= val[cur_idx]) {
continue;
}
for(int j = logn - 1; j >= 0; j--) {
if(strength + lift_str[cur_idx][pos][j] < k) {
strength += lift_str[cur_idx][pos][j];
pos = lift_pos[cur_idx][pos][j];
}
}
strength += lift_str[cur_idx][pos][0];
pos = lift_pos[cur_idx][pos][0];
}
return strength;
}
#undef n
#undef s
#undef p
#undef w
#undef l
void init(signed n, vector<signed> s, vector<signed> p, vector<signed> w, vector<signed> l) {
N = n;
win_str = lose_str = win_pos = lose_pos = (vector<int> (n + 1, 0));
for(int i = 0; i < n; i++) {
win_str[i] = s[i];
lose_str[i] = p[i];
win_pos[i] = w[i];
lose_pos[i] = l[i];
}
win_str[n] = 0;
lose_str[n] = 0;
win_pos[n] = n;
lose_pos[n] = n;
solve();
}
int simulate(signed x, signed z) {
return query(x, z);
}
# | 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... |