제출 #1285223

#제출 시각아이디문제언어결과실행 시간메모리
1285223Faggi던전 (IOI21_dungeons)C++20
25 / 100
1146 ms105328 KiB
#include <bits/stdc++.h> #define ll long long #define sz(x) int(x.size()) #define forn(i, n) for (i = 0; i < n; i++) #define all(x) x.begin(), x.end() #define pb push_back #define mp make_pair #define fr first #define se second using namespace std; const int MAXN = 5e4 + 1; const int LOG = 20; ll ma[MAXN][LOG], up2[MAXN][LOG], sum2[MAXN][LOG]; ll up3[25][MAXN][LOG], sum3[25][MAXN][LOG]; vector<int> S, P, W, L, dif; int N; void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) { s.pb(0); p.pb(0); w.pb(n); l.pb(n); ll i, j; N = n; S = s; P = p; W = w; L = l; map<ll, bool> m; for (i = 0; i < n; i++) { if (m[s[i]] == 0) dif.pb(s[i]); m[s[i]] = 1; } sort(all(dif)); for (i = 0; i <= n; i++) { up2[i][0] = w[i]; ma[i][0] = s[i]; sum2[i][0] = s[i]; for (j = 0; j < sz(dif); j++) { ll x, y; if(s[i]<dif[j]) { x=w[i]; y=s[i]; } else { x=l[i]; y=p[i]; } up3[j][i][0]=x; sum3[j][i][0]=y; } } for (i = 1; i < LOG; i++) { for (j = 0; j <= n; j++) { up2[j][i] = up2[up2[j][i - 1]][i - 1]; sum2[j][i] = sum2[j][i - 1] + sum2[up2[j][i - 1]][i - 1]; ma[j][i] = max(ma[j][i - 1], ma[up2[j][i - 1]][i - 1]); for (ll k = 0; k < sz(dif); k++) { up3[k][j][i]=up3[k][up3[k][j][i-1]][i-1]; sum3[k][j][i]=sum3[k][j][i-1]+sum3[k][up3[k][j][i-1]][i-1]; } } } return; } long long simulate(int x, int z) { ll act = z, i, ult; while (x != N) { if (1ll * S[x] <= act) { ll aum = 0; for (i = LOG - 1; i >= 0; i--) { if (ma[x][i] <= act) { aum += sum2[x][i]; x = up2[x][i]; } } act += aum; } else { ll pos=0; for(i=0; i<sz(dif); i++) { if(dif[i]<=act) { pos++; } } for(i=LOG-1; i>=0; i--) { if(sum3[pos][x][i]+act<dif[pos]) { act+=sum3[pos][x][i]; x=up3[pos][x][i]; } } act+=sum3[pos][x][0]; x=up3[pos][x][0]; } } return act; }
#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...