제출 #1247711

#제출 시각아이디문제언어결과실행 시간메모리
124771112baaterOvertaking (IOI23_overtaking)C++20
39 / 100
3589 ms64312 KiB
#include "overtaking.h" #include <set> #include <map> #include <vector> #include <algorithm> #include <iostream> using namespace std; typedef long long ll; const bool DEBUG = 0; struct bus { int num; ll speed; ll time; bool operator<(const bus& other) const { if (time == other.time) return speed < other.speed; return time < other.time; } void print() { printf("Num: %d, speed %lld, time %lld\n", num, speed, time); } }; struct ST { ll n; vector<ll> seg; ST (int N) : n(N), seg(2*N) {} void update(ll pos, ll val) { pos += n; while (pos > 0) { seg[pos] = max(seg[pos], val); pos >>= 1; } } ll query(ll time) { ll l = n; time += n; ll ret = 0; while (l < time) { if (l&1) ret = max(ret, seg[l++]); if (time&1) ret = max(ret, seg[--time]); time >>= 1; l >>= 1; } return ret; } }; struct station { int num; ll dist; ll distDiff; vector<bus> buses; vector<pair<ll, ll>> maxes; map<ll, ll> solved; ll addToMap; void get_buses(station& other) { // buses.clear(); distDiff = dist-other.dist; sort(other.buses.begin(), other.buses.end()); ll currentMax = 0; for (bus b : other.buses) { buses.push_back(b); currentMax = max(currentMax, b.time + (b.speed*distDiff)); buses.back().time = currentMax; maxes.emplace_back(b.time, currentMax); } if (DEBUG) { debug(); } } ll has_calculated_value(bus& b) { if (solved.contains(b.time)) { return solved[b.time]; } return 0; } ll get_arrival_time(bus& b) { addToMap = -1; if (maxes.empty()) { return (b.speed*distDiff) + b.time; } auto p = lower_bound(maxes.begin(), maxes.end(), make_pair(b.time, static_cast<ll>(0))); int place = distance(maxes.begin(), p); if (b.time > maxes.back().first) { if (maxes.back().second >= (b.speed*distDiff)+b.time) { addToMap = b.time; } return max((b.speed*distDiff) + b.time, maxes.back().second); } if (place == 0) { return (distDiff*b.speed) + b.time; } place--; if (maxes[place].second >= (distDiff*b.speed)+b.time) { addToMap = b.time; } return max((distDiff*b.speed)+b.time, maxes[place].second); } void debug() { cout << "--------------\n"; cout << num << ", dist: " << dist << "\n"; for (bus b : buses) { b.print(); } cout << "--------------\n"; } }; vector<bus> busesGlobal; vector<station> stationGlobal; bus specialBus; void init(int L, int N, std::vector<long long> T, std::vector<int> W, int X, int M, std::vector<int> S) { specialBus.speed = X; specialBus.num = N; for (int i = 0; i < N; i++) { bus b; b.num = i; b.speed = W[i]; b.time = T[i]; if (b.speed <= X) continue; // bus specialbus; // specialbus.speed = X; // specialbus.time = T[i]; // specialbus.num = N; busesGlobal.push_back(b); // busesGlobal.push_back(specialbus); } for (int i = 0; i < M; i++) { station stat; stat.dist = S[i]; stat.num = i; stationGlobal.push_back(stat); } sort(busesGlobal.begin(), busesGlobal.end()); stationGlobal[0].buses = busesGlobal; for (int i = 1; i < M; i++) { stationGlobal[i].get_buses(stationGlobal[i-1]); } return; } long long arrival_time(long long Y) { specialBus.time = Y; vector<station> a; for (int i = 1; i < stationGlobal.size(); i++) { ll time = stationGlobal[i].has_calculated_value(specialBus); if (time != 0) { specialBus.time = time; break; } specialBus.time = stationGlobal[i].get_arrival_time(specialBus); if (stationGlobal[i].addToMap != -1) { a.push_back(stationGlobal[i]); } } for (station b : a) { b.solved[b.addToMap] = specialBus.time; } return specialBus.time; // vector<bus> newVec; // newVec.insert(newVec.end(), busesGlobal.begin(), busesGlobal.end()); // newVec.push_back(specialBus); // sort(newVec.begin(), newVec.end()); // stationGlobal[0].buses = newVec; // for (int i = 1; i < stationGlobal.size(); i++) { // stationGlobal[i].get_buses(stationGlobal[i-1]); // } // // for (bus b : stationGlobal.back().buses) { // if (b.num == specialBus.num) return b.time; // } // return -1; }
#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...