Submission #280096

# Submission time Handle Problem Language Result Execution time Memory
280096 2020-08-22T13:30:04 Z SamAnd Wall (IOI14_wall) C++17
100 / 100
1057 ms 205336 KB
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
const int N = 2000006;

vector<int> v[N];
int op[N], height[N];

struct ban
{
    int l, r;
    int u;
    ban()
    {
        l = 0;
        r = N;
        u = -1;
    }
    ban(int ty, int h)
    {
        if (ty == 1)
        {
            l = h;
            r = N;
            u = -1;
        }
        else
        {
            l = 0;
            r = h;
            u = -1;
        }
    }
    ban(int l, int r, int u)
    {
        this->l = l;
        this->r = r;
        this->u = u;
    }
};

ban t[N * 4];

ban mer(const ban& l, const ban& r)
{
    if (r.u != -1)
        return r;
    if (l.u != -1)
    {
        if (r.l <= l.u && l.u <= r.r)
            return l;
        if (l.u < r.l)
            return ban(-1, -1, r.l);
        return ban(-1, -1, r.r);
    }
    if (l.l > r.r)
        return ban(-1, -1, r.r);
    if (l.r < r.l)
        return ban(-1, -1, r.l);
    return ban(max(l.l, r.l), min(l.r, r.r), -1);
}

void ubd(int tl, int tr, int x, bool z, int pos)
{
    if (tl == tr)
    {
        if (z)
            t[pos] = ban(op[x], height[x]);
        else
            t[pos] = ban();
        return;
    }
    int m = (tl + tr) / 2;
    if (x <= m)
        ubd(tl, m, x, z, pos * 2);
    else
        ubd(m + 1, tr, x, z, pos * 2 + 1);
    t[pos] = mer(t[pos * 2], t[pos * 2 + 1]);
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
    for (int i = 0; i < k; ++i)
    {
        ::op[i] = op[i];
        ::height[i] = height[i];
        v[left[i]].push_back(i + 1);
        v[right[i] + 1].push_back(-i - 1);
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < sz(v[i]); ++j)
        {
            int x = v[i][j];
            if (x > 0)
            {
                ubd(0, k - 1, x - 1, true, 1);
            }
            else
            {
                ubd(0, k - 1, -x - 1, false, 1);
            }
        }
        if (t[1].u != -1)
            finalHeight[i] = t[1].u;
        else
        {
            if (t[1].l <= 0 && 0 <= t[1].r)
                finalHeight[i] = 0;
            else
                finalHeight[i] = t[1].l;
        }
    }
}

# Verdict Execution time Memory Grader output
1 Correct 87 ms 141176 KB Output is correct
2 Correct 90 ms 141432 KB Output is correct
3 Correct 88 ms 141304 KB Output is correct
4 Correct 99 ms 141688 KB Output is correct
5 Correct 97 ms 141688 KB Output is correct
6 Correct 96 ms 141756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 141176 KB Output is correct
2 Correct 450 ms 159532 KB Output is correct
3 Correct 423 ms 152952 KB Output is correct
4 Correct 1057 ms 171248 KB Output is correct
5 Correct 668 ms 171384 KB Output is correct
6 Correct 682 ms 169576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 141180 KB Output is correct
2 Correct 91 ms 141516 KB Output is correct
3 Correct 92 ms 141292 KB Output is correct
4 Correct 94 ms 141688 KB Output is correct
5 Correct 95 ms 141668 KB Output is correct
6 Correct 96 ms 141728 KB Output is correct
7 Correct 93 ms 141180 KB Output is correct
8 Correct 445 ms 163172 KB Output is correct
9 Correct 418 ms 152932 KB Output is correct
10 Correct 1030 ms 171188 KB Output is correct
11 Correct 657 ms 171384 KB Output is correct
12 Correct 665 ms 169708 KB Output is correct
13 Correct 96 ms 141216 KB Output is correct
14 Correct 438 ms 162908 KB Output is correct
15 Correct 126 ms 143352 KB Output is correct
16 Correct 943 ms 171800 KB Output is correct
17 Correct 583 ms 169740 KB Output is correct
18 Correct 571 ms 169592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 141176 KB Output is correct
2 Correct 95 ms 141432 KB Output is correct
3 Correct 89 ms 141304 KB Output is correct
4 Correct 95 ms 141688 KB Output is correct
5 Correct 98 ms 141688 KB Output is correct
6 Correct 100 ms 141688 KB Output is correct
7 Correct 88 ms 141176 KB Output is correct
8 Correct 439 ms 162908 KB Output is correct
9 Correct 428 ms 152952 KB Output is correct
10 Correct 1036 ms 171332 KB Output is correct
11 Correct 673 ms 171384 KB Output is correct
12 Correct 638 ms 169652 KB Output is correct
13 Correct 87 ms 141176 KB Output is correct
14 Correct 411 ms 163036 KB Output is correct
15 Correct 125 ms 143480 KB Output is correct
16 Correct 923 ms 171512 KB Output is correct
17 Correct 565 ms 169720 KB Output is correct
18 Correct 563 ms 169464 KB Output is correct
19 Correct 830 ms 205304 KB Output is correct
20 Correct 818 ms 202616 KB Output is correct
21 Correct 851 ms 205228 KB Output is correct
22 Correct 831 ms 202872 KB Output is correct
23 Correct 822 ms 202616 KB Output is correct
24 Correct 825 ms 202720 KB Output is correct
25 Correct 823 ms 202580 KB Output is correct
26 Correct 831 ms 205336 KB Output is correct
27 Correct 830 ms 205172 KB Output is correct
28 Correct 821 ms 202628 KB Output is correct
29 Correct 828 ms 202624 KB Output is correct
30 Correct 864 ms 202740 KB Output is correct