#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
#define maxn 2000050
vector<int> seg(maxn*4,0);
vector<int> up(maxn*4,-1);
vector<int> down(maxn*4,INT_MAX);
vector<int> ans;
void push(int node){
up[node*2+1] = max(up[node*2+1],up[node]);
up[node*2+2] = max(up[node*2+2],up[node]);
down[node*2+1] = max(down[node*2+1],up[node]);
down[node*2+2] = max(down[node*2+2],up[node]);
down[node*2+1] = min(down[node*2+1],down[node]);
down[node*2+2] = min(down[node*2+2],down[node]);
up[node*2+1] = min(up[node*2+1],down[node]);
up[node*2+2] = min(up[node*2+2],down[node]);
up[node] = -1;
down[node] = INT_MAX;
}
void update(int node,int start,int end,int rangemin,int rangemax,int type,int val){
//cout << node << " " << start << " " << end << ' ' << rangemin << ' ' << rangemax << " " << type << " "<< val << endl;
if(start>=rangemin&&end<=rangemax){
//cout << " " << start " "
if(type==1){
up[node] = max(up[node],val);
down[node] = max(down[node],up[node]);
}
if(type==2){
down[node] = min(down[node],val);
up[node] = min(up[node],down[node]);
}
if(start==end){
if(up[node]!=-1){
seg[node] = max(seg[node],up[node]);
}
if(down[node]!=INT_MAX){
seg[node] = min(seg[node],down[node]);
}
up[node] = -1;
down[node] = INT_MAX;
}
return;
}
if(start==end){
if(up[node]!=-1){
seg[node] = max(seg[node],up[node]);
}
if(down[node]!=INT_MAX){
seg[node] = min(seg[node],down[node]);
}
up[node] = -1;
down[node] = INT_MAX;
return;
}
if(start>rangemax||end<rangemin){
//cout << " "<< start << " " << end << "---------\n";
return;
}
push(node);
int mid = (start+end)/2;
update(node*2+1,start,mid,rangemin,rangemax,type,val);
update(node*2+2,mid+1,end,rangemin,rangemax,type,val);
}
void print(int node,int start,int end){
//cout << up[node] << " "<< down[node] << " " << start << " " << end << "--\n";
if(start==end){
if(up[node]!=-1){
seg[node] = max(seg[node],up[node]);
}
if(down[node]!=INT_MAX){
seg[node] = min(seg[node],down[node]);
}
up[node] = -1;
down[node] = INT_MAX;
}
push(node);
if(start==end){
ans.push_back(seg[node]);
return;
}
int mid = (start+end)/2;
print(node*2+1,start,mid);
print(node*2+2,mid+1,end);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
int a,b,c,d;
for(int i=0;i<k;i++){
a = op[i];
b = left[i];
c = right[i];
d = height[i];
update(0,0,n-1,b,c,a,d);
}
print(0,0,n-1);
for(int i=0;i<n;i++){
finalHeight[i] = ans[i];
}
return;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
94188 KB |
Output is correct |
2 |
Correct |
55 ms |
94444 KB |
Output is correct |
3 |
Correct |
55 ms |
94316 KB |
Output is correct |
4 |
Correct |
67 ms |
94572 KB |
Output is correct |
5 |
Correct |
62 ms |
94572 KB |
Output is correct |
6 |
Correct |
62 ms |
94720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
94444 KB |
Output is correct |
2 |
Correct |
231 ms |
108268 KB |
Output is correct |
3 |
Correct |
304 ms |
101612 KB |
Output is correct |
4 |
Correct |
867 ms |
112868 KB |
Output is correct |
5 |
Correct |
533 ms |
113880 KB |
Output is correct |
6 |
Correct |
515 ms |
112356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
94188 KB |
Output is correct |
2 |
Correct |
56 ms |
94444 KB |
Output is correct |
3 |
Correct |
56 ms |
94316 KB |
Output is correct |
4 |
Correct |
64 ms |
94572 KB |
Output is correct |
5 |
Correct |
61 ms |
94700 KB |
Output is correct |
6 |
Correct |
61 ms |
94572 KB |
Output is correct |
7 |
Correct |
55 ms |
94188 KB |
Output is correct |
8 |
Correct |
222 ms |
107884 KB |
Output is correct |
9 |
Correct |
308 ms |
101612 KB |
Output is correct |
10 |
Correct |
750 ms |
112868 KB |
Output is correct |
11 |
Correct |
526 ms |
113952 KB |
Output is correct |
12 |
Correct |
540 ms |
112484 KB |
Output is correct |
13 |
Correct |
59 ms |
94188 KB |
Output is correct |
14 |
Correct |
227 ms |
108140 KB |
Output is correct |
15 |
Correct |
103 ms |
95652 KB |
Output is correct |
16 |
Correct |
767 ms |
113124 KB |
Output is correct |
17 |
Correct |
499 ms |
112484 KB |
Output is correct |
18 |
Correct |
509 ms |
112484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
94188 KB |
Output is correct |
2 |
Correct |
60 ms |
94444 KB |
Output is correct |
3 |
Correct |
66 ms |
94316 KB |
Output is correct |
4 |
Correct |
66 ms |
94572 KB |
Output is correct |
5 |
Correct |
65 ms |
94572 KB |
Output is correct |
6 |
Correct |
65 ms |
94572 KB |
Output is correct |
7 |
Correct |
58 ms |
94188 KB |
Output is correct |
8 |
Correct |
234 ms |
108140 KB |
Output is correct |
9 |
Correct |
285 ms |
101612 KB |
Output is correct |
10 |
Correct |
792 ms |
112868 KB |
Output is correct |
11 |
Correct |
531 ms |
113864 KB |
Output is correct |
12 |
Correct |
528 ms |
112356 KB |
Output is correct |
13 |
Correct |
59 ms |
94316 KB |
Output is correct |
14 |
Correct |
228 ms |
107884 KB |
Output is correct |
15 |
Correct |
96 ms |
95648 KB |
Output is correct |
16 |
Correct |
776 ms |
113124 KB |
Output is correct |
17 |
Correct |
506 ms |
112676 KB |
Output is correct |
18 |
Correct |
507 ms |
112484 KB |
Output is correct |
19 |
Correct |
1175 ms |
138672 KB |
Output is correct |
20 |
Correct |
1126 ms |
136392 KB |
Output is correct |
21 |
Correct |
1141 ms |
138568 KB |
Output is correct |
22 |
Correct |
1199 ms |
136228 KB |
Output is correct |
23 |
Correct |
1124 ms |
136392 KB |
Output is correct |
24 |
Correct |
1134 ms |
136176 KB |
Output is correct |
25 |
Correct |
1129 ms |
136136 KB |
Output is correct |
26 |
Correct |
1180 ms |
138696 KB |
Output is correct |
27 |
Correct |
1159 ms |
138720 KB |
Output is correct |
28 |
Correct |
1159 ms |
136136 KB |
Output is correct |
29 |
Correct |
1132 ms |
136264 KB |
Output is correct |
30 |
Correct |
1136 ms |
136148 KB |
Output is correct |