# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
321055 | saarang123 | Discharging (NOI20_discharging) | C++14 | 149 ms | 17508 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1e15;
const int N = 1502;
struct CHT {
struct Line {
int slope, c; //slope, yIntercept
Line(int slope, int c) : slope(slope), c(c) {}
int val(int xCoordinate) { return slope * xCoordinate + c; } //y coordinate
int intersect(Line other) { //ceiling of x coordinate of intersection
return (other.c - c + slope - other.slope - 1) / (slope - other.slope);
}
};
//Similar to monotonic queue
deque<pair<Line, int>> dq; //used to maintain the CHT
void add(int slope, int yIntersect) { //add new line
Line newLine(slope, yIntersect);
while(dq.size() > 1 && dq.back().second >= dq.back().first.intersect(newLine)) // <= if max is optimal
dq.pop_back(); //pop redundant(not optimal) lines
if(dq.empty())
dq.push_back(make_pair(newLine, 0)); //set 0 to -inf if -ve
else
dq.push_back(make_pair(newLine, dq.back().first.intersect(newLine)));
}
int qry(int xCoordinate) { //only if queries are monotonic - O(1) on average
while(dq.size() > 1) {
if(dq[1].second <= xCoordinate) dq.pop_front(); //finding optimal range for xCoord
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |