제출 #819477

#제출 시각아이디문제언어결과실행 시간메모리
819477becaido던전 (IOI21_dungeons)C++17
89 / 100
7139 ms1382640 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,popcnt,sse4,abm") #include <bits/stdc++.h> using namespace std; #ifndef WAIMAI #include "dungeons.h" #endif #ifdef WAIMAI #define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE) void dout() {cout << '\n';} template<typename T, typename...U> void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);} #else #define debug(...) 7122 #endif #define ll long long #define Waimai ios::sync_with_stdio(false), cin.tie(0) #define FOR(x,a,b) for (int x = a, I = b; x <= I; x++) #define pb emplace_back #define F first #define S second const ll INF = 1e18; const int SIZE = 4e5 + 5; const int K = 10; const int H1 = log(1e7) / log(K) + 1; const int H2 = __lg((int) 1e7); int n; int s[SIZE], p[SIZE], w[SIZE], l[SIZE]; int to[SIZE][H1 + 1][H2 + 1]; int mn[SIZE][H1 + 1][H2 + 1]; ll sum[SIZE][H1 + 1][H2 + 1]; int power(int d, int up) { int re = 1; while (up) { if (up & 1) re *= d; d *= d; up >>= 1; } return re; } void init(int _n, vector<int> _s, vector<int> _p, vector<int> _w, vector<int> _l) { n = _n; FOR (i, 0, n - 1) s[i] = _s[i], p[i] = _p[i], w[i] = _w[i], l[i] = _l[i]; w[n] = l[n] = n; FOR (h, 0, H1) { int L = power(K, h), R = L * K; FOR (i, 0, n - 1) { if (s[i] < L) { to[i][h][0] = w[i]; sum[i][h][0] = s[i]; mn[i][h][0] = R; } else { to[i][h][0] = l[i]; sum[i][h][0] = p[i]; mn[i][h][0] = s[i]; } } to[n][h][0] = n; FOR (j, 1, H2) FOR (i, 1, n) { int np = to[i][h][j - 1]; to[i][h][j] = to[np][h][j - 1]; sum[i][h][j] = min(INF, sum[i][h][j - 1] + sum[np][h][j - 1]); mn[i][h][j] = min(mn[i][h][j - 1], mn[np][h][j - 1]); } } } ll simulate(int pos, int z) { ll ans = z; while (pos != n) { int h = 0; while (power(K, h + 1) <= ans) h++; if (h >= H1) { h = H1; for (int i = H2; i >= 0; i--) if (to[pos][h][i] != n) { ans += sum[pos][h][i]; pos = to[pos][h][i]; } ans += sum[pos][h][0]; pos = to[pos][h][0]; continue; } int L = power(K, h), R = L * K; for (int i = H2; i >= 0; i--) if (ans + sum[pos][h][i] < min(R, mn[pos][h][i])) { ans += sum[pos][h][i]; pos = to[pos][h][i]; } if (ans >= s[pos]) { ans += s[pos]; pos = w[pos]; } else { ans += p[pos]; pos = l[pos]; } } return ans; } /* in1 3 2 2 6 9 3 1 2 2 2 3 1 0 1 0 1 2 3 out1 24 25 */ #ifdef WAIMAI int main() { int n, q; vector<int> s, p, z; vector<int> w, l, x; vector<ll> answer; assert(scanf("%d %d", &n, &q) == 2); s.resize(n); p.resize(n); w.resize(n); l.resize(n); x.resize(q); z.resize(q); answer.resize(q); for (int i = 0; i < n; i++) { assert(scanf("%d", &s[i]) == 1); } for (int i = 0; i < n; i++) { assert(scanf("%d", &p[i]) == 1); } for (int i = 0; i < n; i++) { assert(scanf("%d", &w[i]) == 1); } for (int i = 0; i < n; i++) { assert(scanf("%d", &l[i]) == 1); } init(n, s, p, w, l); for (int i = 0; i < q; i++) { assert(scanf("%d %d", &x[i], &z[i]) == 2); answer[i] = simulate(x[i], z[i]); } fclose(stdin); for (int i = 0; i < q; i++) { printf("%lld\n", answer[i]); } fclose(stdout); return 0; } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...