Submission #1179962

#TimeUsernameProblemLanguageResultExecution timeMemory
1179962MarwenElarbiFire (JOI20_ho_t5)C++20
0 / 100
323 ms19772 KiB
#include <bits/stdc++.h>
using namespace std;
const int nax=2e5+5;
vector<int> tab(nax);
vector<int> segtree(nax*4);
void build(int pos,int l,int r){
  if(l==r){
    segtree[pos]=tab[l];
    return;
  }
  int mid=(r+l)/2;
  build(pos*2+1,l,mid);
  build(pos*2+2,mid+1,r);
  segtree[pos]=max(segtree[pos*2+1],segtree[pos*2+2]);
}
long long query(int pos,int l,int r,int left,int right){
  if(l>r||l>right||r<left) return 0;
  if(l>=left&&r<=right) return segtree[pos];
  int mid=(r+l)/2;
  return max(query(pos*2+1,l,mid,left,right),query(pos*2+2,mid+1,r,left,right));
}
int main(){
  int n,q;
  cin>>n>>q;
  for (int i = 0; i < n; ++i)
  {
    cin>>tab[i];
  }
  vector<int> cur(n);
  multiset<int> st;
  int t;
  vector<pair<int,int>> p(q);
  for (int i = 0; i < q; ++i)
  {
    cin>>t;
    cin>>p[i].first>>p[i].second;
    p[i].first--;
    p[i].second--;
  }
  long long pre[n];
  for (int i = 0; i < n; ++i)
  {
    st.insert(tab[i]);
    if(i>=t) st.erase(st.find(tab[i-t]));
    cur[i]=*--st.end();
    pre[i]=cur[i];
    if(i) pre[i]+=pre[i-1];
  }
  for (int i = 0; i < q; ++i)
  {
    cout << pre[p[i].second] - ( p[i].first>0 ? pre[p[i].first-1] : 0 )<<endl;
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...