This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
ll p[100010];
map <ll,int> M;
set <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 : 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("%lld",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)S.insert(++M[p[--L]] * p[L]);
while(R<q[i].d)S.insert(++M[p[++R]] * p[R]);
while(L<q[i].s)S.erase(M[p[L]]-- * p[L++]);
while(R>q[i].d)S.erase(M[p[R]]-- * p[R--]);
ans[q[i].c] = *(--S.end());
}
for(i=0;i<qu;i++)printf("%lld\n",ans[i]);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |