Submission #424413

# Submission time Handle Problem Language Result Execution time Memory
424413 2021-06-11T22:40:39 Z APROHACK Holiday (IOI14_holiday) C++14
0 / 100
18 ms 1988 KB
#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

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
1 Runtime error 4 ms 1228 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 1964 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1228 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 18 ms 1988 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -