Submission #635264

# Submission time Handle Problem Language Result Execution time Memory
635264 2022-08-25T19:23:47 Z ghostwriter Wall (IOI14_wall) C++14
100 / 100
859 ms 107104 KB
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#include "grader.cpp"
#endif
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
    Tran The Bao
    CTL - Da Lat
    Cay ngay cay dem nhung deo duoc cong nhan
*/
const int oo = 1e9;
const int T = 8e6 + 1;
const int N = 2e6 + 1;
int n, k, ans[N];
pi tr[T];
pi comb(pi a, pi b) {
    pi rs = a;
    rs.st = min(rs.st, b.st);
    rs.nd = min(rs.nd, b.st);
    rs.nd = max(rs.nd, b.nd);
    return rs;
}
void lazy(int i, int l, int r) {
    if (l != r) {
        tr[i * 2] = comb(tr[i * 2], tr[i]);
        tr[i * 2 + 1] = comb(tr[i * 2 + 1], tr[i]);
        tr[i] = {oo, -oo};
    }
}
void upd(int i, int l, int r, int ql, int qr, pi v) {
    lazy(i, l, r);
    if (r < ql || l > qr) return;
    if (ql <= l && r <= qr) {
        tr[i] = comb(tr[i], v);
        lazy(i, l, r);
        return;
    }
    int mid = l + (r - l) / 2;
    upd(i * 2, l, mid, ql, qr, v);
    upd(i * 2 + 1, mid + 1, r, ql, qr, v);
}
void dfs(int i, int l, int r) {
    lazy(i, l, r);
    if (l == r) {
        ans[l] = max(0, tr[i].nd);
        return;
    }
    int mid = l + (r - l) / 2;
    dfs(i * 2, l, mid);
    dfs(i * 2 + 1, mid + 1, r);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
    ::n = n;
    ::k = k;
    FOR(i, 1, 4 * n) tr[i] = {oo, -oo};
    FOR(i, 0, k - 1) {
        int t = op[i], l = left[i], r = right[i], h = height[i];
        pi tmp;
        if (t == 1) tmp = {oo, h};
        else tmp = {h, -oo};
        upd(1, 0, n - 1, l, r, tmp);
    }
    dfs(1, 0, n - 1);
    FOR(i, 0, n - 1) finalHeight[i] = ans[i];
    return;
}
/*
10 6
1 1 8 4
2 4 9 1
2 3 6 5
1 0 5 3
1 2 2 5
2 6 7 0
*/

Compilation message

wall.cpp: In function 'void buildWall(int, int, int*, int*, int*, int*, int*)':
wall.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
wall.cpp:82:5: note: in expansion of macro 'FOR'
   82 |     FOR(i, 1, 4 * n) tr[i] = {oo, -oo};
      |     ^~~
wall.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
wall.cpp:83:5: note: in expansion of macro 'FOR'
   83 |     FOR(i, 0, k - 1) {
      |     ^~~
wall.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
wall.cpp:91:5: note: in expansion of macro 'FOR'
   91 |     FOR(i, 0, n - 1) finalHeight[i] = ans[i];
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 5 ms 852 KB Output is correct
5 Correct 5 ms 840 KB Output is correct
6 Correct 5 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 135 ms 13892 KB Output is correct
3 Correct 168 ms 8032 KB Output is correct
4 Correct 488 ms 21864 KB Output is correct
5 Correct 326 ms 22836 KB Output is correct
6 Correct 293 ms 21296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 6 ms 840 KB Output is correct
5 Correct 6 ms 852 KB Output is correct
6 Correct 6 ms 852 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 158 ms 13936 KB Output is correct
9 Correct 169 ms 8112 KB Output is correct
10 Correct 485 ms 21800 KB Output is correct
11 Correct 314 ms 22984 KB Output is correct
12 Correct 304 ms 21296 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 163 ms 13980 KB Output is correct
15 Correct 29 ms 2044 KB Output is correct
16 Correct 479 ms 22080 KB Output is correct
17 Correct 360 ms 21564 KB Output is correct
18 Correct 299 ms 21484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 6 ms 896 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 5 ms 892 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 131 ms 13904 KB Output is correct
9 Correct 186 ms 8116 KB Output is correct
10 Correct 458 ms 21796 KB Output is correct
11 Correct 297 ms 22864 KB Output is correct
12 Correct 295 ms 21296 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 140 ms 13960 KB Output is correct
15 Correct 28 ms 2028 KB Output is correct
16 Correct 484 ms 22164 KB Output is correct
17 Correct 301 ms 21484 KB Output is correct
18 Correct 368 ms 21480 KB Output is correct
19 Correct 780 ms 107088 KB Output is correct
20 Correct 814 ms 104764 KB Output is correct
21 Correct 777 ms 107096 KB Output is correct
22 Correct 764 ms 104648 KB Output is correct
23 Correct 747 ms 104616 KB Output is correct
24 Correct 796 ms 104644 KB Output is correct
25 Correct 854 ms 104552 KB Output is correct
26 Correct 819 ms 107068 KB Output is correct
27 Correct 859 ms 107104 KB Output is correct
28 Correct 795 ms 104612 KB Output is correct
29 Correct 786 ms 104652 KB Output is correct
30 Correct 816 ms 104572 KB Output is correct