제출 #18648

#제출 시각아이디문제언어결과실행 시간메모리
18648mindol역사적 조사 (JOI14_historical)C++14
100 / 100
3156 ms6768 KiB
#include<cstdio> #include<vector> #include<algorithm> using namespace std; vector<int> cpr; int a[100001]; struct Query{ int s,e,index; long long ans; } d[100001]; int sq=316; bool comp_sqd(Query a,Query b) { if(a.s/sq==b.s/sq) return a.e<b.e; else return a.s<b.s; } bool comp_ind(Query a,Query b){ return a.index<b.index; } long long tree[1<<18]; int base=1<<17; void add(int place,int value) { place+=base-1; tree[place]+=value; for(place>>=1;place>=1;place>>=1) tree[place]=max(tree[place*2],tree[place*2+1]); } int main() { int n,q; scanf("%d %d",&n,&q); for(int i=1;i<=n;i++) scanf("%d",&a[i]), cpr.push_back(a[i]); sort(cpr.begin(),cpr.end()); for(int i=1;i<=n;i++) a[i]=lower_bound(cpr.begin(),cpr.end(),a[i])-cpr.begin()+1; for(int i=1;i<=q;i++) scanf("%d %d",&d[i].s,&d[i].e),d[i].index=i; sort(d+1,d+1+q,comp_sqd); int s=1,e=0; // [s,e] for(int i=1;i<=q;i++) { while(e<d[i].e) { e++; add(a[e],cpr[a[e]-1]); } while(e>d[i].e) { add(a[e],-cpr[a[e]-1]); e--; } while(s>d[i].s) { s--; add(a[s],cpr[a[s]-1]); } while(s<d[i].s) { add(a[s],-cpr[a[s]-1]); s++; } d[i].ans=tree[1]; } sort(d+1,d+1+q,comp_ind); for(int i=1;i<=q;i++) printf("%lld\n",d[i].ans); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...