#include "wall.h"
#include <bits/stdc++.h>
#define INF 1e+9
using namespace std;
typedef pair<int,int> P;
P dat[1050000];
int seg = 1;
P add(P p1,P p2){
int a = p1.first,b = p1.second,c = p2.first,d = p2.second;
return P(min(a,max(c,d)),min(max(b,d),max(c,d)));
}
int f(int x,P p){
return max(min(x,p.first),p.second);
}
void update(int i,P x){
i += seg - 1;
dat[i] = x;
while(i){
i = (i - 1) / 2;
dat[i] = add(dat[i * 2 + 1],dat[i * 2 + 2]);
}
}
void buildWall(int n, int k, int op[], int l[], int r[], int height[], int finalHeight[]){
while(seg < k) seg *= 2;
for(int i = 0;i < seg * 2 - 1;i++) dat[i] = P(INF,0);
vector<int> on[2000010],off[2000010];
for(int i = 0;i < k;i++){
on[l[i]].push_back(i);
off[r[i]].push_back(i);
}
for(int i = 0;i < n;i++){
for(int v : on[i]){
if(op[v] == 1) update(v,P(INF,height[v]));
else update(v,P(height[v],0));
}
finalHeight[i] = f(0,dat[0]);
for(int v : off[i]) update(v,P(INF,0));
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
94200 KB |
Output is correct |
2 |
Correct |
100 ms |
94696 KB |
Output is correct |
3 |
Correct |
99 ms |
94696 KB |
Output is correct |
4 |
Correct |
106 ms |
95128 KB |
Output is correct |
5 |
Correct |
92 ms |
95128 KB |
Output is correct |
6 |
Correct |
83 ms |
95140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
95140 KB |
Output is correct |
2 |
Correct |
363 ms |
115228 KB |
Output is correct |
3 |
Correct |
324 ms |
115228 KB |
Output is correct |
4 |
Correct |
999 ms |
121376 KB |
Output is correct |
5 |
Correct |
462 ms |
121376 KB |
Output is correct |
6 |
Correct |
452 ms |
121376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
121376 KB |
Output is correct |
2 |
Correct |
98 ms |
121376 KB |
Output is correct |
3 |
Correct |
95 ms |
121376 KB |
Output is correct |
4 |
Correct |
101 ms |
121376 KB |
Output is correct |
5 |
Correct |
105 ms |
121376 KB |
Output is correct |
6 |
Correct |
88 ms |
121376 KB |
Output is correct |
7 |
Correct |
78 ms |
121376 KB |
Output is correct |
8 |
Correct |
425 ms |
121376 KB |
Output is correct |
9 |
Correct |
370 ms |
121376 KB |
Output is correct |
10 |
Correct |
1054 ms |
121568 KB |
Output is correct |
11 |
Correct |
434 ms |
121568 KB |
Output is correct |
12 |
Correct |
477 ms |
121568 KB |
Output is correct |
13 |
Correct |
89 ms |
121568 KB |
Output is correct |
14 |
Correct |
418 ms |
121568 KB |
Output is correct |
15 |
Correct |
137 ms |
121568 KB |
Output is correct |
16 |
Correct |
1030 ms |
121632 KB |
Output is correct |
17 |
Correct |
473 ms |
121632 KB |
Output is correct |
18 |
Correct |
508 ms |
121632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
121632 KB |
Output is correct |
2 |
Correct |
88 ms |
121632 KB |
Output is correct |
3 |
Correct |
100 ms |
121632 KB |
Output is correct |
4 |
Correct |
108 ms |
121632 KB |
Output is correct |
5 |
Correct |
104 ms |
121632 KB |
Output is correct |
6 |
Correct |
95 ms |
121632 KB |
Output is correct |
7 |
Correct |
93 ms |
121632 KB |
Output is correct |
8 |
Correct |
424 ms |
121632 KB |
Output is correct |
9 |
Correct |
388 ms |
121632 KB |
Output is correct |
10 |
Correct |
1069 ms |
121632 KB |
Output is correct |
11 |
Correct |
507 ms |
121632 KB |
Output is correct |
12 |
Correct |
572 ms |
121632 KB |
Output is correct |
13 |
Correct |
94 ms |
121632 KB |
Output is correct |
14 |
Correct |
467 ms |
121632 KB |
Output is correct |
15 |
Correct |
131 ms |
121632 KB |
Output is correct |
16 |
Correct |
953 ms |
121700 KB |
Output is correct |
17 |
Correct |
464 ms |
121700 KB |
Output is correct |
18 |
Correct |
520 ms |
121700 KB |
Output is correct |
19 |
Correct |
761 ms |
152808 KB |
Output is correct |
20 |
Correct |
949 ms |
152808 KB |
Output is correct |
21 |
Correct |
859 ms |
152840 KB |
Output is correct |
22 |
Correct |
755 ms |
152840 KB |
Output is correct |
23 |
Correct |
806 ms |
152840 KB |
Output is correct |
24 |
Correct |
864 ms |
152840 KB |
Output is correct |
25 |
Correct |
745 ms |
152840 KB |
Output is correct |
26 |
Correct |
714 ms |
152952 KB |
Output is correct |
27 |
Correct |
977 ms |
153096 KB |
Output is correct |
28 |
Correct |
869 ms |
153096 KB |
Output is correct |
29 |
Correct |
754 ms |
153096 KB |
Output is correct |
30 |
Correct |
708 ms |
153096 KB |
Output is correct |