Submission #379072

#TimeUsernameProblemLanguageResultExecution timeMemory
379072leinad2Holiday (IOI14_holiday)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;
struct node
{
    int l, r, v;
    long long sum;
}nd;
node pst[2000010];
map<int, int>x;
map<int, int>::iterator it;
int t, n, q, a, b, c, i, j, sz, d, rt, cnt, root[100010], opt[100010], X[100010], A[100010], st;
long long dap=-1e18;
void make_node(){pst[sz++]={-1, -1, 0, 0};}
void init(int id, int s, int e)
{
    if(s==e)return;
    int m=s+e>>1;
    if(pst[id].l==-1)
    {
        pst[id].l=sz;
        make_node();
    }
    init(pst[id].l, s, m);
    if(pst[id].r==-1)
    {
        pst[id].r=sz;
        make_node();
    }
    init(pst[id].r, m+1, e);
}
void update(int prev, int id, int s, int e, int x)
{
    pst[id].v=pst[prev].v+1;
    pst[id].sum=pst[prev].sum+X[x];
    if(s==e)return;
    int m=s+e>>1;
    if(x<=m)
    {
        pst[id].l=sz;
        make_node();
        pst[id].r=pst[prev].r;
        update(pst[prev].l, pst[id].l, s, m, x);
    }
    else
    {
        pst[id].r=sz;
        make_node();
        pst[id].l=pst[prev].l;
        update(pst[prev].r, pst[id].r, m+1, e, x);
    }
}
long long get(int prev, int id, int s, int e, int k)
{
    if(s==e)
    {
        if(X[s])return min(k, (int)(pst[id].sum-pst[prev].sum)/X[s])*X[s];
        return 0;
    }
    long long d=pst[pst[id].r].sum-pst[pst[prev].r].sum;
    int ee=pst[pst[id].r].v-pst[pst[prev].r].v;
    int m=s+e>>1;
    if(k<=ee)return get(pst[prev].r, pst[id].r, m+1, e, k);
    else return d+get(pst[prev].l, pst[id].l, s, m, k-ee);
}
void dnc(int s, int e, int l, int r)
{
    if(s>e)return;
    int mid=s+e>>1;
    long long ans=-1e18;
    int pos;
    for(int i=l;i<=r;i++)
    {
        if(d-(i+st-2*mid)<0)continue;
        long long res=get(root[mid-1], root[max(st, i)], 1, cnt, d-(i+st-2*mid));
        if(ans<res)
        {
            ans=res;
            pos=i;
        }
    }
    dap=max(dap, ans);
    opt[mid]=pos;
    dnc(s, mid-1, l, pos);
    dnc(mid+1, e, pos, r);
}
void rev(int a, int b)
{
    if(a>=b)return;
    swap(A[a], A[b]);
    rev(a+1, b-1);
}
main()
{
    for(scanf("%d %d %d", &n, &st, &d);i++<n;)
    {
        scanf("%d", &A[i]);
        x[A[i]]++;
    }
    for(it=x.begin();it!=x.end();it++)it->second=++cnt,X[cnt]=it->first;
    make_node();
    init(0, 1, cnt);
    for(i=0;i++<n;)
    {
        A[i]=x[A[i]];
        root[i]=sz;
        make_node();
        update(root[i-1], root[i], 1, cnt, A[i]);
    }
    dnc(1, st, 1, n);
    sz=0;
    make_node();
    init(0, 1, cnt);
    rev(1, n);
    for(i=0;i++<n;)
    {
        root[i]=sz;
        make_node();
        update(root[i-1], root[i], 1, cnt, A[i]);
    }
    st=n+1-st;
    dnc(1, st, 1, n);
    cout<<dap;
}

Compilation message (stderr)

holiday.cpp: In function 'void init(int, int, int)':
holiday.cpp:17:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   17 |     int m=s+e>>1;
      |           ~^~
holiday.cpp: In function 'void update(int, int, int, int, int)':
holiday.cpp:36:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |     int m=s+e>>1;
      |           ~^~
holiday.cpp: In function 'long long int get(int, int, int, int, int)':
holiday.cpp:61:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   61 |     int m=s+e>>1;
      |           ~^~
holiday.cpp: In function 'void dnc(int, int, int, int)':
holiday.cpp:68:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   68 |     int mid=s+e>>1;
      |             ~^~
holiday.cpp: At global scope:
holiday.cpp:92:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   92 | main()
      |      ^
holiday.cpp: In function 'int main()':
holiday.cpp:94:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   94 |     for(scanf("%d %d %d", &n, &st, &d);i++<n;)
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
holiday.cpp:96:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   96 |         scanf("%d", &A[i]);
      |         ~~~~~^~~~~~~~~~~~~
holiday.cpp: In function 'void dnc(int, int, int, int)':
holiday.cpp:83:8: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   83 |     dnc(s, mid-1, l, pos);
      |     ~~~^~~~~~~~~~~~~~~~~~
/tmp/ccRZCw18.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccBWFE09.o:holiday.cpp:(.text.startup+0x0): first defined here
/tmp/ccRZCw18.o: In function `main':
grader.cpp:(.text.startup+0x8c): undefined reference to `findMaxAttraction(int, int, int, int*)'
collect2: error: ld returned 1 exit status