Submission #719597

# Submission time Handle Problem Language Result Execution time Memory
719597 2023-04-06T10:37:56 Z ovidiush11 Wall (IOI14_wall) C++14
0 / 100
156 ms 38748 KB
#include <bits/stdc++.h>
#include "wall.h"

using namespace std;

#define ll long long
#define mp make_pair
#define ff first
#define ss second

const ll inf = 1e18;

ll n,k;
vector<pair<ll,ll>> a;
vector<ll> pos;
vector<queue<ll>> vq;

void build(ll p,ll l,ll r)
{
    if(l == r)pos[l] = p;
    else
    {
        ll m = (l + r) / 2;
        build(p*2,l,m);
        build(p*2+1,m+1,r);
    }
    return ;
}

void change(ll p)
{
    if(p == 0)return ;
    ll mx = min(a[p*2].ss,a[p*2+1].ss);
    ll mn = max(a[p*2].ff,a[p*2+1].ff);
    if(mn > mx)
    {
        if(mn == a[p*2+1].ff)mx = mn;
        else mn = mx;
    }
    a[p] = mp(mn,mx);
    change(p/2);
    return ;
}

void buildWall(int N, int K, int op[], int left[], int right[], int height[], int finalHeight[])
{
    n = N;k = K;
    a.resize(n * 4);
    pos.resize(n * 4);
    vq.resize(n);
    build(1,0,n-1);
    for(ll i = 0;i < n*4;i++)a[i] = mp(0,inf);
    for(ll i = 0;i < k;i++)vq[left[i]].push(i+1);
    for(ll i = 0;i < k;i++)vq[right[i]].push(-i-1);
    for(ll i = 0;i < n;i++)
    {
        while(!vq[i].empty() && vq[i].front() > 0)
        {
            ll v = vq[i].front();
            vq[i].pop();
            v--;
            if(op[v] == 1)a[pos[v]].ff = height[v];
            else a[pos[v]].ss = height[v];
            change(pos[v]/2);
        }
        finalHeight[i] = a[1].ff;
        while(!vq[i].empty())
        {
            ll v = vq[i].front();
            vq[i].pop();
            v++;
            a[pos[-v]] = mp(0,inf);
            change(pos[-v]/2);
        }
    }
    return ;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 3 ms 724 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 156 ms 38748 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 3 ms 688 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 3 ms 724 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -