# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
13892 |
2015-04-11T01:02:20 Z |
comet |
역사적 조사 (JOI14_historical) |
C++ |
|
924 ms |
199540 KB |
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long
int N,Q,x[100010],c[100010][500],p[100010],s[100010],sz;
ll d[500][500];
int main(){
scanf("%d%d",&N,&Q);
for(int i=0;i<N;i++)scanf("%d",&x[i]),s[sz++]=x[i];
sort(s,s+sz);
sz=unique(s,s+sz)-s;
for(int i=0;i<N;i++)x[i]=lower_bound(s,s+sz,x[i])-s;
for(int i=0;i<N;i++){
if(!(i&255)){
for(int j=0;j<sz;j++)c[j][(i>>8)+1]=c[j][i>>8];
for(int j=0;j<=(i>>8);j++)d[j][(i>>8)+1]=d[j][i>>8];
}
c[x[i]][(i>>8)+1]++;
for(int j=0;j<=(i>>8);j++)d[j][(i>>8)+1]=max(d[j][(i>>8)+1],1ll*s[x[i]]*(c[x[i]][(i>>8)+1]-c[x[i]][j]));
}
int S,E,l,r;
ll ans;
while(Q--){
scanf("%d%d",&S,&E);
S--;
l=(S+255)>>8;
r=E>>8;
if(l>r){
ans=0;
for(int i=S;i<E;i++)p[x[i]]++;
for(int i=S;i<E;i++)ans=max(ans,1ll*s[x[i]]*p[x[i]]),p[x[i]]--;
}
else{
ans=d[l][r];
for(int i=S;i<(l<<8);i++)p[x[i]]++;
for(int i=(r<<8);i<E;i++)p[x[i]]++;
for(int i=S;i<(l<<8);i++)ans=max(ans,1ll*s[x[i]]*(p[x[i]]+c[x[i]][r]-c[x[i]][l])),p[x[i]]--;
for(int i=(r<<8);i<E;i++)ans=max(ans,1ll*s[x[i]]*(p[x[i]]+c[x[i]][r]-c[x[i]][l])),p[x[i]]--;
}
printf("%lld\n",ans);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
199540 KB |
Output is correct |
2 |
Correct |
0 ms |
199540 KB |
Output is correct |
3 |
Correct |
0 ms |
199540 KB |
Output is correct |
4 |
Correct |
0 ms |
199540 KB |
Output is correct |
5 |
Correct |
0 ms |
199540 KB |
Output is correct |
6 |
Correct |
0 ms |
199540 KB |
Output is correct |
7 |
Correct |
0 ms |
199540 KB |
Output is correct |
8 |
Correct |
0 ms |
199540 KB |
Output is correct |
9 |
Correct |
0 ms |
199540 KB |
Output is correct |
10 |
Correct |
0 ms |
199540 KB |
Output is correct |
11 |
Correct |
0 ms |
199540 KB |
Output is correct |
12 |
Correct |
0 ms |
199540 KB |
Output is correct |
13 |
Correct |
0 ms |
199540 KB |
Output is correct |
14 |
Correct |
0 ms |
199540 KB |
Output is correct |
15 |
Correct |
0 ms |
199540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
199540 KB |
Output is correct |
2 |
Correct |
0 ms |
199540 KB |
Output is correct |
3 |
Correct |
0 ms |
199540 KB |
Output is correct |
4 |
Correct |
0 ms |
199540 KB |
Output is correct |
5 |
Correct |
7 ms |
199540 KB |
Output is correct |
6 |
Correct |
10 ms |
199540 KB |
Output is correct |
7 |
Correct |
11 ms |
199540 KB |
Output is correct |
8 |
Correct |
9 ms |
199540 KB |
Output is correct |
9 |
Correct |
10 ms |
199540 KB |
Output is correct |
10 |
Correct |
13 ms |
199540 KB |
Output is correct |
11 |
Correct |
10 ms |
199540 KB |
Output is correct |
12 |
Correct |
12 ms |
199540 KB |
Output is correct |
13 |
Correct |
11 ms |
199540 KB |
Output is correct |
14 |
Correct |
7 ms |
199540 KB |
Output is correct |
15 |
Correct |
10 ms |
199540 KB |
Output is correct |
16 |
Correct |
11 ms |
199540 KB |
Output is correct |
17 |
Correct |
7 ms |
199540 KB |
Output is correct |
18 |
Correct |
8 ms |
199540 KB |
Output is correct |
19 |
Correct |
10 ms |
199540 KB |
Output is correct |
20 |
Correct |
7 ms |
199540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
199540 KB |
Output is correct |
2 |
Correct |
0 ms |
199540 KB |
Output is correct |
3 |
Correct |
1 ms |
199540 KB |
Output is correct |
4 |
Correct |
0 ms |
199540 KB |
Output is correct |
5 |
Correct |
1 ms |
199540 KB |
Output is correct |
6 |
Correct |
0 ms |
199540 KB |
Output is correct |
7 |
Correct |
0 ms |
199540 KB |
Output is correct |
8 |
Correct |
7 ms |
199540 KB |
Output is correct |
9 |
Correct |
9 ms |
199540 KB |
Output is correct |
10 |
Correct |
22 ms |
199540 KB |
Output is correct |
11 |
Correct |
140 ms |
199540 KB |
Output is correct |
12 |
Correct |
79 ms |
199540 KB |
Output is correct |
13 |
Correct |
133 ms |
199540 KB |
Output is correct |
14 |
Correct |
263 ms |
199540 KB |
Output is correct |
15 |
Correct |
250 ms |
199540 KB |
Output is correct |
16 |
Correct |
531 ms |
199540 KB |
Output is correct |
17 |
Correct |
118 ms |
199540 KB |
Output is correct |
18 |
Correct |
197 ms |
199540 KB |
Output is correct |
19 |
Correct |
470 ms |
199540 KB |
Output is correct |
20 |
Correct |
298 ms |
199540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
199540 KB |
Output is correct |
2 |
Correct |
54 ms |
199540 KB |
Output is correct |
3 |
Correct |
95 ms |
199540 KB |
Output is correct |
4 |
Correct |
170 ms |
199540 KB |
Output is correct |
5 |
Correct |
236 ms |
199540 KB |
Output is correct |
6 |
Correct |
209 ms |
199540 KB |
Output is correct |
7 |
Correct |
199 ms |
199540 KB |
Output is correct |
8 |
Correct |
199 ms |
199540 KB |
Output is correct |
9 |
Correct |
234 ms |
199540 KB |
Output is correct |
10 |
Correct |
279 ms |
199540 KB |
Output is correct |
11 |
Correct |
249 ms |
199540 KB |
Output is correct |
12 |
Correct |
298 ms |
199540 KB |
Output is correct |
13 |
Correct |
434 ms |
199540 KB |
Output is correct |
14 |
Correct |
761 ms |
199540 KB |
Output is correct |
15 |
Correct |
924 ms |
199540 KB |
Output is correct |
16 |
Correct |
819 ms |
199540 KB |
Output is correct |
17 |
Correct |
808 ms |
199540 KB |
Output is correct |
18 |
Correct |
776 ms |
199540 KB |
Output is correct |
19 |
Correct |
774 ms |
199540 KB |
Output is correct |
20 |
Correct |
749 ms |
199540 KB |
Output is correct |
21 |
Correct |
733 ms |
199540 KB |
Output is correct |
22 |
Correct |
718 ms |
199540 KB |
Output is correct |
23 |
Correct |
729 ms |
199540 KB |
Output is correct |
24 |
Correct |
718 ms |
199540 KB |
Output is correct |
25 |
Correct |
286 ms |
199540 KB |
Output is correct |