#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
map<int, int> chk;
int N,Q,C,X[100010],O[100010],Z,F; long long R[100010],B[100100],A[100010];
struct seg{
seg(int s_, int e_, int i_){s = s_; e = e_; i = i_;}
int s,e,i;
bool operator <(const seg t)const{return e != t.e ? e < t.e : s < t.s;}
};
vector<seg> intv[201];
void upt(int x, int p)
{
x = X[x]; O[x] += p;
B[x+F] = R[x] * O[x];
x = (x + F + 2) / 4;
while (x){
B[x] = max(max(B[x*4-2],B[x*4-1]),max(B[x*4],B[x*4+1]));
x = (x + 2) / 4;
}
}
int main()
{
scanf ("%d %d",&N,&Q);
for (int i=0;i<N;i++){
scanf ("%d",&X[i]);
chk[X[i]] = 0;
}
for (map<int, int>::iterator I = chk.begin(); I != chk.end(); I++) R[C] = I->first, I->second = C++;
for (int i=0;i<N;i++) X[i] = chk[X[i]];
for (Z=1;Z<C;Z<<=2) F += Z; F++;
for (int i=0,s,e;i<Q;i++){
scanf ("%d %d",&s,&e); s--;
intv[s/1000].push_back(seg(s,e,i));
}
for (int i=0;i<100;i++) if (!intv[i].empty()){
for (int k=0;k<F+Z;k++) B[k] = 0;
for (int k=0;k<C;k++) O[k] = 0;
int s = 0, e = 0;
sort(intv[i].begin(),intv[i].end());
for (int j=0;j<intv[i].size();j++){
while (e < intv[i][j].e) upt(e++,1);
//while (e > intv[i][j].e) upt(--e,-1);
while (s < intv[i][j].s) upt(s++,-1);
while (s > intv[i][j].s) upt(--s,1);
A[intv[i][j].i] = B[1];
}
}
for (int i=0;i<Q;i++) printf ("%lld\n",A[i]);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4344 KB |
Output is correct |
2 |
Correct |
0 ms |
4344 KB |
Output is correct |
3 |
Correct |
0 ms |
4344 KB |
Output is correct |
4 |
Correct |
0 ms |
4344 KB |
Output is correct |
5 |
Correct |
0 ms |
4344 KB |
Output is correct |
6 |
Correct |
0 ms |
4344 KB |
Output is correct |
7 |
Correct |
0 ms |
4344 KB |
Output is correct |
8 |
Correct |
0 ms |
4344 KB |
Output is correct |
9 |
Correct |
0 ms |
4344 KB |
Output is correct |
10 |
Correct |
0 ms |
4344 KB |
Output is correct |
11 |
Correct |
0 ms |
4344 KB |
Output is correct |
12 |
Correct |
0 ms |
4344 KB |
Output is correct |
13 |
Correct |
0 ms |
4344 KB |
Output is correct |
14 |
Correct |
0 ms |
4344 KB |
Output is correct |
15 |
Correct |
0 ms |
4344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4344 KB |
Output is correct |
2 |
Correct |
0 ms |
4344 KB |
Output is correct |
3 |
Correct |
4 ms |
4344 KB |
Output is correct |
4 |
Correct |
12 ms |
4344 KB |
Output is correct |
5 |
Correct |
32 ms |
4344 KB |
Output is correct |
6 |
Correct |
52 ms |
4344 KB |
Output is correct |
7 |
Correct |
56 ms |
4344 KB |
Output is correct |
8 |
Correct |
44 ms |
4344 KB |
Output is correct |
9 |
Correct |
44 ms |
4344 KB |
Output is correct |
10 |
Correct |
80 ms |
4480 KB |
Output is correct |
11 |
Correct |
80 ms |
4476 KB |
Output is correct |
12 |
Correct |
80 ms |
4488 KB |
Output is correct |
13 |
Correct |
80 ms |
4492 KB |
Output is correct |
14 |
Correct |
64 ms |
4344 KB |
Output is correct |
15 |
Correct |
68 ms |
4496 KB |
Output is correct |
16 |
Correct |
56 ms |
4344 KB |
Output is correct |
17 |
Correct |
24 ms |
4344 KB |
Output is correct |
18 |
Correct |
68 ms |
4476 KB |
Output is correct |
19 |
Correct |
80 ms |
4484 KB |
Output is correct |
20 |
Correct |
76 ms |
4484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4344 KB |
Output is correct |
2 |
Correct |
0 ms |
4344 KB |
Output is correct |
3 |
Correct |
0 ms |
4344 KB |
Output is correct |
4 |
Correct |
0 ms |
4344 KB |
Output is correct |
5 |
Correct |
0 ms |
4344 KB |
Output is correct |
6 |
Correct |
0 ms |
4344 KB |
Output is correct |
7 |
Correct |
4 ms |
4344 KB |
Output is correct |
8 |
Correct |
8 ms |
4476 KB |
Output is correct |
9 |
Correct |
56 ms |
4608 KB |
Output is correct |
10 |
Correct |
40 ms |
4344 KB |
Output is correct |
11 |
Correct |
328 ms |
5540 KB |
Output is correct |
12 |
Correct |
204 ms |
4344 KB |
Output is correct |
13 |
Correct |
644 ms |
4872 KB |
Output is correct |
14 |
Correct |
912 ms |
6984 KB |
Output is correct |
15 |
Correct |
956 ms |
8312 KB |
Output is correct |
16 |
Runtime error |
108 ms |
9628 KB |
SIGSEGV Segmentation fault |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
4492 KB |
Output is correct |
2 |
Correct |
300 ms |
4608 KB |
Output is correct |
3 |
Correct |
656 ms |
5028 KB |
Output is correct |
4 |
Correct |
964 ms |
5564 KB |
Output is correct |
5 |
Correct |
1316 ms |
5824 KB |
Output is correct |
6 |
Correct |
1488 ms |
5596 KB |
Output is correct |
7 |
Correct |
1264 ms |
5600 KB |
Output is correct |
8 |
Correct |
1268 ms |
5724 KB |
Output is correct |
9 |
Correct |
880 ms |
5872 KB |
Output is correct |
10 |
Correct |
696 ms |
5988 KB |
Output is correct |
11 |
Correct |
1320 ms |
6008 KB |
Output is correct |
12 |
Correct |
2000 ms |
5988 KB |
Output is correct |
13 |
Correct |
2844 ms |
6264 KB |
Output is correct |
14 |
Correct |
3696 ms |
7444 KB |
Output is correct |
15 |
Correct |
3816 ms |
8644 KB |
Output is correct |
16 |
Correct |
3792 ms |
8104 KB |
Output is correct |
17 |
Correct |
3732 ms |
7852 KB |
Output is correct |
18 |
Correct |
3712 ms |
7732 KB |
Output is correct |
19 |
Correct |
3712 ms |
7572 KB |
Output is correct |
20 |
Correct |
3668 ms |
7308 KB |
Output is correct |
21 |
Correct |
3676 ms |
7308 KB |
Output is correct |
22 |
Correct |
3648 ms |
7332 KB |
Output is correct |
23 |
Correct |
3640 ms |
7180 KB |
Output is correct |
24 |
Correct |
3652 ms |
7032 KB |
Output is correct |
25 |
Correct |
308 ms |
5992 KB |
Output is correct |