답안 #864000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
864000 2023-10-21T16:34:52 Z thegamercoder19 벽 (IOI14_wall) C++14
100 / 100
840 ms 224808 KB
#include "wall.h"
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846
#define FILER 0
using ll = int;
using ull = unsigned long long;
using ld = long double;
const ll MOD = pow(10, 9) + 7;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const ull INFUL = 0x3f3f3f3f3f3f3f3f;
const ll INFT = 0x3f3f3f3f;
const ull MAX = 1LL << 24;
const ll MODD = 998244353;
const double EPS = 1e-10;
#define V vector
#define pll pair<ll, ll>
#define pull2 pair<ull,ull>
#define MS multiset
#define M map
#define Q queue
#define PQ priority_queue
#define IOF ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(typ,i,a,b,c) for(typ i = a; i < b; i += c)
#define FORR(typ,i,a,b,c) for(typ i = a; i > b; i -= c)
#define FORA(a,i) for(auto &i : a)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define sorta(a) sort(all(a))
#define sortd(a) sort(all(a), greater<ll>())
#define setp(x) setprecision(x)<<fixed
#define RET return
#define log(a,b) log(b)/log(a)
#define WH(s) while(s)
#define WHI(t) WH(t--)
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define YESNO(s) cout << (s ? "YES" : "NO") << endl;
#define YesNo(s) cout<<(s?"Yes":"No")<<endl;
#define TYP 0
using namespace std;


struct node
{
    ll mx, smx, cmx, mn, smn, cmn;
};

V<node> st;
ll n, q, c, l, r, h;
void merge(ll u)
{

    if (st[u << 1].mx == st[u << 1 | 1].mx)
    {
        st[u].cmx = st[u << 1].cmx + st[u << 1 | 1].cmx;
        st[u].mx = st[u << 1].mx;
        st[u].smx = max(st[u << 1].smx, st[u << 1 | 1].smx);
    }
    else
    {
        st[u].mx = max(st[u << 1].mx, st[u << 1 | 1].mx);
        if (st[u << 1].mx > st[u << 1 | 1].mx)
        {
            st[u].smx = max(st[u << 1].smx, st[u << 1 | 1].mx);
            st[u].cmx = st[u << 1].cmx;
        }
        else
        {
            st[u].smx = max(st[u << 1 | 1].smx, st[u << 1].mx);
            st[u].cmx = st[u << 1 | 1].cmx;
        }
    }

    if (st[u << 1].mn == st[u << 1 | 1].mn)
    {
        st[u].cmn = st[u << 1].cmn + st[u << 1 | 1].cmn;
        st[u].mn = st[u << 1].mn;
        st[u].smn = min(st[u << 1].smn, st[u << 1 | 1].smn);
    }
    else
    {
        st[u].mn = min(st[u << 1].mn, st[u << 1 | 1].mn);
        if (st[u << 1].mn < st[u << 1 | 1].mn)
        {
            st[u].smn = min(st[u << 1].smn, st[u << 1 | 1].mn);
            st[u].cmn = st[u << 1].cmn;
        }
        else
        {
            st[u].smn = min(st[u << 1 | 1].smn, st[u << 1].mn);
            st[u].cmn = st[u << 1 | 1].cmn;
        }
    }
}

void push_min(ll u, ll h, ll l, ll r)
{
    if (h <= st[u].mn)RET;
    st[u].mn = h;
    if (l == r)st[u].mx = st[u].mn;
    else
    {
        if (st[u].mx <= h)st[u].mx = h;
        else if (st[u].smx < h)st[u].smx = h;
    }
}


void push_max(ll u, ll h, ll l, ll r)
{
    if (h >= st[u].mx)RET;
    st[u].mx = h;
    if (l == r)st[u].mn = st[u].mx;
    else
    {
        if (st[u].mn >= h)st[u].mn = h;
        else if (st[u].smn > h)st[u].smn = h;
    }
}

void push_down(ll u, ll l, ll r)
{
    ll m = (l + r) >> 1;
    push_max(u << 1, st[u].mx, l, m); push_max(u << 1 | 1, st[u].mx, m + 1, r);
    push_min(u << 1, st[u].mn, l, m); push_min(u << 1 | 1, st[u].mn, m + 1, r);
}


void add(ll u, ll l, ll r, ll ql, ll qr, ll h)
{
    if (l > r || qr < l || ql > r || st[u].mn >= h) RET;
    if (ql <= l && r <= qr && st[u].smn > h)
    {
        push_min(u, h, l, r);
        RET;
    }
    push_down(u, l, r);
    ll m = (l + r) >> 1;
    add(u << 1, l, m, ql, qr, h); add(u << 1 | 1, m + 1, r, ql, qr, h);
    merge(u);
}

void sub(ll u, ll l, ll r, ll ql, ll qr, ll h)
{
    if (l > r || qr < l || ql > r || st[u].mx <= h) RET;
    if (ql <= l && r <= qr && st[u].smx < h)
    {
        push_max(u, h, l, r);
        RET;
    }
    push_down(u, l, r);
    ll m = (l + r) >> 1;
    sub(u << 1, l, m, ql, qr, h); sub(u << 1 | 1, m + 1, r, ql, qr, h);
    merge(u);
}

ll get(ll u, ll l, ll r, ll p)
{
    if (l > r)RET 0;

    if (l == r)
        RET st[u].mn;
    push_down(u, l, r);
    ll m = (l + r) >> 1;
    if (p <= m)RET get(u << 1, l, m, p);
    RET get(u << 1 | 1, m + 1, r, p);
}

void build(ll u, ll l, ll r)
{
    if (l == r) { st[u].mx = st[u].mn = 0; st[u].smx = -INFL, st[u].smn = INFL; st[u].cmn = st[u].cmx = 1; RET; }
    ll m = (l + r) >> 1;
    build(u << 1, l, m); build(u << 1 | 1, m + 1, r);
    merge(u);
}


void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
    st.resize(4 * n + 4);
    build(1, 0, n - 1);
    FOR(ll, i, 0, k, 1)
    {
        if (op[i]==1) add(1, 0, n-1, left[i], right[i], height[i]);
        else sub(1, 0, n - 1, left[i], right[i], height[i]);
    }
    FOR(ll, i, 0, n, 1)finalHeight[i] = get(1, 0, n - 1, i);
}

Compilation message

wall.cpp:11:17: warning: overflow in conversion from 'long int' to 'll' {aka 'int'} changes value from '4557430888798830399' to '1061109567' [-Woverflow]
   11 | const ll INFL = 0x3f3f3f3f3f3f3f3f;
      |                 ^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 448 KB Output is correct
4 Correct 7 ms 1628 KB Output is correct
5 Correct 5 ms 1628 KB Output is correct
6 Correct 7 ms 1588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 102 ms 11164 KB Output is correct
3 Correct 62 ms 7504 KB Output is correct
4 Correct 141 ms 23308 KB Output is correct
5 Correct 148 ms 24076 KB Output is correct
6 Correct 181 ms 23316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 444 KB Output is correct
4 Correct 6 ms 1628 KB Output is correct
5 Correct 5 ms 1624 KB Output is correct
6 Correct 5 ms 1624 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 111 ms 11108 KB Output is correct
9 Correct 60 ms 7504 KB Output is correct
10 Correct 142 ms 23124 KB Output is correct
11 Correct 153 ms 23884 KB Output is correct
12 Correct 178 ms 23304 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 100 ms 11296 KB Output is correct
15 Correct 31 ms 2980 KB Output is correct
16 Correct 503 ms 23544 KB Output is correct
17 Correct 271 ms 23380 KB Output is correct
18 Correct 273 ms 23336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 6 ms 1628 KB Output is correct
5 Correct 5 ms 1412 KB Output is correct
6 Correct 5 ms 1624 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 102 ms 11092 KB Output is correct
9 Correct 55 ms 7324 KB Output is correct
10 Correct 141 ms 23124 KB Output is correct
11 Correct 148 ms 24048 KB Output is correct
12 Correct 177 ms 23128 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 104 ms 11140 KB Output is correct
15 Correct 29 ms 3152 KB Output is correct
16 Correct 514 ms 23496 KB Output is correct
17 Correct 277 ms 23292 KB Output is correct
18 Correct 268 ms 23380 KB Output is correct
19 Correct 840 ms 224808 KB Output is correct
20 Correct 797 ms 222256 KB Output is correct
21 Correct 798 ms 224680 KB Output is correct
22 Correct 783 ms 222200 KB Output is correct
23 Correct 802 ms 221988 KB Output is correct
24 Correct 775 ms 222144 KB Output is correct
25 Correct 831 ms 222104 KB Output is correct
26 Correct 802 ms 224596 KB Output is correct
27 Correct 836 ms 224508 KB Output is correct
28 Correct 786 ms 221952 KB Output is correct
29 Correct 803 ms 222048 KB Output is correct
30 Correct 778 ms 222032 KB Output is correct