Submission #883381

# Submission time Handle Problem Language Result Execution time Memory
883381 2023-12-05T08:44:48 Z alexdd Divide and conquer (IZhO14_divide) C++17
Compilation error
0 ms 0 KB
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];
    int mij=(st+dr)/2;
    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,1,nrm[x[i]-prefd[i]]));
    }
    cout<<mxm;
    return 0;
}

Compilation message

divide.cpp:1:1: error: 'include' does not name a type
    1 | include <bits/stdc++.h>
      | ^~~~~~~
divide.cpp:11:1: error: 'map' does not name a type
   11 | map<int,int> mp;
      | ^~~
divide.cpp:12:1: error: 'map' does not name a type
   12 | map<int,int> nrm;
      | ^~~
divide.cpp: In function 'void upd(long long int, long long int, long long int, long long int, long long int)':
divide.cpp:28:21: error: 'max' was not declared in this scope
   28 |         aint[nod] = max(aint[nod],newv);
      |                     ^~~
divide.cpp:34:17: error: 'max' was not declared in this scope
   34 |     aint[nod] = max(aint[nod*2], aint[nod*2+1]);
      |                 ^~~
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:43:36: error: 'min' was not declared in this scope; did you mean 'mij'?
   43 |     return max(qry(nod*2,st,mij,le,min(mij,ri)),
      |                                    ^~~
      |                                    mij
divide.cpp:44:38: error: 'max' was not declared in this scope
   44 |                 qry(nod*2+1,mij+1,dr,max(mij+1,le),ri));
      |                                      ^~~
divide.cpp:43:12: error: 'max' was not declared in this scope
   43 |     return max(qry(nod*2,st,mij,le,min(mij,ri)),
      |            ^~~
divide.cpp: In function 'int main()':
divide.cpp:48:5: error: 'cin' was not declared in this scope
   48 |     cin>>n;
      |     ^~~
divide.cpp:54:9: error: 'mp' was not declared in this scope
   54 |         mp[x[i]-prefd[i]]++;
      |         ^~
divide.cpp:56:5: error: 'mp' was not declared in this scope
   56 |     mp[0]++;
      |     ^~
divide.cpp:61:9: error: 'nrm' was not declared in this scope
   61 |         nrm[it.first]=++cate;
      |         ^~~
divide.cpp:65:18: error: 'nrm' was not declared in this scope
   65 |     upd(1,1,cate,nrm[0],0);
      |                  ^~~
divide.cpp:69:15: error: 'max' was not declared in this scope
   69 |         mxm = max(mxm, g[i]+qry(1,1,cate,1,nrm[x[i]-prefd[i]]));
      |               ^~~
divide.cpp:71:5: error: 'cout' was not declared in this scope
   71 |     cout<<mxm;
      |     ^~~~