Submission #947599

# Submission time Handle Problem Language Result Execution time Memory
947599 2024-03-16T14:32:02 Z steveonalex Wall (IOI14_wall) C++11
100 / 100
2799 ms 214560 KB
#include <bits/stdc++.h>
#include "wall.h"

using namespace std;

 
typedef long long ll;
typedef unsigned long long ull;
 
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
 
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return 63 - __builtin_clzll(mask);}
 
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
 
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }
 
template <class T>
    void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }
 
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const int INF = 1e9 + 69;

struct SegmentTree{
    struct Node{
        int t, op, h;
        Node(int _t = -1, int _op = -1, int _h = -1){
            t = _t, op = _op, h = _h;
        }
    };

    int time = 0;

    int n;
    vector<pair<Node, Node>> a;

    SegmentTree(int _n){
        n = _n;
        a.resize(n * 4 + 4, {Node(0, 1, 0), Node(0, 2, 0)});
    }

    pair<Node, Node> combine(pair<Node, Node> a, pair<Node, Node> b){
        Node sigma_duck[] = {a.first, a.second, b.first, b.second};
        sort(sigma_duck, sigma_duck + 4, [] (Node a, Node b){return a.t < b.t;});
        pair<Node, Node> ans;
        for(Node i: sigma_duck){
            if (i.t == -1) continue;
            if (i.op == 1){
                if (maximize(ans.first.h, i.h)) {
                    ans.first = i;
                    if (ans.second.t != -1) maximize(ans.second.h, i.h);
                }
            }   
            else{
                if (ans.second.h == -1 || minimize(ans.second.h, i.h)) {
                    ans.second = i;
                    if (ans.first.t != -1) minimize(ans.first.h, i.h);
                }
            }
        }
        return ans;
    }

    void down(int id){
        a[id * 2] = combine(a[id * 2], a[id]);
        a[id * 2 + 1] = combine(a[id * 2 + 1], a[id]);
        a[id] = {Node(), Node()};
    }

    void update(int u, int v, int op, int h, int l, int r, int id){
        if (u <= l && r <= v) {
            if (op == 1) a[id] = combine(a[id], {Node(++time, op, h), Node()});
            else a[id] = combine(a[id], {Node(), Node(++time, op, h)});
            return;
        }
        down(id);
        int mid = (l + r) >> 1;
        if (u <= mid) update(u, v, op, h, l, mid, id * 2);
        if (v > mid) update(u, v, op, h, mid + 1, r, id * 2 + 1);
    }

    void update(int u, int v, int op, int h){update(u, v, op, h, 0, n-1, 1);}

    int get(int i, int l, int r, int id){
        if (l == r){
            return a[id].first.h;
        }
        down(id);
        int mid = (l + r) >> 1;
        if (i <= mid) return get(i, l, mid, id * 2);
        return get(i, mid + 1, r, id * 2 + 1);
    }

    int get(int i){return get(i, 0, n-1, 1);}
};

void buildWall(int n, int k, int op[], int left[], int right[],int height[], int finalHeight[]){
    SegmentTree st(n);
    for(int i = 0; i<k; ++i) st.update(left[i], right[i], op[i], height[i]);
    for(int i= 0; i<n; ++i) finalHeight[i] = st.get(i);
}

// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//     int n, q; cin >> n >> q;
//     SegmentTree st(n);
//     for(int i = 0; i<q; ++i){
//         int op, l, r, h; cin >> op >> l >> r >> h;
//         st.update(l, r, op, h);
//         for(int i = 0; i<n; ++i) cout << st.get(i) << " "; cout << "\n";
//     }


//     return 0;
// }
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 17 ms 1404 KB Output is correct
5 Correct 12 ms 1372 KB Output is correct
6 Correct 13 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 124 ms 14116 KB Output is correct
3 Correct 409 ms 7980 KB Output is correct
4 Correct 1132 ms 27732 KB Output is correct
5 Correct 613 ms 28072 KB Output is correct
6 Correct 552 ms 26568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 572 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 17 ms 1372 KB Output is correct
5 Correct 12 ms 1372 KB Output is correct
6 Correct 12 ms 1624 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 130 ms 13888 KB Output is correct
9 Correct 407 ms 9488 KB Output is correct
10 Correct 1179 ms 27584 KB Output is correct
11 Correct 568 ms 28088 KB Output is correct
12 Correct 544 ms 26504 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 122 ms 13908 KB Output is correct
15 Correct 79 ms 3124 KB Output is correct
16 Correct 1425 ms 27520 KB Output is correct
17 Correct 561 ms 26948 KB Output is correct
18 Correct 547 ms 26948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 17 ms 1372 KB Output is correct
5 Correct 13 ms 1412 KB Output is correct
6 Correct 12 ms 1372 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 120 ms 13976 KB Output is correct
9 Correct 418 ms 9228 KB Output is correct
10 Correct 1138 ms 27520 KB Output is correct
11 Correct 575 ms 28348 KB Output is correct
12 Correct 531 ms 26452 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 124 ms 13908 KB Output is correct
15 Correct 78 ms 2908 KB Output is correct
16 Correct 1407 ms 28052 KB Output is correct
17 Correct 556 ms 26872 KB Output is correct
18 Correct 558 ms 27072 KB Output is correct
19 Correct 2799 ms 214560 KB Output is correct
20 Correct 2735 ms 214444 KB Output is correct
21 Correct 2740 ms 214556 KB Output is correct
22 Correct 2720 ms 214368 KB Output is correct
23 Correct 2797 ms 214420 KB Output is correct
24 Correct 2777 ms 214384 KB Output is correct
25 Correct 2738 ms 214348 KB Output is correct
26 Correct 2796 ms 214336 KB Output is correct
27 Correct 2790 ms 214164 KB Output is correct
28 Correct 2755 ms 214248 KB Output is correct
29 Correct 2722 ms 214216 KB Output is correct
30 Correct 2733 ms 214408 KB Output is correct