제출 #934185

#제출 시각아이디문제언어결과실행 시간메모리
934185AdamGSTwo Antennas (JOI19_antennas)C++17
100 / 100
595 ms58604 KiB
#include<bits/stdc++.h> using namespace std; typedef long double ld; typedef long long ll; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const ll INF=1e18+7; const int LIM=2e5+7; struct Node { ll val, lazy, mi; }; Node tr[4*LIM]; vector<ll>V[LIM], wlacz[LIM], wylacz[LIM]; ll T[LIM], wynik[LIM], A[LIM], B[LIM], N=1; pair<ll,ll>pyt[LIM]; void spl(int v) { tr[2*v].lazy=max(tr[2*v].lazy, tr[v].lazy); tr[2*v+1].lazy=max(tr[2*v+1].lazy, tr[v].lazy); tr[2*v].val=max(tr[2*v].val, tr[2*v].lazy-tr[2*v].mi); tr[2*v+1].val=max(tr[2*v+1].val, tr[2*v+1].lazy-tr[2*v+1].mi); tr[v].lazy=-INF; } void maxuj(int v, int l, int r, int a, int b, ll x) { if(r<a || b<l) return; if(a<=l && r<=b) { tr[v].lazy=max(tr[v].lazy, x); tr[v].val=max(tr[v].val, tr[v].lazy-tr[v].mi); return; } if(tr[v].lazy!=-INF) spl(v); int mid=(l+r)/2; maxuj(2*v, l, mid, a, b, x); maxuj(2*v+1, mid+1, r, a, b, x); tr[v].val=max(tr[2*v].val, tr[2*v+1].val); tr[v].mi=min(tr[2*v].mi, tr[2*v+1].mi); } void upd(int v, int l, int r, int a, ll x) { if(r<a || a<l) return; if(l==r) { tr[v].mi=x; tr[v].lazy=-INF; return; } if(tr[v].lazy!=-INF) spl(v); int mid=(l+r)/2; upd(2*v, l, mid, a, x); upd(2*v+1, mid+1, r, a, x); tr[v].val=max(tr[2*v].val, tr[2*v+1].val); tr[v].mi=min(tr[2*v].mi, tr[2*v+1].mi); } ll cnt(int v, int l, int r, int a, int b) { if(r<a || b<l) return -INF; if(a<=l && r<=b) return tr[v].val; if(tr[v].lazy!=-INF) spl(v); int mid=(l+r)/2; return max(cnt(2*v, l, mid, a, b), cnt(2*v+1, mid+1, r, a, b)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll n; cin >> n; while(N<n) N*=2; rep(i, 2*N) { tr[i].val=tr[i].lazy=-INF; tr[i].mi=INF; } rep(i, n) { cin >> T[i] >> A[i] >> B[i]; if(i+A[i]<n) wlacz[i+A[i]].pb(i); if(i+B[i]+1<n) wylacz[i+B[i]+1].pb(i); } ll q; cin >> q; rep(i, q) { cin >> pyt[i].st >> pyt[i].nd; --pyt[i].st; --pyt[i].nd; wynik[i]=-1; V[pyt[i].nd].pb(i); } rep(i, n) { for(auto j : wlacz[i]) upd(1, 0, N-1, j, T[j]); for(auto j : wylacz[i]) upd(1, 0, N-1, j, INF); maxuj(1, 0, N-1, i-B[i], i-A[i], T[i]); for(auto j : V[i]) wynik[j]=max(wynik[j], cnt(1, 0, N-1, pyt[j].st, pyt[j].nd)); } rep(i, n) { V[i].clear(); wlacz[i].clear(); wylacz[i].clear(); } rep(i, 2*N) { tr[i].val=tr[i].lazy=-INF; tr[i].mi=INF; } rep(i, n/2) { swap(T[i], T[n-i-1]); swap(A[i], A[n-i-1]); swap(B[i], B[n-i-1]); } rep(i, q) { pyt[i].st=n-pyt[i].st-1; pyt[i].nd=n-pyt[i].nd-1; swap(pyt[i].st, pyt[i].nd); } rep(i, n) { if(i+A[i]<n) wlacz[i+A[i]].pb(i); if(i+B[i]+1<n) wylacz[i+B[i]+1].pb(i); } rep(i, q) V[pyt[i].nd].pb(i); rep(i, n) { for(auto j : wlacz[i]) upd(1, 0, N-1, j, T[j]); for(auto j : wylacz[i]) upd(1, 0, N-1, j, INF); maxuj(1, 0, N-1, i-B[i], i-A[i], T[i]); for(auto j : V[i]) wynik[j]=max(wynik[j], cnt(1, 0, N-1, pyt[j].st, pyt[j].nd)); } rep(i, q) cout << wynik[i] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...