Submission #112456

# Submission time Handle Problem Language Result Execution time Memory
112456 2019-05-20T05:35:05 Z ansol4328 Wall (IOI14_wall) C++11
100 / 100
1099 ms 92280 KB
#include<vector>
#include<algorithm>

using namespace std;

struct SegTree
{
    vector<int> MaxT, MinT;
    vector<int> MaxLazy, MinLazy;
    int base;
    SegTree(int a)
    {
        base=1;
        while(base<a) base<<=1;
        MaxT.resize(base*2+2);
        MinT.resize(base*2+2);
        MaxLazy.resize(base*2+2,-1);
        MinLazy.resize(base*2+2,-1);
        base--;
    }
    void propagate(int ns, int nf, int num)
    {
        int a, b, c;
        if(MaxLazy[num]!=-1)
        {
            c=MaxLazy[num];
            if(ns<nf)
            {
                a=MinT[num*2], b=MaxT[num*2];
                if(MinLazy[num*2]!=-1) a=MinLazy[num*2];
                if(MaxLazy[num*2]!=-1) b=MaxLazy[num*2];
                if(c<a) MaxLazy[num*2]=MinLazy[num*2]=c;
                else if(a<=c && c<b) MaxLazy[num*2]=c;

                a=MinT[num*2+1], b=MaxT[num*2+1];
                if(MinLazy[num*2+1]!=-1) a=MinLazy[num*2+1];
                if(MaxLazy[num*2+1]!=-1) b=MaxLazy[num*2+1];
                if(c<a) MaxLazy[num*2+1]=MinLazy[num*2+1]=c;
                else if(a<=c && c<b) MaxLazy[num*2+1]=c;
            }
            MaxT[num]=c;
            MaxLazy[num]=-1;
        }
        if(MinLazy[num]!=-1)
        {
            c=MinLazy[num];
            if(ns<nf)
            {
                a=MinT[num*2], b=MaxT[num*2];
                if(MinLazy[num*2]!=-1) a=MinLazy[num*2];
                if(MaxLazy[num*2]!=-1) b=MaxLazy[num*2];
                if(a<c && c<=b) MinLazy[num*2]=c;
                else if(b<c) MinLazy[num*2]=MaxLazy[num*2]=c;

                a=MinT[num*2+1], b=MaxT[num*2+1];
                if(MinLazy[num*2+1]!=-1) a=MinLazy[num*2+1];
                if(MaxLazy[num*2+1]!=-1) b=MaxLazy[num*2+1];
                if(a<c && c<=b) MinLazy[num*2+1]=c;
                else if(b<c) MinLazy[num*2+1]=MaxLazy[num*2+1]=c;
            }
            MinT[num]=c;
            MinLazy[num]=-1;
        }
    }
    void oper(int op, int v, int st, int fn, int ns=1, int nf=-1, int num=1)
    {
        if(nf==-1) nf=base+1;
        propagate(ns,nf,num);
        if(fn<ns || nf<st) return;
        if(st<=ns && nf<=fn)
        {
            int a=MinT[num], b=MaxT[num], c=v;
            if(op==1)
            {
                if(a<c && c<=b) MinLazy[num]=c;
                else if(b<c) MinLazy[num]=MaxLazy[num]=c;
            }
            else if(op==2)
            {
                if(c<a) MaxLazy[num]=MinLazy[num]=c;
                else if(a<=c && c<b) MaxLazy[num]=c;
            }
            propagate(ns,nf,num);
            return;
        }
        int mid=(ns+nf)>>1;
        oper(op,v,st,fn,ns,mid,num*2);
        oper(op,v,st,fn,mid+1,nf,num*2+1);
        MinT[num]=min(MinT[num*2],MinT[num*2+1]);
        MaxT[num]=max(MaxT[num*2],MaxT[num*2+1]);
    }
    void get_res()
    {
        int len=base+1, num=1;
        while(len!=0)
        {
            for(int ns=1 ; ns<=base+1 ; ns+=len)
            {
                propagate(ns,ns+len-1,num);
                num++;
            }
            len>>=1;
        }
    }
};

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
	SegTree T(n);
  	for(int i=0 ; i<k ; i++)
    {
      	left[i]++, right[i]++;
        T.oper(op[i],height[i],left[i],right[i]);
    }
  	T.get_res();
  	for(int i=0 ; i<n ; i++) finalHeight[i]=T.MinT[T.base+i+1];
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 10 ms 1024 KB Output is correct
5 Correct 8 ms 1024 KB Output is correct
6 Correct 8 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 156 ms 13944 KB Output is correct
3 Correct 201 ms 8520 KB Output is correct
4 Correct 643 ms 22368 KB Output is correct
5 Correct 318 ms 22904 KB Output is correct
6 Correct 297 ms 21368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 10 ms 1024 KB Output is correct
5 Correct 7 ms 1024 KB Output is correct
6 Correct 7 ms 1024 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 146 ms 14036 KB Output is correct
9 Correct 188 ms 8440 KB Output is correct
10 Correct 574 ms 22392 KB Output is correct
11 Correct 304 ms 22888 KB Output is correct
12 Correct 303 ms 21368 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 154 ms 13944 KB Output is correct
15 Correct 52 ms 2680 KB Output is correct
16 Correct 1030 ms 22416 KB Output is correct
17 Correct 319 ms 21884 KB Output is correct
18 Correct 320 ms 21752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 11 ms 1024 KB Output is correct
5 Correct 7 ms 1024 KB Output is correct
6 Correct 8 ms 1024 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 146 ms 13944 KB Output is correct
9 Correct 189 ms 8568 KB Output is correct
10 Correct 638 ms 22344 KB Output is correct
11 Correct 325 ms 22824 KB Output is correct
12 Correct 300 ms 21496 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 167 ms 13944 KB Output is correct
15 Correct 56 ms 2432 KB Output is correct
16 Correct 1099 ms 22372 KB Output is correct
17 Correct 335 ms 21896 KB Output is correct
18 Correct 319 ms 21752 KB Output is correct
19 Correct 854 ms 92256 KB Output is correct
20 Correct 883 ms 92144 KB Output is correct
21 Correct 886 ms 92248 KB Output is correct
22 Correct 815 ms 92152 KB Output is correct
23 Correct 813 ms 92280 KB Output is correct
24 Correct 834 ms 92260 KB Output is correct
25 Correct 921 ms 92252 KB Output is correct
26 Correct 837 ms 92232 KB Output is correct
27 Correct 865 ms 92264 KB Output is correct
28 Correct 836 ms 92204 KB Output is correct
29 Correct 877 ms 92152 KB Output is correct
30 Correct 853 ms 92264 KB Output is correct