Submission #7289

# Submission time Handle Problem Language Result Execution time Memory
7289 2014-07-29T12:40:12 Z myungwoo Wall (IOI14_wall) C++
100 / 100
1040 ms 87600 KB
#include <stdlib.h>
#include <algorithm>
using namespace std;
 
static int N,K,*H;
 
struct NODE{
    NODE(int h=0): mini(h),maxi(h),left(NULL),right(NULL) {}
    int mini,maxi;
    NODE *left,*right;
};
 
void dfs(NODE *now,int s,int e,int l,int r,int mini,int maxi,int op,int h)
{
    if (mini <= now->mini && now->maxi <= maxi);
    else if (now->mini < mini && maxi < now->maxi) now->mini = mini, now->maxi = maxi;
    else if (maxi < now->mini) now->mini = now->maxi = maxi;
    else if (now->maxi < mini) now->mini = now->maxi = mini;
    else if (mini > now->mini) now->mini = mini;
    else if (maxi < now->maxi) now->maxi = maxi;
    mini = now->mini; maxi = now->maxi;
    if (e < l || s > r) return;
    if (l <= s && e <= r){
        if (op == 1){   // add
            if (now->mini < h) now->mini = h;
            if (now->maxi < h) now->maxi = h;
        }else{          // remove
            if (now->maxi > h) now->maxi = h;
            if (now->mini > h) now->mini = h;
        }
        return;
    }
    int m = (s+e)>>1;
    if (now->left == NULL){
        now->left = new NODE(now->mini);
        now->right = new NODE(now->mini);
    }
    dfs(now->left,s,m,l,r,mini,maxi,op,h);
    dfs(now->right,m+1,e,l,r,mini,maxi,op,h);
    now->mini = min(now->left->mini,now->right->mini);
    now->maxi = max(now->left->maxi,now->right->maxi);
}
 
void cdfs(NODE *now,int s,int e,int mini,int maxi)
{
    if (mini <= now->mini && now->maxi <= maxi);
    else if (now->mini < mini && maxi < now->maxi) now->mini = mini, now->maxi = maxi;
    else if (maxi < now->mini) now->mini = now->maxi = maxi;
    else if (now->maxi < mini) now->mini = now->maxi = mini;
    else if (mini > now->mini) now->mini = mini;
    else if (maxi < now->maxi) now->maxi = maxi;
    mini = now->mini; maxi = now->maxi;
    if (mini == maxi){
        for (int i=s;i<=e;i++) H[i] = mini;
        return;
    }
    int m = (s+e)>>1;
    cdfs(now->left,s,m,mini,maxi);
    cdfs(now->right,m+1,e,mini,maxi);
}
 
void buildWall(int n,int k,int op[],int left[],int right[],int height[],int finalHeight[])
{
    int i;
    NODE *root = new NODE();
    N = n, K = k;
    for (i=0;i<K;i++){
        dfs(root,0,N-1,left[i],right[i],0,1e9,op[i],height[i]);
    }
    H = finalHeight;
    cdfs(root,0,N-1,0,1e9);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1208 KB Output is correct
2 Correct 0 ms 1208 KB Output is correct
3 Correct 0 ms 1208 KB Output is correct
4 Correct 4 ms 1736 KB Output is correct
5 Correct 8 ms 1736 KB Output is correct
6 Correct 4 ms 1736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1208 KB Output is correct
2 Correct 184 ms 9032 KB Output is correct
3 Correct 216 ms 5644 KB Output is correct
4 Correct 720 ms 15628 KB Output is correct
5 Correct 404 ms 14176 KB Output is correct
6 Correct 416 ms 14176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1208 KB Output is correct
2 Correct 0 ms 1208 KB Output is correct
3 Correct 0 ms 1208 KB Output is correct
4 Correct 8 ms 1736 KB Output is correct
5 Correct 8 ms 1736 KB Output is correct
6 Correct 8 ms 1736 KB Output is correct
7 Correct 0 ms 1208 KB Output is correct
8 Correct 192 ms 9032 KB Output is correct
9 Correct 216 ms 5644 KB Output is correct
10 Correct 696 ms 15628 KB Output is correct
11 Correct 396 ms 14176 KB Output is correct
12 Correct 392 ms 14176 KB Output is correct
13 Correct 0 ms 1208 KB Output is correct
14 Correct 184 ms 9032 KB Output is correct
15 Correct 40 ms 2748 KB Output is correct
16 Correct 852 ms 15628 KB Output is correct
17 Correct 444 ms 14176 KB Output is correct
18 Correct 420 ms 14176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1208 KB Output is correct
2 Correct 0 ms 1208 KB Output is correct
3 Correct 0 ms 1208 KB Output is correct
4 Correct 8 ms 1736 KB Output is correct
5 Correct 8 ms 1736 KB Output is correct
6 Correct 8 ms 1736 KB Output is correct
7 Correct 0 ms 1208 KB Output is correct
8 Correct 160 ms 9032 KB Output is correct
9 Correct 200 ms 5644 KB Output is correct
10 Correct 696 ms 15628 KB Output is correct
11 Correct 416 ms 14176 KB Output is correct
12 Correct 412 ms 14176 KB Output is correct
13 Correct 0 ms 1208 KB Output is correct
14 Correct 176 ms 9032 KB Output is correct
15 Correct 48 ms 2748 KB Output is correct
16 Correct 872 ms 15628 KB Output is correct
17 Correct 428 ms 14176 KB Output is correct
18 Correct 424 ms 14176 KB Output is correct
19 Correct 1012 ms 87468 KB Output is correct
20 Correct 1020 ms 87468 KB Output is correct
21 Correct 1008 ms 87600 KB Output is correct
22 Correct 1004 ms 87468 KB Output is correct
23 Correct 988 ms 87468 KB Output is correct
24 Correct 1004 ms 87468 KB Output is correct
25 Correct 1012 ms 87468 KB Output is correct
26 Correct 1040 ms 87468 KB Output is correct
27 Correct 1016 ms 87468 KB Output is correct
28 Correct 1028 ms 87336 KB Output is correct
29 Correct 996 ms 87468 KB Output is correct
30 Correct 1012 ms 87468 KB Output is correct