제출 #1255131

#제출 시각아이디문제언어결과실행 시간메모리
1255131thdh__Two Antennas (JOI19_antennas)C++20
100 / 100
506 ms58360 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define eb emplace_back #define pu push #define ins insert #define fi first #define se second #define all(a) a.begin(),a.end() #define bruh ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define fu(x,a,b) for (auto x=a;x<=b;x++) #define fd(x,a,b) for (auto x=a;x>=b;x--) #define int ll using namespace std; //mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); /* Competitive Programming notes that I need to study & fix my dumbass self: 1. Coding: - Always be sure to check the memory of arrays (maybe use vectors), for loops - Always try to maximize the memory if possible, even if you are going for subtasks - Do not exploit #define int long long, it will kill you 2. Stress: - Always try generating big testcases and try if they run 3. Time management: - Don't overcommit or undercommit, always spend a certain amount of time to think a problem, don't just look at it and say I'm fucked - Do not spend too much time coding brute-force solutions, they should be easily-codable solutions that don't take up too much time Time management schedule: Offline / LAH days (4 problems - 3h): 15' thinking of solution / idea 1. no idea: skip 2. yes idea: continue thinking for <= 15' + implementing: <= 20' + brute-force: <= 5' + test generator: <= 5' I hate offline because I am dumb */ typedef pair<int, int> ii; const int N = 2e5+5; const int B = 750; const int mod = 1e9+7; const int inf = 1e18; using cd = complex<double>; const long double PI = acos(-1); int power(int a,int b) {ll x = 1;if (a >= mod) a%=mod; while (b) {if (b & 1) x = x*a % mod;a = a*a % mod;b>>=1;}return x;} struct node { int mx1 = -inf, mn1 = inf; int lmn = inf, lmx = -inf; int mxa = -1; node(){} node(int mx1, int mn1, int lmn, int lmx, int mxa): mx1(mx1), mn1(mn1), lmn(lmn), lmx(lmx), mxa(mxa) {} }; node st[4*N]; int eval(node a) { return max(a.mx1 - a.lmn, a.lmx - a.mn1); } void push(int id, int l, int r) { st[id*2].lmx = max(st[id*2].lmx, st[id].lmx), st[id*2].lmn = min(st[id*2].lmn, st[id].lmn); st[id*2+1].lmx = max(st[id*2+1].lmx, st[id].lmx), st[id*2+1].lmn = min(st[id*2+1].lmn, st[id].lmn); st[id*2].mxa = max(st[id*2].mxa, max(st[id*2].mx1-st[id].lmn, st[id].lmx-st[id*2].mn1)); st[id*2+1].mxa = max(st[id*2+1].mxa, max(st[id*2+1].mx1-st[id].lmn, st[id].lmx-st[id*2+1].mn1)); st[id].lmn = inf, st[id].lmx = -inf; } void turn(int id, int l, int r, int i, int val) { if (l > i || r < i) return; if (l == r) { st[id].mx1 = st[id].mn1 = val; return; } int mid = l+r>>1; push(id, l, r); turn(id*2, l, mid, i, val); turn(id*2+1, mid+1, r, i, val); st[id].mx1 = max(st[id*2].mx1, st[id*2+1].mx1); st[id].mn1 = min(st[id*2].mn1, st[id*2+1].mn1); st[id].mxa = max(st[id*2].mxa, st[id*2+1].mxa); } void off(int id, int l, int r, int i) { if (l > i || r < i) return; if (l == r) { st[id].mx1 = -inf, st[id].mn1 = inf; return; } int mid = l+r>>1; push(id, l, r); off(id*2, l, mid, i); off(id*2+1, mid+1, r, i); st[id].mx1 = max(st[id*2].mx1, st[id*2+1].mx1); st[id].mn1 = min(st[id*2].mn1, st[id*2+1].mn1); st[id].mxa = max(st[id*2].mxa, st[id*2+1].mxa); } void update(int id, int l, int r, int u, int v, int val) { if (l > v || r < u) return; if (u <= l && r <= v) { st[id].lmx = max(st[id].lmx, val); st[id].lmn = min(st[id].lmn, val); st[id].mxa = max(st[id].mxa, max(st[id].mx1-val, val-st[id].mn1)); return; } int mid = l+r>>1; push(id, l, r); update(id*2, l, mid, u, v, val); update(id*2+1, mid+1, r, u, v, val); st[id].mxa = max(st[id*2].mxa, st[id*2+1].mxa); } int get(int id, int l, int r, int u, int v) { if (l > v || r < u) return -1; if (u <= l && r <= v) return st[id].mxa; int mid = l+r>>1; push(id, l, r); return max(get(id*2, l, mid, u, v), get(id*2+1, mid+1, r, u, v)); } int n,q; int h[N], a[N], b[N], ans[N]; vector<ii> qu[N]; vector<ii> delta[N]; void solve() { cin>>n; for (int i = 1; i <= n; i++) { cin>>h[i]>>a[i]>>b[i]; if (i+a[i] <= n) delta[i+a[i]].pb({i, 0}); if (i+b[i]+1 <= n) delta[i+b[i]+1].pb({i, 1}); } cin>>q; for (int i = 0; i < q; i++) { int l,r; cin>>l>>r; qu[r].pb({l,i}); } for (int i = 1; i <= n; i++) { for (auto j : delta[i]) { if (j.se == 0) turn(1,1,n,j.fi,h[j.fi]); else off(1,1,n,j.fi); } if (i-a[i] >= 1) update(1,1,n,max(1ll, i-b[i]), i-a[i], h[i]); for (auto j : qu[i]) ans[j.se] = max(-1ll, get(1,1,n,j.fi,i)); } for (int i = 0; i < q; i++) cout<<ans[i]<<endl; } /* Go through the mistakes you usually make and revise your code, for god's sake... */ signed main() { bruh //freopen("input.inp","r",stdin); //freopen("output.inp","w",stdout); int t = 1; // cin>>t; while (t--) { solve(); cout<<"\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...