//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 2005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
const ll inf = 1<<30;
/*
struct beats{
ll mi[4*maxn], smi[4*maxn], ma[4*maxn], tag[4*maxn], arr[4*maxn], seg[4*maxn];
//Arr: single point array, ma: second array, seg = max(ma[i] - arr[i]), mi, smi, tag are to maintain ma
void push(int cur, int l, int r) {
}
void pull(int cur, int l, int r) {
}
void init(int cur, int l, int r) {
if (r <= l) return;
tag[cur] = 0;
if (r - l == 1) {
mi[cur] = -inf + 1, smi[cur] = -inf;
arr[cur] = inf;
seg[cur] = mi[cur] - arr[cur];
return;
}
int m = (l + r) / 2;
init(cur*2, l, m), init(cur*2+1, m, r);
pull(cur, l, r);
}
};
*/
struct segtree{
ll seg[4*maxn];
void init(int cur, int l, int r){
if (r <= l) return;
seg[cur] = inf;
if (r - l == 1) return;
int m = (l + r) / 2;
init(cur*2, l, m), init(cur*2+1, m, r);
}
void modify(int cur, int l, int r, int ind, ll val) {
if (r <= l) return;
if (r - l == 1) {
seg[cur] = val;
return;
}
int m = (l + r) / 2;
if (ind < m) modify(cur*2, l, m, ind, val);
else modify(cur*2+1, m, r, ind, val);
seg[cur] = min(seg[cur*2], seg[cur*2+1]);
}
ll query(int cur, int l, int r, int ql, int qr) {
if (r <= l || ql >= r || qr <= l) return inf;
if (ql <= l && qr >= r) return seg[cur];
int m = (l + r) / 2;
return min(query(cur*2, l, m, ql, qr),query(cur*2+1, m, r, ql, qr));
}
} tr;
ll h[maxn], ans[maxn][maxn];
int a[maxn], b[maxn];
vector<pii> que[maxn], ev[maxn];
void solve(int n, int st) {
tr.init(1, 0, n);
for (int i = st;i < n;i++) ev[i].clear();
for (int i = st;i < n;i++) {
for (auto [id, ch]:ev[i]) {
debug(id, ch);
if (ch == 1) tr.modify(1, 0, n, id, h[id]);
else tr.modify(1, 0, n, id, inf);
}
int l = max(0, i - b[i]), r = max(0, i - a[i]);
debug(i, h[i], tr.query(1, 0, n, l, r+1));
ans[st][i] = max(ans[st][i], h[i] - tr.query(1, 0, n, l, r+1));
if (i > st) ans[st][i] = max(ans[st][i], ans[st][i-1]);
l = min(n-1, i+a[i]), r = min(n, i + b[i] + 1);
ev[l].push_back({i, 1}), ev[r].push_back({i, -1});
}
}
int main() {
io
int n;
cin >> n;
for (int i = 0;i < n;i++) {
cin >> h[i] >> a[i] >> b[i];
}
for (int i = 0;i < n;i++) {
for (int j = 0;j < n;j++) ans[i][j] = -1;
solve(n, i);
}
for (int i = 0;i < n;i++) h[i] = -h[i];
for (int i = 0;i < n;i++) solve(n, i);
int q;
cin >> q;
for (int i = 0;i < q;i++) {
int l, r;
cin >> l >> r;
r--, l--;
cout << ans[l][r] << "\n";
que[r].push_back({l, i});
}
/*
solve(n);
for (int i = 0;i < n;i++) h[i] = -h[i];
solve(n);
for (int i = 0;i < q;i++) cout << ans[i] << "\n";
*/
}
Compilation message
antennas.cpp: In function 'void solve(int, int)':
antennas.cpp:12:20: warning: statement has no effect [-Wunused-value]
12 | #define debug(...) 0
| ^
antennas.cpp:83:4: note: in expansion of macro 'debug'
83 | debug(id, ch);
| ^~~~~
antennas.cpp:12:20: warning: statement has no effect [-Wunused-value]
12 | #define debug(...) 0
| ^
antennas.cpp:88:3: note: in expansion of macro 'debug'
88 | debug(i, h[i], tr.query(1, 0, n, l, r+1));
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
1100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
1100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
844 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
1100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |