#include <bits/stdc++.h>
using namespace std;
#define fori(i, a, b) for(int i = (int) a; i <= (int) b; ++i)
#define rofi(i, b, a) for(int i = (int) b; i >= (int) a; --i)
#define foreach(tt, a) for(auto &tt: a)
#define all(a) begin(a), end(a)
#define csz(a) (int) a.size()
#define pb push_back
#define epb emplace_back
#define mp make_pair
#define load(a, v) fill(begin(a), end(a), v)
#define load_mem(a, v) memset(a, v, sizeof(a));
#define iostream_optimize() ios::sync_with_stdio(false); cin.tie(0);
using ll = long long;
const ll MOD = 1e9+7, LINF = 1e16+1;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const ll P1 = 31, P2 = 37, M1 = 1e9+7, M2 = 1e9+9;
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<< END TEMPLATE >>>>>>>>>>>>>>>>>>>>>>>>>>> */
#include "wall.h"
const int N = 1 << 4;
int mx[N << 1], mn[N << 1];
void puttag(int i, int v, int tp) {
if(tp == 1) {
mx[i] = max(v, mx[i]);
mn[i] = max(v, mn[i]);
} else {
mx[i] = min(v, mx[i]);
mn[i] = min(v, mn[i]);
}
}
void apply(int i) {
if(i >= N) return;
puttag(i << 1, mx[i], 1);
puttag(i << 1, mn[i], 2);
puttag(i << 1 | 1, mx[i], 1);
puttag(i << 1 | 1, mn[i], 2);
mx[i] = 0, mn[i] = INF;
}
void update(int tl, int tr, int v, int tp, int i, int l, int r) {
apply(i);
if(l > tr || r < tl) return;
if(tl <= l && r <= tr) {
if(tp == 1) { // update max
mx[i] = max(mx[i], v);
mn[i] = max(mn[i], v);
} else { // update min
mx[i] = min(mx[i], v);
mn[i] = min(mn[i], v);
}
apply(i);
return;
}
int mid = l+r >> 1;
update(tl, tr, v, tp, i << 1, l, mid);
update(tl, tr, v, tp, i << 1 | 1, mid+1, r);
}
void propogate(int i, int l, int r) {
apply(i);
if(l == r) return;
int mid = l+r >> 1;
propogate(i << 1, l, mid);
propogate(i << 1 | 1, mid+1, r);
}
void buildWall(int n, int q, int op[], int left[], int right[], int height[], int finalHeight[]) {
load(mn, INF);
fori(i, 0, q-1) update(left[i], right[i], height[i], op[i], 1, 0, N-1);
propogate(1, 0, N-1);
fori(i, 0, n-1) finalHeight[i] = mx[N+i];
}
Compilation message
wall.cpp: In function 'void update(int, int, int, int, int, int, int)':
wall.cpp:59:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l+r >> 1;
~^~
wall.cpp: In function 'void propogate(int, int, int)':
wall.cpp:67:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l+r >> 1;
~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
496 KB |
Output is correct |
3 |
Incorrect |
3 ms |
608 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
608 KB |
Output is correct |
2 |
Correct |
213 ms |
14320 KB |
Output is correct |
3 |
Runtime error |
113 ms |
16924 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
16924 KB |
Output is correct |
2 |
Correct |
4 ms |
16924 KB |
Output is correct |
3 |
Incorrect |
4 ms |
16924 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
16924 KB |
Output is correct |
2 |
Correct |
4 ms |
16924 KB |
Output is correct |
3 |
Incorrect |
2 ms |
16924 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |