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"holiday.h"
#include <bits/stdc++.h>
#define PB push_back
#define F first
#define S second
using namespace std;
int att[100000];
struct segTree{
long long dd, ht, mid, val1, val2;
segTree *L, *R;
segTree(int l, int r){
dd=l;
ht=r;
mid=(dd+ht)/2;
if(dd!=ht){
L=new segTree(l, mid);
R=new segTree(mid+1, r);
}
val1=0;
val2=0;
}
void encender(int ps, bool enc){
if(dd==ht){
if(enc){
val1++;
val2+=att[ps];
}else{
val1=0;
val2=0;
}
return ;
}else{
if(ps<=mid)L->encender(ps, enc);
else R->encender(ps, enc);
val1=L->val1+R->val1;
val2=L->val2+R->val2;
}
}
long long query(int cant){
if(cant==val1)return val2;
if(cant<=R->val1){
return R->query(cant);
}else if(cant>R->val1){
if(cant>L->val1){
cant=L->val1+R->val1;
}
return R->val2+L->query((cant-R->val1));
}
}
};
long long int findMaxAttraction(int n, int start, int d, int attraction[]) {
for(int i = 0 ; i < n ; i++)att[i]=attraction[i];
//priority_queue<long long>pq;
long long total = 0;
segTree *st=new segTree(0, 101);
for(int i = 0 ; i <= d-1 ; i++){
//if(start+i<n)pq.push(attraction[i+start]);
for(int j = 0 ; j<= (d-i) && (start-j)>=0; j++){
st->encender(att[i], true);
total=max(total, st->query((d-i)));
}
}
return total;
}
Compilation message (stderr)
holiday.cpp: In member function 'long long int segTree::query(int)':
holiday.cpp:49:5: warning: control reaches end of non-void function [-Wreturn-type]
49 | }
| ^
# | 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... |