Submission #202783

# Submission time Handle Problem Language Result Execution time Memory
202783 2020-02-17T22:44:01 Z DavidDamian Wall (IOI14_wall) C++11
32 / 100
1131 ms 23520 KB
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
int segm_tree[5000000];
int leftNode(int i)
{
    return i*2;
}
int rightNode(int i)
{
    return i*2+1;
}
void recompute(int i)
{
    segm_tree[i]=max(segm_tree[leftNode(i)],segm_tree[rightNode(i)]);
}
struct ura
{
    int type;
    int var1;
    int var2;
} lazy[5000000];
#define add 1 //Add
#define rem 2 //Remove
#define change 3 //Change
#define bound 4 //Bound
ura Add(int i,int j)
{
    ura ret;
    int a,b,c;
    a=lazy[i].var1;
    b=lazy[j].var1;
    c=lazy[j].var2;
    if(lazy[j].type==add)
        ret={add,max(a,b),0};
    else if(lazy[j].type==rem){
        if(a>=b) ret={change,b,0};
        else ret={bound,a,b};
    }
    else if(lazy[j].type==change)
        ret={change,b,0};
    else if(lazy[j].type==bound){
        if(a<b) ret={bound,b,c};
        else if(a>c) ret={change,c,0};
        else ret={bound,a,c};
    }
    return ret;
}
ura Remove(int i,int j)
{
    ura ret;
    int a,b,c;
    a=lazy[i].var1;
    b=lazy[j].var1;
    c=lazy[j].var2;
    if(lazy[j].type==add){
        if(a<b) ret={change,b,0};
        else ret={bound,b,a};
    }
    else if(lazy[j].type==rem){
        ret={rem,min(a,b),0};
    }
    else if(lazy[j].type==change){
        ret={change,b,0};
    }
    else if(lazy[j].type==bound){
        if(a<b) ret={change,b,0};
        else if(a>c) ret={bound,b,c};
        else ret={bound,b,a};
    }
    return ret;
}
ura Change(int i,int j)
{
    ura ret;
    int a,b,c;
    a=lazy[i].var1;
    b=lazy[j].var1;
    c=lazy[j].var2;
    if(lazy[j].type==add){
        ret={change,max(a,b),0};
    }
    else if(lazy[j].type==rem){
        ret={change,min(a,b),0};
    }
    else if(lazy[j].type==change){
        ret={change,b,0};
    }
    else if(lazy[j].type==bound){
        if(a<b) ret={change,b,0};
        else if(a>c) ret={change,c,0};
        else ret={bound,a,c};
    }
    return ret;
}
ura Bound(int i,int j)
{
    ura ret;
    int a,b,c,d;
    a=lazy[i].var1;
    b=lazy[i].var2;
    c=lazy[j].var1;
    d=lazy[j].var2;
    if(lazy[j].type==add){
        if(c<a) ret={bound,a,b};
        else if(c>b) ret={change,c,0};
        else ret={bound,c,b};
    }
    else if(lazy[j].type==rem){
        if(c<a) ret={change,c,0};
        else if(c>b) ret={bound,a,b};
        else ret={bound,a,c};
    }
    else if(lazy[j].type==change){
        ret={change,c,0};
    }
    else if(lazy[j].type==bound){
        if(b<c) ret={change,c,0};
        else if(d<a) ret={change,d,0};
        else if(a<c) ret={bound,c,b};
        else if(b>d) ret={bound,a,d};
    }
    return ret;
}
ura combine(int i,int j)
{
    if(lazy[i].type==0)
        return lazy[j];
    if(lazy[i].type==add)
        return Add(i,j);
    if(lazy[i].type==rem)
        return Remove(i,j);
    if(lazy[i].type==change)
        return Change(i,j);
    if(lazy[i].type==bound)
        return Bound(i,j);
}
void propagate(int i,int L,int R)
{
    if(lazy[i].type==0) return;
    if(lazy[i].type==add) segm_tree[i]=max(segm_tree[i],lazy[i].var1);
    else if(lazy[i].type==rem) segm_tree[i]=min(segm_tree[i],lazy[i].var1);
    else if(lazy[i].type==change) segm_tree[i]=lazy[i].var1;
    else if(lazy[i].type==bound){
        if(segm_tree[i]<lazy[i].var1)
            segm_tree[i]=lazy[i].var1;
        else if(segm_tree[i]>lazy[i].var2)
            segm_tree[i]=lazy[i].var2;
    }
    if(L<R){

        lazy[leftNode(i)]=combine(leftNode(i),i);
        lazy[rightNode(i)]=combine(rightNode(i),i);
    }
    lazy[i].type=0;
}
void update(int i,int L,int R,int x,int y,int type,int h)
{
    propagate(i,L,R);
    if(x<=L && R<=y)
        lazy[i].type=type,lazy[i].var1=h;
    else{
        int mid=(L+R)/2;
        if(x<=mid)
            update(leftNode(i),L,mid,x,y,type,h);
        if(mid+1<=y)
            update(rightNode(i),mid+1,R,x,y,type,h);
        propagate(leftNode(i),L,mid);
        propagate(rightNode(i),mid+1,R);
        recompute(i);
    }
}
int query(int i,int L,int R,int x)
{
    propagate(i,L,R);
    if(L==R){
        return segm_tree[i];
    }
    else{
        int mid=(L+R)/2;
        if(x<=mid)
            return query(leftNode(i),L,mid,x);
        else
            return query(rightNode(i),mid+1,R,x);
    }
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
    for(int i=0;i<k;i++){
        update(1,1,n,left[i]+1,right[i]+1,op[i],height[i]);
    }
    for(int i=0;i<n;i++){
        finalHeight[i]=query(1,1,n,i+1);
    }
}

Compilation message

wall.cpp: In function 'ura combine(int, int)':
wall.cpp:137:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 7 ms 376 KB Output is correct
4 Correct 18 ms 1144 KB Output is correct
5 Correct 11 ms 1144 KB Output is correct
6 Correct 12 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 182 ms 13992 KB Output is correct
3 Correct 372 ms 8504 KB Output is correct
4 Correct 1104 ms 22528 KB Output is correct
5 Correct 396 ms 22648 KB Output is correct
6 Correct 356 ms 22088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 7 ms 376 KB Output is correct
4 Correct 16 ms 1144 KB Output is correct
5 Correct 13 ms 1144 KB Output is correct
6 Correct 12 ms 1144 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 180 ms 13944 KB Output is correct
9 Correct 383 ms 8648 KB Output is correct
10 Correct 1110 ms 22520 KB Output is correct
11 Correct 391 ms 23520 KB Output is correct
12 Correct 368 ms 22008 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 180 ms 13944 KB Output is correct
15 Incorrect 72 ms 2680 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 7 ms 376 KB Output is correct
4 Correct 16 ms 1140 KB Output is correct
5 Correct 12 ms 1144 KB Output is correct
6 Correct 12 ms 1144 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 178 ms 14072 KB Output is correct
9 Correct 394 ms 8504 KB Output is correct
10 Correct 1131 ms 22444 KB Output is correct
11 Correct 355 ms 22648 KB Output is correct
12 Correct 344 ms 22008 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 184 ms 13944 KB Output is correct
15 Incorrect 71 ms 2552 KB Output isn't correct
16 Halted 0 ms 0 KB -