Submission #944151

#TimeUsernameProblemLanguageResultExecution timeMemory
944151beepbeepsheepTriple Jump (JOI19_jumps)C++17
5 / 100
3918 ms524288 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ii pair<ll,ll> #ifndef DEBUG #define cerr if (0) cerr #define endl '\n' #endif const ll maxn=5005; const ll inf=1e15; ll arr[maxn]; struct node{ ll s,e,m,val; node *l,*r; node (ll _s, ll _e){ s=_s,e=_e,m=(s+e)>>1,val=0; if (s!=e) l=new node(s,m),r=new node(m+1,e); } void upd(ll x, ll v){ if (s==e){ val=max(v,val); return; } if (x>m) r->upd(x,v); else l->upd(x,v); val=max(l->val,r->val); } ll query(ll x, ll y){ if (x<=s && e<=y) return val; if (x>m) return r->query(x,y); if (y<=m) return l->query(x,y); return max(l->query(x,y),r->query(x,y)); } }*root,*rmq; ll n; vector<tuple<ll,ll,ll>> v,q; ll ans[maxn]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; root=new node(1,n); for (int i=1;i<=n;i++) cin>>arr[i],root->upd(i,arr[i]); for (int i=1;i<=n;i++){ for (int j=i+2;j<=n;j++){ v.emplace_back(i,j,arr[i]+arr[j]+ root->query(i+1,(i+j)>>1)); //cerr<<i<<' '<<j<<' '<<arr[i]+arr[j]+root->query(i+1,(i+j)>>1)<<endl; } } sort(v.rbegin(),v.rend()); rmq=new node(1,n); ll qu,l,r; cin>>qu; for (int i=1;i<=qu;i++){ cin>>l>>r; q.emplace_back(l,r,i); } sort(q.rbegin(),q.rend()); ll ptr=0; for (auto [l,r,i]:q){ while (ptr!=v.size() && l<=get<0>(v[ptr])){ rmq->upd(get<1>(v[ptr]),get<2>(v[ptr])); ptr++; } ans[i]=rmq->query(l,r); } for (int i=1;i<=qu;i++){ cout<<ans[i]<<endl; } return 0; }

Compilation message (stderr)

jumps.cpp: In function 'int main()':
jumps.cpp:64:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::tuple<long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         while (ptr!=v.size() && l<=get<0>(v[ptr])){
      |                ~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...