답안 #726166

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
726166 2023-04-18T15:47:34 Z reitracn Measures (CEOI22_measures) C++17
100 / 100
340 ms 34564 KB
#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

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]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19136 KB Output is correct
2 Correct 10 ms 19140 KB Output is correct
3 Correct 10 ms 19136 KB Output is correct
4 Correct 10 ms 19156 KB Output is correct
5 Correct 10 ms 19156 KB Output is correct
6 Correct 13 ms 19132 KB Output is correct
7 Correct 10 ms 19156 KB Output is correct
8 Correct 10 ms 19108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19136 KB Output is correct
2 Correct 10 ms 19140 KB Output is correct
3 Correct 10 ms 19136 KB Output is correct
4 Correct 10 ms 19156 KB Output is correct
5 Correct 10 ms 19156 KB Output is correct
6 Correct 13 ms 19132 KB Output is correct
7 Correct 10 ms 19156 KB Output is correct
8 Correct 10 ms 19108 KB Output is correct
9 Correct 270 ms 31392 KB Output is correct
10 Correct 245 ms 31444 KB Output is correct
11 Correct 196 ms 31316 KB Output is correct
12 Correct 245 ms 31380 KB Output is correct
13 Correct 224 ms 30852 KB Output is correct
14 Correct 203 ms 31348 KB Output is correct
15 Correct 264 ms 30720 KB Output is correct
16 Correct 194 ms 31456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 235 ms 30460 KB Output is correct
2 Correct 222 ms 32392 KB Output is correct
3 Correct 238 ms 32344 KB Output is correct
4 Correct 212 ms 30240 KB Output is correct
5 Correct 221 ms 31436 KB Output is correct
6 Correct 212 ms 30540 KB Output is correct
7 Correct 217 ms 31560 KB Output is correct
8 Correct 273 ms 30200 KB Output is correct
9 Correct 228 ms 30124 KB Output is correct
10 Correct 286 ms 32628 KB Output is correct
11 Correct 221 ms 31000 KB Output is correct
12 Correct 250 ms 32000 KB Output is correct
13 Correct 228 ms 30184 KB Output is correct
14 Correct 256 ms 32144 KB Output is correct
15 Correct 218 ms 32016 KB Output is correct
16 Correct 260 ms 30220 KB Output is correct
17 Correct 210 ms 31508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 235 ms 30460 KB Output is correct
2 Correct 222 ms 32392 KB Output is correct
3 Correct 238 ms 32344 KB Output is correct
4 Correct 212 ms 30240 KB Output is correct
5 Correct 221 ms 31436 KB Output is correct
6 Correct 212 ms 30540 KB Output is correct
7 Correct 217 ms 31560 KB Output is correct
8 Correct 273 ms 30200 KB Output is correct
9 Correct 228 ms 30124 KB Output is correct
10 Correct 286 ms 32628 KB Output is correct
11 Correct 221 ms 31000 KB Output is correct
12 Correct 250 ms 32000 KB Output is correct
13 Correct 228 ms 30184 KB Output is correct
14 Correct 256 ms 32144 KB Output is correct
15 Correct 218 ms 32016 KB Output is correct
16 Correct 260 ms 30220 KB Output is correct
17 Correct 210 ms 31508 KB Output is correct
18 Correct 288 ms 30620 KB Output is correct
19 Correct 291 ms 34248 KB Output is correct
20 Correct 262 ms 34236 KB Output is correct
21 Correct 242 ms 32244 KB Output is correct
22 Correct 276 ms 32620 KB Output is correct
23 Correct 263 ms 32412 KB Output is correct
24 Correct 340 ms 32928 KB Output is correct
25 Correct 254 ms 32052 KB Output is correct
26 Correct 276 ms 32156 KB Output is correct
27 Correct 287 ms 34564 KB Output is correct
28 Correct 257 ms 32492 KB Output is correct
29 Correct 262 ms 33944 KB Output is correct
30 Correct 271 ms 32004 KB Output is correct
31 Correct 263 ms 34076 KB Output is correct
32 Correct 264 ms 33952 KB Output is correct
33 Correct 286 ms 31692 KB Output is correct
34 Correct 266 ms 33368 KB Output is correct