Submission #1062947

# Submission time Handle Problem Language Result Execution time Memory
1062947 2024-08-17T12:19:08 Z andrei_iorgulescu Wall (IOI14_wall) C++14
100 / 100
2466 ms 161908 KB
#include <bits/stdc++.h>
#include "wall.h"
#warning That's not FB, that's my FB

using namespace std;

struct node
{
    int mx = 0, mx2 = -1, mn = 0, mn2 = -1;
};

vector<node> aint;

void prop(int nod, int l, int r)
{
    if (l == r)
        return;
    aint[2 * nod].mx = min(aint[2 * nod].mx, aint[nod].mx);
    aint[2 * nod].mn = min(aint[2 * nod].mn, aint[nod].mx);
    aint[2 * nod].mx = max(aint[2 * nod].mx, aint[nod].mn);
    aint[2 * nod].mn = max(aint[2 * nod].mn, aint[nod].mn);
    aint[2 * nod + 1].mx = min(aint[2 * nod + 1].mx, aint[nod].mx);
    aint[2 * nod + 1].mn = min(aint[2 * nod + 1].mn, aint[nod].mx);
    aint[2 * nod + 1].mx = max(aint[2 * nod + 1].mx, aint[nod].mn);
    aint[2 * nod + 1].mn = max(aint[2 * nod + 1].mn, aint[nod].mn);

    if (aint[2 * nod].mn == aint[2 * nod].mx)
        aint[2 * nod].mx2 = aint[2 * nod].mn2 = -1;
    else
    {
        aint[2 * nod].mx2 = max(aint[2 * nod].mx2, aint[nod].mn);
        aint[2 * nod].mn2 = min(aint[2 * nod].mn2, aint[nod].mx);
    }

    if (aint[2 * nod + 1].mn == aint[2 * nod + 1].mx)
        aint[2 * nod + 1].mx2 = aint[2 * nod + 1].mn2 = -1;
    else
    {
        aint[2 * nod + 1].mx2 = max(aint[2 * nod + 1].mx2, aint[nod].mn);
        aint[2 * nod + 1].mn2 = min(aint[2 * nod + 1].mn2, aint[nod].mx);
    }
}

void update(int nod, int l, int r, int st, int dr, int tip, int h)
{
    if (r < st or dr < l)
        return;
    prop(nod,l,r);
    if (st <= l and r <= dr)
    {
        if (tip == 1)
        {
            if (h <= aint[nod].mn)
                return;
            if (aint[nod].mn2 == -1 or h < aint[nod].mn2)
            {
                if (aint[nod].mx2 == aint[nod].mn)
                    aint[nod].mx2 = h;
                //aint[nod].lazy_tag_min = true;
                aint[nod].mn = h;
                if (aint[nod].mn2 == -1)
                {
                    //aint[nod].lazy_tag_max = true;
                    aint[nod].mx = h;
                }
                //cout << "wow" << nod << ' ' << l << ' ' << r << endl;
                return;
            }
        }
        else
        {
            if (h >= aint[nod].mx)
                return;
            if (aint[nod].mx2 == -1 or h > aint[nod].mx2)
            {
                if (aint[nod].mn2 == aint[nod].mx)
                    aint[nod].mn2 = h;
                //aint[nod].lazy_tag_max = true;
                aint[nod].mx = h;
                if (aint[nod].mx2 == -1)
                {
                    //aint[nod].lazy_tag_min = true;
                    aint[nod].mn = h;
                }
                return;
            }
        }
    }
    //cout << nod << ' ' << l << ' ' << r << endl;
    int mij = (l + r) / 2;
    update(2 * nod, l, mij, st, dr, tip, h);
    update(2 * nod + 1, mij + 1, r, st, dr, tip, h);
    vector<int> ele = {aint[2 * nod].mx, aint[2 * nod].mx2, aint[2 * nod].mn, aint[2 * nod].mn2, aint[2 * nod + 1].mx, aint[2 * nod + 1].mx2, aint[2 * nod + 1].mn, aint[2 * nod + 1].mn2};
    sort(ele.begin(),ele.end());
    vector<int> e2;
    for (int i = 0; i < 8; i++)
        if ((i == 0 or ele[i] != ele[i - 1]) and ele[i] != -1)
            e2.push_back(ele[i]);
    if (e2.size() == 1)
    {
        aint[nod].mx = aint[nod].mn = e2[0];
        aint[nod].mx2 = aint[nod].mn2 = -1;
    }
    else
    {
        int sz = e2.size();
        aint[nod].mx = e2[sz - 1];
        aint[nod].mx2 = e2[sz - 2];
        aint[nod].mn = e2[0];
        aint[nod].mn2 = e2[1];
    }
}

int query(int nod, int l, int r, int st, int dr)
{
    if (r < st or dr < l)
        return 0;
    prop(nod,l,r);
    if (st <= l and r <= dr)
        return aint[nod].mn;
    int mij = (l + r) / 2;
    return max(query(2 * nod,l,mij,st,dr), query(2 * nod + 1,mij + 1,r,st,dr));
}

void buildWall (int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
    aint.resize(4 * n + 5);
    for (int i = 0; i < k; i++)
    {
        left[i]++;
        right[i]++;
        update(1,1,n,left[i],right[i],op[i],height[i]);
    }
    for (int i = 0; i < n; i++)
        finalHeight[i] = query(1,1,n,i + 1,i + 1);
}

///hai sa vedem daca iese si cu beats :)

Compilation message

wall.cpp:3:2: warning: #warning That's not FB, that's my FB [-Wcpp]
    3 | #warning That's not FB, that's my FB
      |  ^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 4 ms 480 KB Output is correct
4 Correct 18 ms 1184 KB Output is correct
5 Correct 15 ms 1116 KB Output is correct
6 Correct 15 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 86 ms 8020 KB Output is correct
3 Correct 432 ms 4944 KB Output is correct
4 Correct 1241 ms 15040 KB Output is correct
5 Correct 665 ms 15588 KB Output is correct
6 Correct 706 ms 15552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 19 ms 1188 KB Output is correct
5 Correct 20 ms 1116 KB Output is correct
6 Correct 16 ms 1116 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 86 ms 8244 KB Output is correct
9 Correct 438 ms 4900 KB Output is correct
10 Correct 1270 ms 15040 KB Output is correct
11 Correct 687 ms 15552 KB Output is correct
12 Correct 728 ms 15364 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 83 ms 8140 KB Output is correct
15 Correct 100 ms 2132 KB Output is correct
16 Correct 1980 ms 15224 KB Output is correct
17 Correct 839 ms 15304 KB Output is correct
18 Correct 815 ms 15184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 18 ms 1184 KB Output is correct
5 Correct 24 ms 1116 KB Output is correct
6 Correct 19 ms 1116 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 80 ms 8020 KB Output is correct
9 Correct 434 ms 4892 KB Output is correct
10 Correct 1263 ms 14928 KB Output is correct
11 Correct 730 ms 15444 KB Output is correct
12 Correct 704 ms 15552 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 92 ms 8192 KB Output is correct
15 Correct 101 ms 1996 KB Output is correct
16 Correct 1876 ms 15296 KB Output is correct
17 Correct 912 ms 15188 KB Output is correct
18 Correct 814 ms 15292 KB Output is correct
19 Correct 2359 ms 151436 KB Output is correct
20 Correct 2466 ms 159380 KB Output is correct
21 Correct 2320 ms 161860 KB Output is correct
22 Correct 2326 ms 159604 KB Output is correct
23 Correct 2404 ms 159560 KB Output is correct
24 Correct 2379 ms 159416 KB Output is correct
25 Correct 2384 ms 159304 KB Output is correct
26 Correct 2294 ms 161908 KB Output is correct
27 Correct 2354 ms 161860 KB Output is correct
28 Correct 2310 ms 159316 KB Output is correct
29 Correct 2306 ms 159312 KB Output is correct
30 Correct 2314 ms 159324 KB Output is correct