제출 #122742

#제출 시각아이디문제언어결과실행 시간메모리
122742sealnot123Two Antennas (JOI19_antennas)C++14
100 / 100
713 ms49660 KiB
#include<bits/stdc++.h> #define x first #define y second #define pb push_back #define eb emplace_back #define all(a) (a).begin(),(a).end() #define SZ(a) (int)(a).size() using namespace std; typedef long long LL; typedef pair<LL,LL> PLL; typedef pair<int,int> PII; typedef double D; typedef long double LD; const int N = 200007; const int INF = 1<<30; int validMA[4*N], validMI[4*N]; int ANS[4*N], H[N], A[N], B[N]; int MA[4*N], MI[4*N], ans[N]; int n; vector<int> come[N], go[N]; vector<PII> qq[N]; void push(int now, int l, int r){ ANS[now] = max(ANS[now], max(validMA[now] - MI[now], MA[now] - validMI[now])); if(l!=r){ if(validMA[now<<1] != -INF){ MA[now<<1] = max(MA[now<<1], MA[now]); MI[now<<1] = min(MI[now<<1], MI[now]); } if(validMA[now<<1|1] != -INF){ MA[now<<1|1] = max(MA[now<<1|1], MA[now]); MI[now<<1|1] = min(MI[now<<1|1], MI[now]); } } MA[now] = -INF; MI[now] = INF; } void add_valid(int idx, int val, int l = 1, int r = n, int now = 1){ push(now, l, r); if(l == r){ if(val==-1) validMA[now] = -INF, validMI[now] = INF; else validMA[now] = validMI[now] = val; return ; } int m = (l+r)>>1; if(idx <= m) add_valid(idx, val, l, m, now<<1); else add_valid(idx, val, m+1, r, now<<1|1); validMA[now] = max(validMA[now<<1], validMA[now<<1|1]); validMI[now] = min(validMI[now<<1], validMI[now<<1|1]); } void add_val(int ll, int rr, int val, int l = 1, int r = n, int now = 1){ push(now, l, r); if(l > rr || r < ll || validMA[now] == -INF) return ; if(l >= ll && r <= rr){ MA[now] = max(MA[now], val); MI[now] = min(MI[now], val); push(now, l, r); return; } int m = (l+r)>>1; add_val(ll, rr, val, l, m, now<<1); add_val(ll, rr, val, m+1, r, now<<1|1); ANS[now] = max(ANS[now<<1], ANS[now<<1|1]); } int get(int ll, int rr, int l = 1, int r = n, int now = 1){ push(now, l, r); if(l > rr || r < ll) return -INF; if(l >= ll && r <= rr) return ANS[now]; int m = (l+r)>>1; return max(get(ll, rr, l, m, now<<1), get(ll, rr, m+1, r, now<<1|1)); } int main(){ int i,j,k,l,a,b,c,d,q; scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d%d%d",&H[i],&A[i],&B[i]); if(i+A[i]<=n) come[i+A[i]].pb(i); if(i+B[i]<=n) go[i+B[i]].pb(i); } scanf("%d",&q); for(i=1;i<=q;i++){ scanf("%d%d",&a,&b); qq[b].pb({a,i}); } for(i=1;i<=4*n;i++) validMA[i] = MA[i] = -INF, validMI[i] = MI[i] = INF, ANS[i] = -1; for(i=1;i<=n;i++){ for(int it : come[i]) add_valid(it, H[it]); add_val(i-B[i], i-A[i], H[i]); for(PII it : qq[i]){ ans[it.y] = get(it.x, i); } for(int it : go[i]) add_valid(it, -1); } for(i=1;i<=q;i++) printf("%d\n",ans[i]); return 0; } /* 5 10 2 4 1 1 1 2 1 3 1 1 1 100 1 1 5 1 2 2 3 1 3 1 4 1 5 20 260055884 2 15 737689751 5 5 575359903 1 15 341907415 14 14 162026576 9 19 55126745 10 19 95712405 11 14 416027186 8 13 370819848 11 14 629309664 4 13 822713895 5 15 390716905 13 17 577166133 8 19 195931195 10 17 377030463 14 17 968486685 11 19 963040581 4 10 566835557 1 12 586336111 6 16 385865831 8 9 1 1 20 */

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

antennas.cpp: In function 'int main()':
antennas.cpp:77:11: warning: unused variable 'j' [-Wunused-variable]
     int i,j,k,l,a,b,c,d,q;
           ^
antennas.cpp:77:13: warning: unused variable 'k' [-Wunused-variable]
     int i,j,k,l,a,b,c,d,q;
             ^
antennas.cpp:77:15: warning: unused variable 'l' [-Wunused-variable]
     int i,j,k,l,a,b,c,d,q;
               ^
antennas.cpp:77:21: warning: unused variable 'c' [-Wunused-variable]
     int i,j,k,l,a,b,c,d,q;
                     ^
antennas.cpp:77:23: warning: unused variable 'd' [-Wunused-variable]
     int i,j,k,l,a,b,c,d,q;
                       ^
antennas.cpp:78:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
antennas.cpp:80:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&H[i],&A[i],&B[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
antennas.cpp:84:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&q);
     ~~~~~^~~~~~~~~
antennas.cpp:86:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&a,&b);
         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...