Submission #321055

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
3210552020-11-10 19:14:40saarang123Discharging (NOI20_discharging)C++14
100 / 100
149 ms17508 KiB
#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
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#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...