Submission #241283

# Submission time Handle Problem Language Result Execution time Memory
241283 2020-06-23T16:12:09 Z abacaba Wall (IOI14_wall) C++14
0 / 100
221 ms 102136 KB
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <typename T> inline T range(T l, T r) {
    return uniform_int_distribution<T>(l, r)(rng);
}

inline void setin(string s) {
    freopen(s.c_str(), "r", stdin);
}

inline void setout(string s) {
    freopen(s.c_str(), "w", stdout);
}

template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}

template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int N = 2e6 + 15;

struct segment_tree {
    int mn[N << 2], mx[N << 2], add[N << 2];
    segment_tree() {
        memset(mn, 0, sizeof(mx));
        memset(mx, 0, sizeof(mx));
        memset(add, -1, sizeof(add));
    }
    inline void upd(int v, int x) {
        mn[v] = mx[v] = add[v] = x;
    }
    inline void push(int v) {
        if(v < (N << 1) && add[v] != -1) {
            upd(v << 1, add[v]);
            upd(v << 1 | 1, add[v]);

            add[v] = -1;
        }
    }
    void multiupdate(int v, int tl, int tr, int l, int r, int h, int type) {
        if(tl > r || tr < l || (type == 1 && mn[v] >= h) || (type == 2 && mx[v] <= h))
            return;
        push(v);
        if(tl >= l && tr <= r && ((type == 1 && mx[v] <= h) || (type == 2 && mn[v] >= h)))
            upd(v, h);
        else if(tl != tr) {
            int mid = tl + tr >> 1;
            multiupdate(v << 1, tl, mid, l, r, h, type);
            multiupdate(v << 1 | 1, mid + 1, tr, l, r, h, type);
            mn[v] = min(mn[v << 1], mn[v << 1 | 1]);
            mx[v] = max(mx[v << 1], mx[v << 1 | 1]);
        }
    }
    void output(int v, int tl, int tr, int finalHeight[]) {
        if(tl == tr)
            finalHeight[tl] = mn[v];
        else {
            push(v);
            int mid = tl + tr >> 1;
            output(v << 1, tl, mid, finalHeight);
            output(v << 1 | 1, mid + 1, tr, finalHeight);
        }
    }
} t;

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
    for(int i = 0; i < n; ++i)
        t.multiupdate(1, 0, n - 1, left[i], right[i], height[i], op[i]);
    t.output(1, 0, n - 1, finalHeight);
}

Compilation message

wall.cpp: In member function 'void segment_tree::multiupdate(int, int, int, int, int, int, int)':
wall.cpp:90:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
             int mid = tl + tr >> 1;
                       ~~~^~~~
wall.cpp: In member function 'void segment_tree::output(int, int, int, int*)':
wall.cpp:102:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
             int mid = tl + tr >> 1;
                       ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 52 ms 94200 KB Output is correct
2 Incorrect 54 ms 94328 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 94328 KB Output is correct
2 Incorrect 221 ms 102136 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 94200 KB Output is correct
2 Incorrect 55 ms 94336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 94200 KB Output is correct
2 Incorrect 54 ms 94328 KB Output isn't correct
3 Halted 0 ms 0 KB -