Submission #405656

# Submission time Handle Problem Language Result Execution time Memory
405656 2021-05-16T16:23:20 Z fvogel499 Wall (IOI14_wall) C++14
100 / 100
2330 ms 63636 KB
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <queue>
#include <cstring>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>

using namespace std;

#define pii pair<int, int>
#define f first
#define s second

#define ll long long
#define rint int32_t

const int pow2 = 1<<21;

int minLz [pow2*2];
int maxLz [pow2*2];

void btClear() {
    for (int i = 0; i < pow2*2; i++) {
        minLz[i] = 0;
        maxLz[i] = 100000;
    }
}

void btPrpg(int qNode) {
    if (qNode >= pow2) return;

    if (minLz[qNode*2] < minLz[qNode]) minLz[qNode*2] = minLz[qNode];
    if (maxLz[qNode*2] > maxLz[qNode]) maxLz[qNode*2] = maxLz[qNode];
    if (minLz[qNode*2] > maxLz[qNode*2]) {
        if (minLz[qNode*2] <= minLz[qNode]) maxLz[qNode*2] = minLz[qNode];
        else minLz[qNode*2] = maxLz[qNode];
    }

    if (minLz[qNode*2+1] < minLz[qNode]) minLz[qNode*2+1] = minLz[qNode];
    if (maxLz[qNode*2+1] > maxLz[qNode]) maxLz[qNode*2+1] = maxLz[qNode];
    if (minLz[qNode*2+1] > maxLz[qNode*2+1]) {
        if (minLz[qNode*2+1] <= minLz[qNode]) maxLz[qNode*2+1] = minLz[qNode];
        else minLz[qNode*2+1] = maxLz[qNode];
    }

    minLz[qNode] = 0;
    maxLz[qNode] = 100000;
}

void btUpdate(int rBegin, int rEnd, int rUp, int rVal, int qNode, int qBegin, int qEnd) {
    if (rBegin > qEnd or qBegin > rEnd) return;
    else if (rBegin <= qBegin and qEnd <= rEnd) {
        if (rUp == 1 and minLz[qNode] < rVal) {
            minLz[qNode] = rVal;
            if (minLz[qNode] > maxLz[qNode]) {
                maxLz[qNode] = rVal;
            }
        }
        else if (rUp == 2 and maxLz[qNode] > rVal) {
            maxLz[qNode] = rVal;
            if (minLz[qNode] > maxLz[qNode]) {
                minLz[qNode] = rVal;
            }
        }
        btPrpg(qNode);
    }
    else {
        btPrpg(qNode);
        int qMid = (qBegin+qEnd)/2;
        btUpdate(rBegin, rEnd, rUp, rVal, qNode*2, qBegin, qMid);
        btUpdate(rBegin, rEnd, rUp, rVal, qNode*2+1, qMid+1, qEnd);
    }
}

void buildWall(int n, int nbReq, int up [], int left [], int right [], int height [], int res []) {
    btClear();
    for (int i = 0; i < n; i++) btUpdate(i, i, 2, 0, 1, 0, pow2-1);
    for (int i = 0; i < nbReq; i++) {
        // if (up[i] == 2) continue;
        btUpdate(left[i], right[i], up[i], height[i], 1, 0, pow2-1);
    }
    for (int i = 0; i < n; i++) {
        btUpdate(i, i, 1, 0, 1, 0, pow2-1);
        res[i] = minLz[pow2+i];
        // cout << "--> " << minLz[pow2+i] << "  -  " << maxLz[pow2+i] << endl; // dbg info
    }
    int d = 0;
    d++;
}

// rint main() {
//     cin.tie(0);
//     ios_base::sync_with_stdio(0);

//     int n = 10;
//     int nbReq = 6;
//     int up [6] = {1, 2, 2, 1, 1, 2};
//     int left [6] = {1, 4, 3, 0, 2, 6};
//     int right [6] = {8, 9, 6, 5, 2, 7};
//     int height [6] = {4, 1, 5, 3, 5, 0};
//     int res [6];
//     buildWall(n, nbReq, up, left, right, height, res);

//     int d = 0;
//     d++;
// }
# Verdict Execution time Memory Grader output
1 Correct 19 ms 33100 KB Output is correct
2 Correct 22 ms 33220 KB Output is correct
3 Correct 21 ms 33100 KB Output is correct
4 Correct 36 ms 33348 KB Output is correct
5 Correct 37 ms 33240 KB Output is correct
6 Correct 31 ms 33312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 33092 KB Output is correct
2 Correct 341 ms 45436 KB Output is correct
3 Correct 294 ms 40164 KB Output is correct
4 Correct 780 ms 45976 KB Output is correct
5 Correct 479 ms 46472 KB Output is correct
6 Correct 463 ms 46428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 33100 KB Output is correct
2 Correct 24 ms 33228 KB Output is correct
3 Correct 21 ms 33100 KB Output is correct
4 Correct 34 ms 33260 KB Output is correct
5 Correct 31 ms 33328 KB Output is correct
6 Correct 30 ms 33324 KB Output is correct
7 Correct 19 ms 33100 KB Output is correct
8 Correct 333 ms 45360 KB Output is correct
9 Correct 277 ms 40308 KB Output is correct
10 Correct 777 ms 45960 KB Output is correct
11 Correct 470 ms 46472 KB Output is correct
12 Correct 487 ms 46564 KB Output is correct
13 Correct 21 ms 33092 KB Output is correct
14 Correct 343 ms 45520 KB Output is correct
15 Correct 77 ms 34292 KB Output is correct
16 Correct 938 ms 46228 KB Output is correct
17 Correct 469 ms 46212 KB Output is correct
18 Correct 471 ms 46368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 33084 KB Output is correct
2 Correct 23 ms 33232 KB Output is correct
3 Correct 21 ms 33120 KB Output is correct
4 Correct 34 ms 33364 KB Output is correct
5 Correct 31 ms 33268 KB Output is correct
6 Correct 32 ms 33232 KB Output is correct
7 Correct 19 ms 33104 KB Output is correct
8 Correct 344 ms 45428 KB Output is correct
9 Correct 281 ms 40276 KB Output is correct
10 Correct 755 ms 45960 KB Output is correct
11 Correct 465 ms 46492 KB Output is correct
12 Correct 464 ms 46484 KB Output is correct
13 Correct 20 ms 33076 KB Output is correct
14 Correct 340 ms 45444 KB Output is correct
15 Correct 78 ms 34304 KB Output is correct
16 Correct 943 ms 46228 KB Output is correct
17 Correct 515 ms 46216 KB Output is correct
18 Correct 471 ms 46212 KB Output is correct
19 Correct 2147 ms 63448 KB Output is correct
20 Correct 2215 ms 60996 KB Output is correct
21 Correct 2172 ms 63636 KB Output is correct
22 Correct 2187 ms 61040 KB Output is correct
23 Correct 2176 ms 61008 KB Output is correct
24 Correct 2330 ms 61068 KB Output is correct
25 Correct 2205 ms 61012 KB Output is correct
26 Correct 2180 ms 63500 KB Output is correct
27 Correct 2171 ms 63600 KB Output is correct
28 Correct 2145 ms 61044 KB Output is correct
29 Correct 2135 ms 61032 KB Output is correct
30 Correct 2198 ms 61120 KB Output is correct