제출 #1058659

#제출 시각아이디문제언어결과실행 시간메모리
1058659Jarif_RahmanTwo Antennas (JOI19_antennas)C++17
13 / 100
1382 ms524288 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; struct segtree{ int k; vector<int> v; segtree(int n){ k = 1; while(k < n) k*=2; v.resize(2*k, -1); } void update(int in, int x){ in+=k; v[in] = max(v[in], x); in/=2; while(in > 0){ v[in] = max(v[2*in], v[2*in+1]); in/=2; } } int get(int l, int r, int nd, int a, int b){ if(b < l || a > r) return -1; if(a >= l && b <= r) return v[nd]; int c = (a+b)/2; return max(get(l, r, 2*nd, a, c), get(l, r, 2*nd+1, c+1, b)); } int get(int l, int r){ return get(l, r, 1, 0, k-1); } }; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> H(n), A(n), B(n); for(int i = 0; i < n; i++){ cin >> H[i] >> A[i] >> B[i]; } vector<vector<pair<int, int>>> ed(n); for(int i = 0; i < n; i++) for(int j = i+1; j < n; j++){ if(j >= i+A[i] && j <= i+B[i] && i >= j-B[j] && i <= j-A[j]) ed[j].push_back({i, abs(H[i]-H[j])}); } segtree S(n); int q; cin >> q; vector<int> ans(q, -1); vector<vector<pair<int, int>>> queries(n); for(int i = 0; i < q; i++){ int l, r; cin >> l >> r; l--, r--; queries[r].push_back({l, i}); } for(int i = 0; i < n; i++){ for(auto [j, h]: ed[i]) S.update(j, h); for(auto [l, in]: queries[i]) ans[in] = S.get(l, i); } for(int x: ans) cout << x << "\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...