# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
244917 | Red_Inside | Fireworks (APIO16_fireworks) | C++17 | 230 ms | 50332 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.
/*
* Author: Seokhwan Choi
* Time Complexity: O((N+M) (log (N+M))^2 )
*/
#include<stdio.h>
#include<queue>
#define MAXN 300100
int n,m;
int p[MAXN];
int c[MAXN];
struct ndata{//contains data for subtree (y=f(x), where y is minimum cost when distance to all leaf node is x
long long int a,b;//y=ax+b at large x
std::priority_queue<long long int> *pq;//saves slope changing points, slope change by 1 at each element
ndata operator+(ndata r){//merge two data by adding them
ndata s;//result(merged data)
s.a=a+r.a;
s.b=b+r.b;
if(pq->size()>r.pq->size()){//merge smaller priority queue to larger priority queue
s.pq=pq;
while(r.pq->size()!=0){
s.pq->push(r.pq->top());
r.pq->pop();
}
}
else{
s.pq=r.pq;
while(pq->size()!=0){
s.pq->push(pq->top());
pq->pop();
Compilation message (stderr)
# | 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... |