Submission #883430

# Submission time Handle Problem Language Result Execution time Memory
883430 2023-12-05T09:18:02 Z alexdd Divide and conquer (IZhO14_divide) C++17
100 / 100
196 ms 38468 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[800005];
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[x[i]-prefd[i-1]]++;
    }
    mp[0]++;
    for(auto it:mp)
    {
        if(it.second==0)
            continue;
        nrm[it.first]=++cate;
    }
    build(1,1,cate);
    int mxm=0;
    for(int i=1;i<=n;i++)
    {
        upd(1,1,cate,nrm[x[i]-prefd[i-1]],-prefg[i-1]);
        mxm = max(mxm, prefg[i]+qry(1,1,cate,nrm[x[i]-prefd[i]],cate));
    }
    cout<<mxm;
    return 0;
}
/**
 
prefd[ri] - prefd[le-1] >= x[ri] - x[le]
prefd[ri] - x[ri] >= prefd[le-1] - x[le]
 
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4564 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 2 ms 4772 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
18 Correct 3 ms 4956 KB Output is correct
19 Correct 2 ms 4700 KB Output is correct
20 Correct 2 ms 4700 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 4 ms 4956 KB Output is correct
23 Correct 8 ms 8152 KB Output is correct
24 Correct 8 ms 8216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4564 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 2 ms 4772 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
18 Correct 3 ms 4956 KB Output is correct
19 Correct 2 ms 4700 KB Output is correct
20 Correct 2 ms 4700 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 4 ms 4956 KB Output is correct
23 Correct 8 ms 8152 KB Output is correct
24 Correct 8 ms 8216 KB Output is correct
25 Correct 8 ms 8028 KB Output is correct
26 Correct 13 ms 9548 KB Output is correct
27 Correct 15 ms 9560 KB Output is correct
28 Correct 80 ms 21064 KB Output is correct
29 Correct 85 ms 21332 KB Output is correct
30 Correct 196 ms 38468 KB Output is correct
31 Correct 169 ms 37312 KB Output is correct
32 Correct 166 ms 37288 KB Output is correct
33 Correct 167 ms 37200 KB Output is correct
34 Correct 164 ms 36276 KB Output is correct
35 Correct 191 ms 37544 KB Output is correct
36 Correct 176 ms 38056 KB Output is correct