#include <bits/stdc++.h>
#include "wall.h"
using namespace std;
const int MAXN=4194305;
int sz=1;
int a[MAXN],b[MAXN];
void push(int v){
a[2*v]=max(b[v*2],min(a[v],a[2*v]));
a[2*v+1]=max(b[v*2+1],min(a[v],a[2*v+1]));
b[2*v]=min(a[v*2],max(b[v],b[2*v]));
b[2*v+1]=min(a[v*2+1],max(b[v],b[2*v+1]));
}
void update1(int v, int tl, int tr, int l, int r, int val){
if(l>r)return;
if(tl==l&&tr==r){
b[v]=min(a[v],max(b[v],val));
}else{
push(v);
int mid=(tl+tr)/2;
update1(v*2,tl,mid,l,min(mid,r),val);
update1(v*2+1,mid+1,tr,max(mid+1,l),r,val);
b[v]=min(b[v*2],b[v*2+1]);
}
}
void update2(int v, int tl, int tr, int l, int r, int val){
if(l>r)return;
if(tl==l&&tr==r){
a[v]=max(b[v],min(a[v],val));
}else{
push(v);
int mid=(tl+tr)/2;
update2(v*2,tl,mid,l,min(mid,r),val);
update2(v*2+1,mid+1,tr,max(mid+1,l),r,val);
a[v]=max(a[v*2],a[v*2+1]);
}
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
while(sz<n)sz<<=1;
for(int i=1;i<2*sz;i++){
a[i]=100001;
b[i]=0;
}
for(int i=k-1;i>=0;i--){
if(op[i]==1)update1(1,1,sz,left[i]+1,right[i]+1,height[i]);
else update2(1,1,sz,left[i]+1,right[i]+1,height[i]);
// for(int i=1;i<sz*2;i++)cout << '{' << i << ' ' << a[i] << ' ' << b[i] << '}';
// cout << '\n';
}
for(int i=1;i<sz;i++)push(i);
for(int i=0;i<n;i++)finalHeight[i]=b[i+sz];
return;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
3 ms |
2392 KB |
Output is correct |
3 |
Correct |
2 ms |
2392 KB |
Output is correct |
4 |
Correct |
5 ms |
2652 KB |
Output is correct |
5 |
Correct |
6 ms |
2648 KB |
Output is correct |
6 |
Correct |
8 ms |
2656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
103 ms |
15956 KB |
Output is correct |
3 |
Correct |
159 ms |
12660 KB |
Output is correct |
4 |
Correct |
416 ms |
24580 KB |
Output is correct |
5 |
Correct |
247 ms |
25664 KB |
Output is correct |
6 |
Correct |
230 ms |
24148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2504 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
5 ms |
2824 KB |
Output is correct |
5 |
Correct |
4 ms |
2652 KB |
Output is correct |
6 |
Correct |
4 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
106 ms |
15956 KB |
Output is correct |
9 |
Correct |
147 ms |
13856 KB |
Output is correct |
10 |
Correct |
366 ms |
24716 KB |
Output is correct |
11 |
Correct |
240 ms |
25756 KB |
Output is correct |
12 |
Correct |
228 ms |
24144 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
108 ms |
15908 KB |
Output is correct |
15 |
Correct |
23 ms |
7772 KB |
Output is correct |
16 |
Correct |
376 ms |
24976 KB |
Output is correct |
17 |
Correct |
251 ms |
24400 KB |
Output is correct |
18 |
Correct |
258 ms |
24404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2392 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
5 ms |
2652 KB |
Output is correct |
5 |
Correct |
4 ms |
2688 KB |
Output is correct |
6 |
Correct |
4 ms |
2904 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
100 ms |
15908 KB |
Output is correct |
9 |
Correct |
141 ms |
13904 KB |
Output is correct |
10 |
Correct |
375 ms |
24724 KB |
Output is correct |
11 |
Correct |
245 ms |
25680 KB |
Output is correct |
12 |
Correct |
228 ms |
24060 KB |
Output is correct |
13 |
Correct |
1 ms |
2496 KB |
Output is correct |
14 |
Correct |
103 ms |
15980 KB |
Output is correct |
15 |
Correct |
23 ms |
7956 KB |
Output is correct |
16 |
Correct |
381 ms |
25024 KB |
Output is correct |
17 |
Correct |
242 ms |
24404 KB |
Output is correct |
18 |
Correct |
235 ms |
24404 KB |
Output is correct |
19 |
Correct |
542 ms |
69492 KB |
Output is correct |
20 |
Correct |
537 ms |
66896 KB |
Output is correct |
21 |
Correct |
552 ms |
69612 KB |
Output is correct |
22 |
Correct |
533 ms |
67104 KB |
Output is correct |
23 |
Correct |
548 ms |
67156 KB |
Output is correct |
24 |
Correct |
532 ms |
67036 KB |
Output is correct |
25 |
Correct |
548 ms |
66932 KB |
Output is correct |
26 |
Correct |
547 ms |
69424 KB |
Output is correct |
27 |
Correct |
536 ms |
69680 KB |
Output is correct |
28 |
Correct |
534 ms |
66888 KB |
Output is correct |
29 |
Correct |
540 ms |
67088 KB |
Output is correct |
30 |
Correct |
531 ms |
66912 KB |
Output is correct |