제출 #862195

#제출 시각아이디문제언어결과실행 시간메모리
862195KubogiTwo Antennas (JOI19_antennas)C++17
0 / 100
249 ms49748 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fileio(name) if (fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout) const int maxn = 2e5+4, inf = 1e18; int n, q, h[maxn], a[maxn], b[maxn], ans[maxn], l[maxn], r[maxn]; vector<int> add[maxn], del[maxn]; vector<pair<int, int>> Q[maxn]; struct node { int mx = -inf, mn = inf, diff = -inf*2; } st[maxn*4]; void pushdown(int id) { int x = st[id].mx; st[id*2].mx = max(st[id*2].mx, x); st[id*2].diff = max(st[id*2].diff, st[id*2].mx - st[id*2].mn); st[id*2+1].mx = max(st[id*2+1].mx, x); st[id*2+1].diff = max(st[id*2+1].diff, st[id*2+1].mx - st[id*2+1].mn); } void update_mx(int id, int l, int r, int a, int b, int v) { if (r < a || b < l) return; if (a <= l && r <= b) { st[id].mx = max(st[id].mx, v); st[id].diff = st[id].mx - st[id].mn; return; } pushdown(id); int mid = (l+r)>>1; update_mx(id*2, l, mid, a, b, v); update_mx(id*2+1, mid+1, r, a, b, v); st[id].diff = max(st[id*2].diff, st[id*2+1].diff); } void update_mn(int id, int l, int r, int i, int v) { if (i < l || i > r) return; if (l == r) { st[id].mx = -inf; st[id].mn = v; // st[id].diff = st[id].mx - st[id].mn; return; } pushdown(id); int mid = (l+r)>>1; update_mn(id*2, l, mid, i, v); update_mn(id*2+1, mid+1, r, i, v); st[id].mn = min(st[id*2].mn, st[id*2+1].mn); st[id].diff = max(st[id*2].diff, st[id*2+1].diff); } int query(int id, int l, int r, int a, int b) { if (r < a || b < l) return -inf; if (a <= l && r <= b) return st[id].diff; pushdown(id); int mid = (l+r)>>1; return max(query(id*2, l, mid, a, b), query(id*2+1, mid+1, r, a, b)); } void solve() { for (int i = 1; i <= n*4; i++) { st[i] = {-inf, inf, -inf*2}; } for (int i = 1; i <= n; i++) { add[i].clear(); del[i].clear(); } for (int i = n; i > 0; i--) { for (int j: add[i]) { update_mn(1, 1, n, j, h[j]); } for (int j: del[i]) { update_mn(1, 1, n, j, inf); } if (i + a[i] <= n) { update_mx(1, 1, n, i + a[i], min(n, i + b[i]), h[i]); } for (auto z: Q[i]) { ans[z.second] = max(ans[z.second], query(1, 1, n, i, z.first)); } if (i - a[i] > 0) add[i - a[i]].push_back(i); if (i - b[i] - 1 > 0) del[i - b[i] - 1].push_back(i); } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); fileio(""); // freopen("debug.txt", "w", stderr); cin >> n; for (int i = 1; i <= n; i++) { cin >> h[i] >> a[i] >> b[i]; } cin >> q; for (int i = 1; i <= q; i++) { cin >> l[i] >> r[i]; Q[l[i]].push_back({r[i], i}); ans[i] = -inf; } solve(); reverse(h+1, h+1+n); reverse(a+1, a+1+n); reverse(b+1, b+1+n); for (int i = 1; i <= n; i++) { Q[i].clear(); } for (int i = 1; i <= q; i++) { Q[n - r[i] + 1].push_back({n - l[i] + 1, i}); } solve(); for (int i = 1; i <= q; i++) { cout << ((ans[i] >= 0) ? ans[i] : -1) << "\n"; } return 0 ^ 0; }

컴파일 시 표준 에러 (stderr) 메시지

antennas.cpp: In function 'int32_t main()':
antennas.cpp:5:57: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define fileio(name) if (fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout)
      |                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
antennas.cpp:96:5: note: in expansion of macro 'fileio'
   96 |     fileio("");
      |     ^~~~~~
antennas.cpp:5:90: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define fileio(name) if (fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout)
      |                                                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
antennas.cpp:96:5: note: in expansion of macro 'fileio'
   96 |     fileio("");
      |     ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...