Submission #109984

# Submission time Handle Problem Language Result Execution time Memory
109984 2019-05-08T14:03:36 Z DodgeBallMan Wall (IOI14_wall) C++14
100 / 100
1377 ms 67936 KB
#include <bits/stdc++.h>
#include "wall.h"

using namespace std;

const int N = 1 << 21;
const int inf = 2e9;
int lo[N<<1], hi[N<<1], ret[N], n, k;

void push( int now, int l, int r ) {
    if( l == r ) ret[l] = min( hi[now], max( lo[now], ret[l] ) );
    else {
		hi[now<<1] = max( lo[now], min( hi[now], hi[now<<1] ) ), lo[now<<1] = min( hi[now], max( lo[now], lo[now<<1] ) );
		hi[now<<1|1] = max( lo[now], min( hi[now], hi[now<<1|1] ) ), lo[now<<1|1] = min( hi[now], max( lo[now], lo[now<<1|1] ) );
	}
    //printf("%d %d %d\n",now,l,r);
	lo[now] = 0, hi[now] = inf;
    return ;
}

void update( int ll, int rr, int f, int t, int l = 1, int r = n, int now = 1 ) {
    push( now, l, r );
    if( l > rr || r < ll || l > r ) return ;
    if( l >= ll && r <= rr ) {
        //printf("hi %d lo %d\n",hi[now],lo[now]);
        hi[now] = max( f, min( hi[now], t ) ), lo[now] = min( t, max( lo[now], f ) );
        //printf("l : %d r : %d f : %d t : %d ll : %d rr : %d hi %d lo %d\n",l,r,f,t,ll,rr,hi[now],lo[now]);
        return ;
    }
    
    int mid = ( l + r ) >> 1;
    update( ll, rr, f, t, l, mid, now << 1 ), update( ll, rr, f, t, mid + 1, r, now << 1 | 1 );
    return ;
}

void computeans( int l = 1, int r = n, int now = 1 ) {
    push( now, l, r );
    if( l == r ) return ;
    int mid = ( l + r ) >> 1;
    computeans( l, mid, now << 1 ), computeans( mid + 1, r, now << 1 | 1 );
    return ;
}

void buildWall( int N, int k, int op[], int left[], int right[], int height[], int finalheight[] ) 
{  
    n = N;
    fill( hi, hi + 2*N, inf );
    for( int i = 0 ; i < k ; i++ ) {
        if( op[i] == 1 ) update( left[i] + 1, right[i] + 1, height[i], inf );
        else update( left[i] + 1, right[i] + 1, 0, height[i] );
    }
    computeans();
    for( int i = 1 ; i <= n ; i++ ) finalheight[i-1] = ret[i];
    return ;
}

// #define LOCAL_TEST 0

#ifdef LOCAL_TEST
int main() 
{

    scanf("%d %d",&n,&k);
    for( int i = 0 ; i < k ; i++ ) {
        int op, l, r, h;
        scanf("%d %d %d %d",&op,&l,&r,&h);
        if( op == 1 ) update( l + 1, r + 1, h, inf );
        else update( l + 1, r + 1, 0, h );
        if( i == k - 4 ) {
            computeans();
        for( int i = 1 ; i <= n ; i++ ) printf("%d ",ret[i]);
        cout << endl;
        }
    }
    computeans();
    for( int i = 1 ; i <= n ; i++ ) printf("%d ",ret[i]);
    cout << endl;
    return 0;
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 2 ms 284 KB Output is correct
2 Correct 4 ms 492 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 12 ms 896 KB Output is correct
5 Correct 9 ms 896 KB Output is correct
6 Correct 11 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 149 ms 8636 KB Output is correct
3 Correct 226 ms 4728 KB Output is correct
4 Correct 818 ms 11888 KB Output is correct
5 Correct 398 ms 12444 KB Output is correct
6 Correct 381 ms 12856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 15 ms 888 KB Output is correct
5 Correct 8 ms 896 KB Output is correct
6 Correct 13 ms 896 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 189 ms 9244 KB Output is correct
9 Correct 259 ms 5404 KB Output is correct
10 Correct 859 ms 12316 KB Output is correct
11 Correct 382 ms 12892 KB Output is correct
12 Correct 427 ms 12832 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 169 ms 9332 KB Output is correct
15 Correct 73 ms 2040 KB Output is correct
16 Correct 1004 ms 12572 KB Output is correct
17 Correct 487 ms 12664 KB Output is correct
18 Correct 452 ms 12576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 8 ms 384 KB Output is correct
4 Correct 11 ms 896 KB Output is correct
5 Correct 9 ms 896 KB Output is correct
6 Correct 12 ms 896 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 181 ms 9248 KB Output is correct
9 Correct 254 ms 5408 KB Output is correct
10 Correct 924 ms 12312 KB Output is correct
11 Correct 481 ms 12868 KB Output is correct
12 Correct 456 ms 12920 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 188 ms 9324 KB Output is correct
15 Correct 50 ms 2168 KB Output is correct
16 Correct 866 ms 12636 KB Output is correct
17 Correct 389 ms 12592 KB Output is correct
18 Correct 412 ms 12732 KB Output is correct
19 Correct 898 ms 67832 KB Output is correct
20 Correct 984 ms 65528 KB Output is correct
21 Correct 1116 ms 67936 KB Output is correct
22 Correct 1000 ms 65500 KB Output is correct
23 Correct 1377 ms 65424 KB Output is correct
24 Correct 1113 ms 65372 KB Output is correct
25 Correct 1012 ms 65244 KB Output is correct
26 Correct 902 ms 67832 KB Output is correct
27 Correct 929 ms 67772 KB Output is correct
28 Correct 1176 ms 65272 KB Output is correct
29 Correct 1101 ms 65352 KB Output is correct
30 Correct 1022 ms 65220 KB Output is correct