제출 #170430

#제출 시각아이디문제언어결과실행 시간메모리
170430gs18103Two Antennas (JOI19_antennas)C++14
0 / 100
472 ms20980 KiB
#include <bits/stdc++.h> #define fi first #define se second #define eb emplace_back #define em emplace #define all(v) v.begin(), v.end() #define my_assert cout << "!" << endl; using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; const int MAX = 101010; const int INF = (1 << 30) - 1; const ll LINF = 1LL << 60; struct antena { int h, a, b; } arr[2*MAX]; struct SEG { vector <pii> tree; vector <int> lazy; SEG(int n) { tree.resize(4*n+10); lazy.resize(4*n+10); for(int i = 1; i < tree.size(); i++) { tree[i].fi = -1; tree[i].se = INF; lazy[i] = -INF; } } void update_lazy(int node, int s, int e) { tree[node].fi = max(tree[node].fi, lazy[node] - tree[node].se); if(s != e) { lazy[node*2] = max(lazy[node*2], lazy[node]); lazy[node*2+1] = max(lazy[node*2+1], lazy[node]); } } void update1(int node, int s, int e, int l, int r, int val) { if(l > r) return; update_lazy(node, s, e); if(s > r || e < l) return; if(s >= l && e <= r) { lazy[node] = max(lazy[node], val); update_lazy(node, s, e); return; } int m = (s + e) / 2; update1(node*2, s, m, l, r, val), update1(node*2+1, m+1, e, l, r, val); tree[node].fi = max(tree[node*2].fi, tree[node*2+1].fi); } void update2(int node, int s, int e, int k, bool flag) { update_lazy(node, s, e); if(s == e) { if(flag) tree[node].se = arr[k].h; else tree[node].se = INF; return; } int m = (s + e) / 2; if(k <= m) update2(node*2, s, m, k, flag); else update2(node*2+1, m+1, e, k, flag); tree[node].se = min(tree[node*2].se, tree[node*2+1].se); } int cal(int node, int s, int e, int l, int r) { update_lazy(node, s, e); if(s > r || e < l) return -1; if(s >= l && e <= r) return tree[node].fi; int m = (s + e) / 2; return max(cal(node*2, s, m, l, r), cal(node*2+1, m+1, e, l, r)); } }; struct Query { int l, r, idx; } Q[2*MAX]; int ans[2*MAX], n, q; void solve() { SEG st(n); int idx = 0; priority_queue <pii, vector <pii>, greater <pii> > pq1, pq2; for(int i = 1; i <= q; i++) { while(idx < Q[i].r) { while(!pq2.empty() && pq2.top().fi == idx) { st.update2(1, 1, n, pq2.top().se, false); pq2.pop(); } idx++; while(!pq1.empty() && pq1.top().fi == idx) { st.update2(1, 1, n, pq1.top().se, true); pq1.pop(); } st.update1(1, 1, n, max(1, idx - arr[idx].b), max(0, idx - arr[idx].a), arr[idx].h); pq1.em(idx + arr[idx].a, idx); pq2.em(idx + arr[idx].b, idx); } ans[Q[i].idx] = max(ans[Q[i].idx], st.cal(1, 1, n, Q[i].l, Q[i].r)); } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for(int i = 1; i <= n; i++) { cin >> arr[i].h >> arr[i].a >> arr[i].b; } cin >> q; for(int i = 1; i <= q; i++) { cin >> Q[i].l >> Q[i].r; Q[i].idx = i; ans[i] = -1; } sort(Q+1, Q+q+1, [](Query a, Query b) { if(a.r == b.r) return a.l < b.l; return a.r < b.r; }); solve(); for(int i = 1; i <= n; i++) { arr[i].h = -arr[i].h; } solve(); for(int i = 1; i <= q; i++) { cout << ans[i] << '\n'; } }

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

antennas.cpp: In constructor 'SEG::SEG(int)':
antennas.cpp:29:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 1; i < tree.size(); i++) {
                        ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...