Submission #1088010

#TimeUsernameProblemLanguageResultExecution timeMemory
1088010Valaki2Overtaking (IOI23_overtaking)C++17
10 / 100
3606 ms1745496 KiB
#include "overtaking.h" #include <bits/stdc++.h> using namespace std; #define int __int128_t //#define int long long #define ll long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define fi first #define se second const int inf = 2e18 + 42; struct node { int pl, pr; int vl, vr; int val; node() { pl = 0, pr = 0; vl = 0, vr = 0; val = 0; } node(int vl_, int vr_) { pl = 0, pr = 0; vl = vl_, vr = vr_; val = 0; } }; int l, n, m; vector<pii > buses; int new_speed; vector<int> nxt_dist; vector<vector<node> > tree; //vector<map<int, int> > tree; void upd(int idx, int pos, int val, int cur = 1) { vector<node> &t = tree[idx]; if(t[cur].vl != t[cur].vr) { int mid = (t[cur].vl + t[cur].vr) / 2; if(pos <= mid) { if(t[cur].pl == 0) { t[cur].pl = t.size(); t.pb(node(t[cur].vl, mid)); } upd(idx, pos, val, t[cur].pl); } else { if(t[cur].pr == 0) { t[cur].pr = t.size(); t.pb(node(mid + 1, t[cur].vr)); } upd(idx, pos, val, t[cur].pr); } t[cur].val = max(t[t[cur].pl].val, t[t[cur].pr].val); } else { t[cur].val = max(t[cur].val, val); } } int qry(int idx, int ql, int qr, int cur = 1) { vector<node> &t = tree[idx]; if(ql > t[cur].vr || qr < t[cur].vl) { return 0; } if(ql == t[cur].vl && qr == t[cur].vr) { return t[cur].val; } int mid = (t[cur].vl + t[cur].vr) / 2; if(t[cur].pl == 0) { t[cur].pl = t.size(); t.pb(node(t[cur].vl, mid)); } if(t[cur].pr == 0) { t[cur].pr = t.size(); t.pb(node(mid + 1, t[cur].vr)); } return max(qry(idx, ql, min(qr, mid), t[cur].pl), qry(idx, max(ql, mid + 1), qr, t[cur].pr)); } vector<map<int, int> > arr; /* void upd(int idx, int pos, int val) { arr[idx][pos] = max(arr[idx][pos], val); } int qry(int idx, int junk, int pos) { int res = -inf; for(pii p : arr[idx]) { if(p.fi <= pos) { res = max(res, p.se); } } return res; }*/ /*void upd(int idx, int pos, int val) { while(pos <= inf) { //int &cur = tree[idx][pos]; //cur = max(cur, val); tree[idx][pos] = max(tree[idx][pos], val); //if(inf - (pos & (-pos)) <= pos) { // //} pos += pos & (-pos); } } int qry(int idx, int pos) { int res = 0; while(pos > 0) { res = max(res, tree[idx][pos]); pos -= pos & (-pos); } return res; }*/ void init(signed L, signed N, vector<ll> T, vector<signed> W, signed X, signed M, vector<signed> S) { l = L, n = N, new_speed = X, m = M; buses.resize(n); for(int i = 0; i < n; i++) { buses[i] = mp(W[i], T[i] + 5); } sort(buses.begin(), buses.end()); nxt_dist.resize(m + 1); nxt_dist[0] = 0; for(int i = 1; i < m; i++) { nxt_dist[i] = S[i] - S[i - 1]; } // setup done tree.assign(1 + m, {node(), node(1, inf)}); arr.resize(1 + m); //tree.resize(1 + m); for(pii bus : buses) { int speed = bus.fi, start = bus.se; for(int i = 1; i < m; i++) { int current = start + speed * nxt_dist[i]; int other = qry(i, 1, start); upd(i, start + 1, current); if(other >= current) { start = other; } else { start = current; } } } } ll arrival_time(ll Y) { int speed = new_speed, start = Y + 5; for(int i = 1; i < m; i++) { int current = start + speed * nxt_dist[i]; int other = qry(i, 1, start); if(other >= current) { start = other; } else { start = current; } } return start - 5; }
#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...