제출 #132405

#제출 시각아이디문제언어결과실행 시간메모리
132405KewoTwo Antennas (JOI19_antennas)C++17
22 / 100
469 ms79488 KiB
#include <bits/stdc++.h> #define pb push_back #define ppb pop_back #define fi first #define se second #define mid ((x + y) / 2) #define left (ind * 2) #define right (ind * 2 + 1) #define mp make_pair #define timer ((double)clock() / CLOCKS_PER_SEC) #define endl "\n" #define spc " " #define d1(x) cerr<<#x<<":"<<x<<endl #define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl #define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl #define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; typedef long long int lli; typedef pair<int, int> ii; typedef pair<ii, int> iii; typedef pair<double, double> dd; const int N = (int)(1e6 + 5); const int LOG = (int)(20); const int inf = (int)(1e9 + 5); int n, q, h[N], a[N], b[N], ans, tree[N << 2]; vector<int> v[N]; vector<ii> pt[N]; void upd(int ind, int x, int y, int a, int val) { if(y < a || a < x) return; if(x == y && x == a) { tree[ind] = val; return; } upd(left, x, mid, a, val); upd(right, mid + 1, y, a, val); tree[ind] = max(tree[left], tree[right]); } int get(int ind, int x, int y, int a, int b) { if(b == 0) return -inf; if(y < a || b < x) return -inf; if(a <= x && y <= b) return tree[ind]; return max(get(left, x, mid, a, b), get(right, mid + 1, y, a, b)); } void solve() { memset(tree, -1, sizeof tree); for(int i = 1; i <= n; i++) pt[i].clear(); for(int i = 1; i <= n; i++) { pt[min(n, i + a[i])].pb({i, 0}); pt[min(n + 1, i + b[i] + 1)].pb({i, 1}); } for(int i = 1; i <= n; i++) { for(auto j : pt[i]) { if(j.se == 0) upd(1, 1, n, j.fi, h[j.fi]); else upd(1, 1, n, j.fi, -1); } ans = max(ans, get(1, 1, n, max(1, i - b[i]), max(0, i - a[i])) - h[i]); } } int main() { fast_io(); // freopen("inp.in", "r", stdin); 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++) { int a, b; cin >> a >> b; // v[b].pb({a, i}); } solve(); reverse(a + 1, a + n + 1); reverse(b + 1, b + n + 1); reverse(h + 1, h + n + 1); solve(); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...