제출 #1247676

#제출 시각아이디문제언어결과실행 시간메모리
124767612baaterOvertaking (IOI23_overtaking)C++20
0 / 100
1 ms580 KiB
#include "overtaking.h" #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; 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 get_arrival_time(bus& b) { int place = distance(maxes.begin(), upper_bound(maxes.begin(), maxes.end(), make_pair(b.time, static_cast<ll>(0)))); if (place == maxes.size()) { return max((distDiff * b.speed) + b.time, maxes.back().second); } if (place == 0) { return (distDiff*b.speed) + b.time; } place--; 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; for (int i = 1; i < stationGlobal.size(); i++) { specialBus.time = stationGlobal[i].get_arrival_time(specialBus); } 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...