답안 #289152

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
289152 2020-09-02T12:14:08 Z stoyan_malinin 벽 (IOI14_wall) C++14
0 / 100
3000 ms 55396 KB
#include "wall.h"
//#include "grader.cpp"

#include <vector>
#include <iostream>

const int MAXN = 1e5 + 5;

struct Range
{
    int l, r;

    Range(){}
    Range(int l, int r)
    {
        this->l = l;
        this->r = r;
    }

    int f(int x)
    {
        if(x<=l) return l;
        if(x>=r) return r;
        return x;
    }
};

Range Merge(Range first, Range second)
{
    if(second.l>=first.r) return Range(second.l, second.l);
    if(second.r<=first.l) return Range(second.r, second.r);
    if(second.l<=first.l && first.r<=second.r) return Range(first.l, first.r);
    if(first.l<=second.l && second.r<=first.r) return Range(second.l, second.r);
    if(first.l<=second.l && first.r<=second.r && second.l<=first.r) return Range(second.l, first.r);
    if(second.l<=first.l && second.r<=first.r && first.l<=second.r) return Range(first.l, second.r);
}

struct SegmentTree
{
    Range val;

    int l, r;
    SegmentTree *L, *R;

    SegmentTree(){}
    SegmentTree(int l, int r)
    {
        this->val = Range(0, MAXN);
        this->l = l;
        this->r = r;

        this->L = nullptr;
        this->R = nullptr;
    }

    void build()
    {
        if(l==r) return;

        L = new SegmentTree(l, (l+r)/2);
        R = new SegmentTree((l+r)/2+1, r);

        L->build();
        R->build();
    }

    void rem(int q)
    {
        if(l==r && q==l)
        {
            val = Range(0, MAXN);
            return;
        }
        if(q<l || q>r) return;

        L->rem(q);
        R->rem(q);
        val = Merge(L->val, R->val);
    }

    void add(int q, Range newVal)
    {
        if(l==r && q==l)
        {
            val = newVal;
            return;
        }
        if(q<l || q>r) return;

        L->add(q, newVal);
        R->add(q, newVal);
        val = Merge(L->val, R->val);
    }

    void reset()
    {
        //if(val==Range(0, MAXN)) return;
        val = Range(0, MAXN);

        if(L!=nullptr)
        {
            L->reset();
            R->reset();
        }
    }
};

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
    SegmentTree *T = new SegmentTree(0, k-1);
    T->build();

    for(int ind = 0;ind<n;ind++)
    {
        T->reset();

        Range ans = Range(0, MAXN);
        for(int i = 0;i<k;i++)
        {
            if(ind<left[i] || ind>right[i]) continue;

            if(op[i]==1) T->add(i, Range(height[i], MAXN));//ans = Merge(ans, Range(height[i], MAXN));
            else T->add(i, Range(0, height[i]));//ans = Merge(ans, Range(0, height[i]));
        }

        finalHeight[ind] = T->val.f(0);
    }
}

Compilation message

wall.cpp: In function 'void buildWall(int, int, int*, int*, int*, int*, int*)':
wall.cpp:117:15: warning: variable 'ans' set but not used [-Wunused-but-set-variable]
  117 |         Range ans = Range(0, MAXN);
      |               ^~~
wall.cpp: In function 'Range Merge(Range, Range)':
wall.cpp:36:1: warning: control reaches end of non-void function [-Wreturn-type]
   36 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 35 ms 512 KB Output is correct
4 Execution timed out 3074 ms 1024 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 352 ms 55396 KB Output is correct
3 Execution timed out 3088 ms 23416 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 35 ms 512 KB Output is correct
4 Execution timed out 3079 ms 1024 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 36 ms 512 KB Output is correct
4 Execution timed out 3097 ms 1024 KB Time limit exceeded
5 Halted 0 ms 0 KB -