Submission #1007669

# Submission time Handle Problem Language Result Execution time Memory
1007669 2024-06-25T10:00:46 Z farrellw Wall (IOI14_wall) C++14
100 / 100
440 ms 98152 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define INF 100005
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
 
#include "wall.h"
 
ii combine(ii upd_new, ii upd_old) {    // apply upd_new to upd_old
    ii res = {max(upd_new.fi, upd_old.fi), min(upd_new.se, upd_old.se)};
    if (res.fi > res.se) { // The ranges are disjoint, so suffices to check either
        return (upd_old.se < upd_new.se) ? make_pair(upd_new.fi, upd_new.fi) : make_pair(upd_new.se, upd_new.se);
    }
    return res;
}
 
struct Segtree {    // Segtree of updates
    int sz;
    vector<ii> upd;    // store (a, b)
    vi left;
    vi right;
    vi mid;
    Segtree(int N) {
        sz = 1;
        while (sz < N)
            sz *= 2;
        upd = vii(2 * sz, {0, INF});
        left = vi(2 * sz, 0);
        right = vi(2 * sz, 0);
        mid = vi(2 * sz, 0);
        for(int id = sz-1; id < 2*sz-1; id++) {
            left[id] = id-sz+1;
            right[id] = id-sz+2;
        }
        for(int id = sz-2; id >= 0; id--) {
            left[id] = left[(id<<1)|1];
            right[id] = right[2 * id + 2];
            mid[id] = (left[id] + right[id])>>1;
        }
    }
    void push(int id, int left, int right) { // O(1), for regular updates
        if (this->mid[id]) {
            upd[(id<<1)|1] = combine(upd[id], upd[(id<<1)|1]);
            upd[2 * id + 2] = combine(upd[id], upd[2 * id + 2]);
            upd[id] = {0, INF};
        }
    }
 
    void push_recursive(int id, int left, int right) { // O(N), only for answer extraction at the end
        if(this->mid[id]) {
            push(id, left, right);
            int mid = (left + right)>>1;
            push_recursive((id<<1)|1, this->left[id], this->mid[id]);
            push_recursive(2 * id + 2, this->mid[id], this->right[id]);
            return;
        }
    }
 
    void range_upd(int qleft, int qright, ii val, int id, int left, int right) {
        if (qleft <= left && right <= qright) {
            upd[id] = combine(val, upd[id]);
            return;
        }
        if (qright <= left || right <= qleft)
            return;
        push(id, left, right);
        int mid = (left + right)>>1;
        range_upd(qleft, qright, val, (id<<1)|1, this->left[id], this->mid[id]);
        range_upd(qleft, qright, val, 2 * id + 2, this->mid[id], this->right[id]);
    }
    void range_upd(int qleft, int qright, ii val) {
        range_upd(qleft, qright, val, 0, 0, sz);
    }
};
 
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
    Segtree tree(n);
    for(int z = 0; z < k; z++) {
        ii upd_val = (op[z] == 1) ? make_pair(height[z], INF) : make_pair(0, height[z]);
        tree.range_upd(left[z], right[z]+1, upd_val);
    }
    tree.push_recursive(0, 0, tree.sz);
    for(int z = 0; z < n; z++) {
        finalHeight[z] = tree.upd[z+tree.sz-1].fi;
    }
    return;
}

Compilation message

wall.cpp: In member function 'void Segtree::push_recursive(int, int, int)':
wall.cpp:55:17: warning: unused variable 'mid' [-Wunused-variable]
   55 |             int mid = (left + right)>>1;
      |                 ^~~
wall.cpp: In member function 'void Segtree::range_upd(int, int, ii, int, int, int)':
wall.cpp:70:13: warning: unused variable 'mid' [-Wunused-variable]
   70 |         int mid = (left + right)>>1;
      |             ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 4 ms 1116 KB Output is correct
5 Correct 3 ms 1116 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 71 ms 8252 KB Output is correct
3 Correct 96 ms 4952 KB Output is correct
4 Correct 320 ms 13556 KB Output is correct
5 Correct 163 ms 13648 KB Output is correct
6 Correct 146 ms 13624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 4 ms 1116 KB Output is correct
5 Correct 3 ms 1116 KB Output is correct
6 Correct 3 ms 1116 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 72 ms 8252 KB Output is correct
9 Correct 95 ms 5032 KB Output is correct
10 Correct 344 ms 13652 KB Output is correct
11 Correct 156 ms 13732 KB Output is correct
12 Correct 156 ms 13604 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 77 ms 8020 KB Output is correct
15 Correct 20 ms 2136 KB Output is correct
16 Correct 361 ms 13652 KB Output is correct
17 Correct 165 ms 13648 KB Output is correct
18 Correct 175 ms 13684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 4 ms 1116 KB Output is correct
5 Correct 3 ms 1116 KB Output is correct
6 Correct 3 ms 1116 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 71 ms 8064 KB Output is correct
9 Correct 100 ms 4944 KB Output is correct
10 Correct 335 ms 13652 KB Output is correct
11 Correct 159 ms 13592 KB Output is correct
12 Correct 153 ms 13648 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 77 ms 8188 KB Output is correct
15 Correct 21 ms 2140 KB Output is correct
16 Correct 372 ms 13780 KB Output is correct
17 Correct 174 ms 13652 KB Output is correct
18 Correct 183 ms 13616 KB Output is correct
19 Correct 438 ms 97960 KB Output is correct
20 Correct 389 ms 98152 KB Output is correct
21 Correct 412 ms 98092 KB Output is correct
22 Correct 422 ms 98128 KB Output is correct
23 Correct 392 ms 98124 KB Output is correct
24 Correct 400 ms 98132 KB Output is correct
25 Correct 377 ms 98132 KB Output is correct
26 Correct 440 ms 98128 KB Output is correct
27 Correct 406 ms 97992 KB Output is correct
28 Correct 404 ms 97972 KB Output is correct
29 Correct 403 ms 97984 KB Output is correct
30 Correct 409 ms 98028 KB Output is correct