Submission #552857

#TimeUsernameProblemLanguageResultExecution timeMemory
552857cheetoseTriple Jump (JOI19_jumps)C++17
100 / 100
1075 ms104108 KiB
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define X first #define Y second #define y0 y12 #define y1 y22 #define INF 987654321987654321 #define PI 3.141592653589793238462643383279502884 #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c)) #define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c)) #define MEM0(a) memset((a),0,sizeof(a)) #define MEM_1(a) memset((a),-1,sizeof(a)) #define ALL(a) a.begin(),a.end() #define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin()) #define SYNC ios_base::sync_with_stdio(false);cin.tie(0) using namespace std; typedef long long ll; typedef long double ld; typedef double db; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int, int> Pi; typedef pair<ll, ll> Pll; typedef pair<ld, ld> Pd; typedef vector<int> Vi; typedef vector<ll> Vll; typedef vector<ld> Vd; typedef vector<Pi> VPi; typedef vector<Pll> VPll; typedef vector<Pd> VPd; typedef tuple<int, int, int> iii; typedef tuple<int, int, int, int> iiii; typedef tuple<ll, ll, ll> LLL; typedef vector<iii> Viii; typedef vector<LLL> VLLL; typedef complex<double> base; const int MOD = 998244353; ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; } int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 }; int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 }; ll a[500001],tree[1050000],lazy[1050000],mx[1050000]; void init(int node,int S,int E){ tree[node]=-INF; if(S==E){ mx[node]=a[S]; return; } init(2*node,S,(S+E)/2); init(2*node+1,(S+E)/2+1,E); mx[node]=max(mx[2*node],mx[2*node+1]); } void propagation(int node,int S,int E){ if(lazy[node]!=0){ tree[node]=max(tree[node],lazy[node]+mx[node]); if(S!=E){ lazy[2*node]=max(lazy[node*2],lazy[node]); lazy[2*node+1]=max(lazy[node*2+1],lazy[node]); } lazy[node]=0; } } void upd(int node,int S,int E,int i,int j,ll val){ propagation(node,S,E); if(i>E || j<S) return; if(j>=E && i<=S){ lazy[node]=max(lazy[node],val); propagation(node,S,E); return; } upd(2*node,S,(S+E)/2,i,j,val); upd(2*node+1,(S+E)/2+1,E,i,j,val); tree[node]=max(tree[2*node],tree[2*node+1]); } ll find(int node,int S,int E,int i,int j){ propagation(node,S,E); if(i>E || j<S)return 0; if(j>=E && i<=S)return tree[node]; return max(find(node*2,S,(S+E)/2,i,j),find(2*node+1,(S+E)/2+1,E,i,j)); } ll ans[500005]; Vi v[500005]; VPi Q[500005]; int main(){ int n; scanf("%d",&n); fup(i,1,n,1)scanf("%lld",a+i); Vi st; fup(i,1,n,1){ while(!st.empty() && a[st.back()]<a[i]){ v[st.back()].pb(i); st.pop_back(); } if(!st.empty()){ v[st.back()].pb(i); } st.pb(i); } init(1,1,n); int q; scanf("%d",&q); fup(i,0,q-1,1){ int x,y; scanf("%d%d",&x,&y); Q[x].pb(mp(y,i)); } fdn(i,n,1,1){ for(int j:v[i]){ upd(1,1,n,2*j-i,n,a[i]+a[j]); } for(auto [j,I]:Q[i]){ ans[I]=find(1,1,n,i,j); } } fup(i,0,q-1,1)printf("%lld\n",ans[i]); }

Compilation message (stderr)

jumps.cpp: In function 'int main()':
jumps.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
jumps.cpp:88:2: note: in expansion of macro 'fup'
   88 |  fup(i,1,n,1)scanf("%lld",a+i);
      |  ^~~
jumps.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
jumps.cpp:90:2: note: in expansion of macro 'fup'
   90 |  fup(i,1,n,1){
      |  ^~~
jumps.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
jumps.cpp:103:2: note: in expansion of macro 'fup'
  103 |  fup(i,0,q-1,1){
      |  ^~~
jumps.cpp:11:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   11 | #define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
      |                              ^
jumps.cpp:108:2: note: in expansion of macro 'fdn'
  108 |  fdn(i,n,1,1){
      |  ^~~
jumps.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
jumps.cpp:116:2: note: in expansion of macro 'fup'
  116 |  fup(i,0,q-1,1)printf("%lld\n",ans[i]);
      |  ^~~
jumps.cpp:87:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
jumps.cpp:88:19: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |  fup(i,1,n,1)scanf("%lld",a+i);
      |              ~~~~~^~~~~~~~~~~~
jumps.cpp:102:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |  scanf("%d",&q);
      |  ~~~~~^~~~~~~~~
jumps.cpp:105:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |   scanf("%d%d",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...