Submission #5909

#TimeUsernameProblemLanguageResultExecution timeMemory
5909cki86201역사적 조사 (JOI14_historical)C++98
40 / 100
4000 ms11888 KiB
#include<stdio.h> #include<math.h> #include<algorithm> #include<map> #include<set> using namespace std; typedef long long ll; int n, k, qu; ll ans[100010], a; int p[100010]; map <int,int> M; multiset <ll> S; struct qua{ qua(){} qua(int s,int d):s(s),d(d){} int s, d, c; bool operator<(const qua &l)const{ return d/k != l.d/k ? d/k < l.d/k : (((d/k)&1) ? s < l.s : s > l.s); } }q[100010]; int main() { scanf("%d%d",&n,&qu); k = int(sqrt(n)); int i; for(i=1;i<=n;i++)scanf("%d",p+i); for(i=0;i<qu;i++)scanf("%d%d",&q[i].s,&q[i].d), q[i].c = i; sort(q,q+qu); int L = 1, R = 0; for(i=0;i<qu;i++){ while(L>q[i].s){ a = ++M[p[--L]] * (ll)p[L]; S.insert(a); if(a != p[L])S.erase(S.find(a - p[L])); } while(R<q[i].d){ a = ++M[p[++R]] * (ll)p[R]; S.insert(a); if(a != p[R])S.erase(S.find(a - p[R])); } while(L<q[i].s){ a = M[p[L]]-- * (ll)p[L]; S.erase(S.find(a)); if(a != p[L])S.insert(a - p[L]); ++L; } while(R>q[i].d){ a = M[p[R]]-- * (ll)p[R]; S.erase(S.find(a)); if(a != p[R])S.insert(a - p[R]); --R; } ans[q[i].c] = *S.rbegin(); } for(i=0;i<qu;i++)printf("%lld\n",ans[i]); 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...