#include<stdio.h>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
int s2,f,w,dap,r,p,cnt,x,y,n,m,k,pos[100010],arr[100010],ch[100010],big;
struct data{
int x,y;
bool operator<(const data&r)const{
if(x==r.x) return y<r.y;
return x<r.x;
}
}imsi[100010];
int b[400][400];
vector<int>a[100010];
int main()
{
int i,j,s;
scanf("%d %d",&n,&m);
for(i=1;i<=n;i++){scanf("%d",&arr[i]); imsi[i].x=arr[i]; imsi[i].y=i;}
sort(imsi+1,imsi+n+1);
for(i=1;i<=n;i++)
{
if(imsi[i].x!=imsi[i-1].x) cnt++;
pos[cnt]=imsi[i].x; arr[imsi[i].y]=cnt; a[cnt].push_back(imsi[i].y);
}
k=sqrt(n);
for(i=1;;i++){
w=i-1; big=0; memset(ch,0,sizeof ch);
if(k*(i-1)+1>n) break;
for(j=k*(i-1)+1;j<=n;j++){
ch[arr[j]]++;
big=max(big,ch[arr[j]]*pos[arr[j]]);
if(j%k==0){w++; b[i][w]=big;}
}
if(n%k!=0){w++; b[i][w]=big;}
}
p=i;
for(i=1;i<=m;i++)
{
scanf("%d %d",&x,&y);
f=(x-1)/k+2; r=(y-1)/k;
dap=b[f][r];
for(j=x;j<=(f-1)*k;j++)
{
if(j>y) break;
s=upper_bound(a[arr[j]].begin(),a[arr[j]].end(),y)-lower_bound(a[arr[j]].begin(),a[arr[j]].end(),x);
dap=max(dap,s*pos[arr[j]]);
}
for(j=r*k+1;j<=y;j++)
{
if(j<x) break;
s=upper_bound(a[arr[j]].begin(),a[arr[j]].end(),y)-lower_bound(a[arr[j]].begin(),a[arr[j]].end(),x);
dap=max(dap,s*pos[arr[j]]);
}
printf("%d\n",dap);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
6144 KB |
Output is correct |
2 |
Incorrect |
0 ms |
6144 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6144 KB |
Output is correct |
2 |
Correct |
0 ms |
6144 KB |
Output is correct |
3 |
Correct |
0 ms |
6144 KB |
Output is correct |
4 |
Incorrect |
8 ms |
6144 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
6144 KB |
Output is correct |
2 |
Correct |
0 ms |
6144 KB |
Output is correct |
3 |
Correct |
0 ms |
6144 KB |
Output is correct |
4 |
Correct |
0 ms |
6144 KB |
Output is correct |
5 |
Correct |
4 ms |
6144 KB |
Output is correct |
6 |
Correct |
0 ms |
6144 KB |
Output is correct |
7 |
Correct |
4 ms |
6144 KB |
Output is correct |
8 |
Incorrect |
8 ms |
6144 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
128 ms |
6144 KB |
Output is correct |
2 |
Correct |
288 ms |
6144 KB |
Output is correct |
3 |
Correct |
456 ms |
6276 KB |
Output is correct |
4 |
Correct |
628 ms |
6540 KB |
Output is correct |
5 |
Correct |
836 ms |
6672 KB |
Output is correct |
6 |
Incorrect |
1600 ms |
6540 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |