Submission #883373

# Submission time Handle Problem Language Result Execution time Memory
883373 2023-12-05T08:37:17 Z alexdd Divide and conquer (IZhO14_divide) C++17
Compilation error
0 ms 0 KB
/******************************************************************************
                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
int n;
int x[100005];
int g[100005];
int d[100005];
int prefd[100005];
int prefg[100005];
map<int,int> mp;
map<int,int> nrm;
int cate=0;
int aint[400005];
void build(int nod, int st, int dr)
{
    aint[nod]=-INF;
    if(st==dr)
        return;
    int mij=(st+dr)/2;
    build(nod*2,st,mij);
    build(nod*2+1,mij+1,dr);
}
void upd(int nod, int st, int dr, int poz, int newv)
{
    if(st==dr)
    {
        aint[nod] = max(aint[nod],newv);
        return;
    }
    int mij=(st+dr)/2;
    if(poz<=mij) upd(nod*2,st,mij,poz,newv);
    else upd(nod*2+1,mij+1,dr,poz,newv);
    aint[nod] = max(aint[nod*2], aint[nod*2+1]);
}
int qry(int nod, int st, int dr, int le, int ri)
{
    if(le>ri)
        return -INF;
    if(le==st && dr==ri)
        return aint[nod];
    return max(qry(nod*2,st,mij,le,min(mij,ri)),
                qry(nod*2+1,mij+1,dr,max(mij+1,le),ri));
}
signed main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x[i]>>g[i]>>d[i];
        prefd[i] = prefd[i-1] + d[i];
        prefg[i] = prefg[i-1] + g[i];
        mp[x[i]-prefd[i]]++;
    }
    mp[0]++;
    for(auto it:mp)
    {
        if(it.second==0)
            continue;
        nrm[it.first]=++cate;
    }
    build(1,1,cate);
    int mxm=0;
    upd(1,1,cate,nrm[0],0);
    for(int i=1;i<=n;i++)
    {
        upd(1,1,cate,nrm[x[i]-prefd[i]],-g[i]);
        mxm = max(mxm, g[i]+qry(1,1,cate,nrm[x[i]-prefd[i]],cate));
    }
    cout<<mxm;
    return 0;
}

Compilation message

divide.cpp: In function 'long long int qry(long long int, long long int, long long int, long long int, long long int)':
divide.cpp:47:29: error: 'mij' was not declared in this scope
   47 |     return max(qry(nod*2,st,mij,le,min(mij,ri)),
      |                             ^~~