Submission #726166

#TimeUsernameProblemLanguageResultExecution timeMemory
726166reitracnMeasures (CEOI22_measures)C++17
100 / 100
340 ms34564 KiB
#include<bits/stdc++.h>

using namespace std;
#define int long long

struct Nde
{
    int max, min, ans;
};

const int N = 2e5, INF = 1e18 + 5;

Nde segt[4*N + 5];
int lazy[4*N + 5];

Nde merge(Nde a, Nde b) // a est avant b
{
    Nde ret;
    ret.ans = max({a.ans, b.ans, a.max - b.min});
    ret.min = min(a.min, b.min);
    ret.max = max(a.max, b.max);
    return ret;
}

void update(int nde, int RB, int RE, int GB, int GE, int val)
{
    if(GB > RE || RB > GE)
    {
        return;
    }
    if(RB >= GB && RE <= GE)
    {
        if(GB == GE)
        {
            segt[nde]= {val+lazy[nde],val+lazy[nde],0};
        }
        else
        {
            segt[nde].max += val;
            segt[nde].min += val;
            lazy[nde]     += val;
        }
        return;
    } 
    for(int fils : {2*nde, 2*nde +1})
    {
        segt[fils].max += lazy[nde];
        segt[fils].min += lazy[nde];
        lazy[fils] += lazy[nde];
    }
    lazy[nde] = 0;
    int MID = (RB + RE)/2;
    update(2*nde, RB, MID, GB, GE, val);
    update(2*nde +1, MID+1, RE, GB, GE, val);
    segt[nde] = merge(segt[2*nde], segt[2*nde +1]);
}


signed main()
{
    int nbInit, nbQ, D;
    scanf("%lld%lld%lld", &nbInit, &nbQ, &D);
    fill_n(segt, 4*N + 5, Nde{-INF, INF, -INF});
    vector<int> pos(nbInit + nbQ), idx(nbInit + nbQ);
    vector<pair<int, int>> a(nbInit + nbQ);
    for(int iQ = 0; iQ < nbInit + nbQ; iQ++)
    {   
        scanf("%lld", &pos[iQ]);
        a[iQ] = {pos[iQ], iQ};
    }
    sort(a.begin(), a.end());
    for(int iQ = 0; iQ < nbInit + nbQ; iQ++)
    {
        idx[a[iQ].second]= iQ;
    }
    for(int iQ = 0; iQ< nbInit + nbQ; iQ++)
    {
        int posAct = pos[iQ];
        int idxAct = idx[iQ];
        update(1, 0, nbInit + nbQ+4, idxAct, idxAct, posAct);
        update(1, 0, nbInit + nbQ+4, idxAct+1, nbInit + nbQ+4, -D);
        if(iQ >= nbInit)
        {
            int ans = segt[1].ans;
            printf("%lld", ans/2);
            if(ans %2 == 1)
            {
                printf(".5");
            }
            printf(" ");
        }

    }
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     scanf("%lld%lld%lld", &nbInit, &nbQ, &D);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         scanf("%lld", &pos[iQ]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...