이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 2e5 + 2;
const int inf = 2e9;
int mn[4 * N], mx[4 * N], st[4 * N], lzymn[4 * N], lzymx[4 * N], h[N];
void Propagate(int node, int l, int r) {
if (lzymn[node] == inf) return;
smax(st[node], lzymx[node] - mn[node]);
smax(st[node], mx[node] - lzymn[node]);
if (l < r) {
smin(lzymn[2 * node], lzymn[node]);
smin(lzymn[2 * node + 1], lzymn[node]);
smax(lzymx[2 * node], lzymx[node]);
smax(lzymx[2 * node + 1], lzymx[node]);
}
lzymn[node] = inf; lzymx[node] = -1;
}
void Update(int node, int l, int r, int x, int y) {
Propagate(node, l, r);
if (l == r) {
if (y == 0) {mn[node] = mx[node] = h[l];}
else {mn[node] = inf; mx[node] = -1;}
return;
}
int mid = l + r >> 1;
if (x <= mid) Update(2 * node, l, mid, x, y);
else Update(2 * node + 1, mid + 1, r, x, y);
mn[node] = min(mn[2 * node], mn[2 * node + 1]);
mx[node] = max(mx[2 * node], mx[2 * node + 1]);
smax(st[node], max(st[2 * node], st[2 * node + 1]));
}
void Add(int node, int l, int r, int ql, int qr, int v) {
Propagate(node, l, r);
if (r < ql || qr < l) return;
if (ql <= l && r <= qr) {
lzymn[node] = lzymx[node] = v;
Propagate(node, l, r);
return;
}
int mid = l + r >> 1;
Add(2 * node, l, mid, ql, qr, v);
Add(2 * node + 1, mid + 1, r, ql, qr, v);
smax(st[node], max(st[2 * node], st[2 * node + 1]));
}
int Get(int node, int l, int r, int ql, int qr) {
Propagate(node, l, r);
if (r < ql || qr < l) return -1;
if (ql <= l && r <= qr) return st[node];
int mid = l + r >> 1;
int aa = Get(2 * node, l, mid, ql, qr);
int bb = Get(2 * node + 1, mid + 1, r, ql, qr);
smax(st[node], max(st[2 * node], st[2 * node + 1]));
return max(aa, bb);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n; cin >> n;
vector<int> a(n), b(n);
vector<vector<array<int, 2>>> op(n);
for (int i = 0; i < n; i++) {
cin >> h[i] >> a[i] >> b[i];
if (i + a[i] < n) op[i + a[i]].push_back({i, 0});
if (i + b[i] + 1 < n) op[i + b[i] + 1].push_back({i, 1});
}
int q; cin >> q;
vector<int> l(q), r(q), ans(q);
vector<vector<int>> qq(n);
for (int i = 0; i < q; i++) {
cin >> l[i] >> r[i];
l[i] -= 1; r[i] -= 1;
qq[r[i]].push_back(i);
}
for (int i = 1; i <= 4 * n; i++) {mn[i] = lzymn[i] = inf; mx[i] = lzymx[i] = st[i] = -1;}
for (int i = 0; i < n; i++) {
for (auto u : op[i]) Update(1, 0, n - 1, u[0], u[1]);
if (i >= a[i]) Add(1, 0, n - 1, max(0, i - b[i]), i - a[i], h[i]);
for (int j : qq[i]) ans[j] = Get(1, 0, n - 1, l[j], i);
}
for (int i = 0; i < q; i++) cout << ans[i] << en;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
antennas.cpp: In function 'void Update(int, int, int, int, int)':
antennas.cpp:31:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
31 | int mid = l + r >> 1;
| ~~^~~
antennas.cpp: In function 'void Add(int, int, int, int, int, int)':
antennas.cpp:46:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
46 | int mid = l + r >> 1;
| ~~^~~
antennas.cpp: In function 'int Get(int, int, int, int, int)':
antennas.cpp:55:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | int mid = l + r >> 1;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |