답안 #122561

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
122561 2019-06-28T15:38:07 Z brcode 벽 (IOI14_wall) C++14
0 / 100
3000 ms 13920 KB
#include <iostream>
#include "wall.h"
using namespace std;
struct node{
    int mn,mx;
};
const int MAXN = 4e6+5;
pair<int,int> lazy[4*MAXN];
int ans[MAXN];
node seg[4*MAXN];
void push(int curr,int l,int r){
    auto temp = make_pair(0,0);
    if(lazy[curr] == temp){
        return;
    }
    if(l==r){
        if(lazy[curr].first == 1){
            if(seg[curr].mx <lazy[curr].second){
                seg[curr].mx = lazy[curr].second;
                seg[curr].mn = lazy[curr].second;
            }
        }else{
            if(seg[curr].mx >lazy[curr].second){
                seg[curr].mx = lazy[curr].second;
                seg[curr].mn = lazy[curr].second;
            }
        }
        return;
    }
    int mid = (l+r)/2;
    if(lazy[2*curr]!=temp){
        push(2*curr,l,mid);
    }
    if(lazy[2*curr+1]!=temp){
        push(2*curr+1,mid+1,r);
    }
    seg[curr].mx = max(seg[2*curr].mx,seg[2*curr+1].mx);
    seg[curr].mn = min(seg[2*curr].mn,seg[2*curr+1].mn);
    if(lazy[curr].first == 1){
        if(seg[curr].mn<lazy[curr].second){
            lazy[2*curr] = make_pair(1,lazy[curr].second);
            lazy[2*curr+1] = make_pair(1,lazy[curr].second);
            seg[curr].mn = lazy[curr].second;
            seg[curr].mx = max(seg[curr].mx,lazy[curr].second);
            lazy[curr] = temp;
        }
    }else{
        if(seg[curr].mx>lazy[curr].second){
            lazy[2*curr] = make_pair(2,lazy[curr].second);
            lazy[2*curr+1] = make_pair(2,lazy[curr].second);
            seg[curr].mx = lazy[curr].second;
            seg[curr].mn = min(seg[curr].mn,lazy[curr].second);
            lazy[curr] = temp;
        }
    }
}
void build(int curr,int l,int r){
    if(l==r){
        seg[curr].mn = 0;
        seg[curr].mx = 0;
        return;
    }
    int mid = (l+r)/2;
    build(2*curr,l,mid);
    build(2*curr+1,mid+1,r);
    seg[curr].mn = min(seg[2*curr].mn,seg[2*curr+1].mn);
    seg[curr].mx = max(seg[2*curr].mx,seg[2*curr+1].mx);
}
void updateadd(int curr,int l,int r,int tl,int tr,int val){
    push(curr,l,r);
    if(l>tr||r<tl){
        return;
    }
    if(l>=tl && r<=tr){
        push(curr,l,r);
        lazy[curr] = make_pair(1,val);
        return;
    }
    int mid = (l+r)/2;
    updateadd(2*curr,l,mid,tl,tr,val);
    updateadd(2*curr+1,mid+1,r,tl,tr,val);
    seg[curr].mn = min(seg[2*curr].mn,seg[2*curr+1].mn);
    seg[curr].mx = max(seg[2*curr].mx,seg[2*curr+1].mx);
}
void updatedel(int curr,int l,int r,int tl,int tr,int val){
    push(curr,l,r);
    if(l>tr||r<tl){
        return;
    }
    if(l>=tl && r<=tr){
        push(curr,l,r);
        lazy[curr] = make_pair(2,val);
        return;
    }
    int mid = (l+r)/2;
    updatedel(2*curr,l,mid,tl,tr,val);
    updatedel(2*curr+1,mid+1,r,tl,tr,val);
    seg[curr].mn = min(seg[2*curr].mn,seg[2*curr+1].mn);
    seg[curr].mx = max(seg[2*curr].mx,seg[2*curr+1].mx);
}
void query(int curr,int l,int r){
    push(curr,l,r);
    if(l==r){
        ans[l-1] = seg[curr].mx;
        return;
    }
    int mid = (l+r)/2;
    query(2*curr,l,mid);
    query(2*curr+1,mid+1,r);
    seg[curr].mn = min(seg[2*curr].mn,seg[2*curr+1].mn);
    seg[curr].mx = max(seg[2*curr].mx,seg[2*curr+1].mx);
}
void buildWall(int n, int k, int op[], int left[], int right[],int height[], int finalHeight[]){
    
    build(1,1,n);
    
    for(int i=0;i<k;i++){
        if(op[i] == 1){
            updateadd(1,1,n,left[i]+1,right[i]+1,height[i]);
        }else{
            updatedel(1,1,n,left[i]+1,right[i]+1,height[i]);
        }
        
    }
    query(1,1,n);
    for(int i=0;i<n;i++){
        finalHeight[i] = ans[i];
        //cout<<ans[i]<<endl;
    }
}
/**int main(){
    int n,k;
    cin>>n>>k;
    int left[k+1];
    int right[k+1];
    int height[k+1];
    int type[k+1];
    int finalHeight[k+1];
    for(int i=0;i<k;i++){
        cin>>type[i]>>left[i]>>right[i]>>height[i];
    }
    buildWall(n,k,type,left,right,height,finalHeight);
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Incorrect 5 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 173 ms 13920 KB Output is correct
3 Execution timed out 3009 ms 8440 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Incorrect 5 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Incorrect 6 ms 420 KB Output isn't correct
4 Halted 0 ms 0 KB -