Submission #5899

# Submission time Handle Problem Language Result Execution time Memory
5899 2014-05-21T12:24:01 Z cki86201 역사적 조사 (JOI14_historical) C++
5 / 100
3704 ms 10568 KB
#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];
int p[100010];
map <int,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];

inline void ins(int x){
	int t = M[p[x]];
	++M[p[x]];
	S.insert((ll)(t+1) * p[x]);
}

inline void del(int x){
	int t = M[p[x]];
	--M[p[x]];
	S.erase((ll)t * p[x]);
}

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;
	for(i=0;i<qu;i++)if(q[i].s > q[i].d)for(i=0;;i++);
	sort(q, q+qu);
	int L = 1, R = 0;
	for(i=0;i<qu;i++){
		while(L>q[i].s)ins(--L);
		while(R<q[i].d)ins(++R);
		while(L<q[i].s)del(L++);
		while(R>q[i].d)del(R--);
		int a = M[9];
		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
1 Correct 0 ms 3572 KB Output is correct
2 Correct 0 ms 3572 KB Output is correct
3 Correct 0 ms 3572 KB Output is correct
4 Correct 0 ms 3572 KB Output is correct
5 Correct 0 ms 3572 KB Output is correct
6 Correct 0 ms 3572 KB Output is correct
7 Correct 0 ms 3572 KB Output is correct
8 Correct 0 ms 3572 KB Output is correct
9 Correct 0 ms 3572 KB Output is correct
10 Correct 0 ms 3572 KB Output is correct
11 Correct 0 ms 3572 KB Output is correct
12 Correct 0 ms 3572 KB Output is correct
13 Correct 0 ms 3572 KB Output is correct
14 Correct 0 ms 3572 KB Output is correct
15 Correct 0 ms 3572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3572 KB Output is correct
2 Correct 0 ms 3572 KB Output is correct
3 Correct 4 ms 3572 KB Output is correct
4 Correct 20 ms 3572 KB Output is correct
5 Correct 64 ms 3704 KB Output is correct
6 Incorrect 120 ms 3704 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3572 KB Output is correct
2 Correct 0 ms 3572 KB Output is correct
3 Correct 0 ms 3572 KB Output is correct
4 Correct 0 ms 3572 KB Output is correct
5 Correct 0 ms 3572 KB Output is correct
6 Correct 0 ms 3572 KB Output is correct
7 Correct 4 ms 3572 KB Output is correct
8 Correct 12 ms 3836 KB Output is correct
9 Correct 28 ms 3836 KB Output is correct
10 Correct 16 ms 3704 KB Output is correct
11 Correct 104 ms 3572 KB Output is correct
12 Correct 88 ms 4496 KB Output is correct
13 Correct 108 ms 3836 KB Output is correct
14 Correct 144 ms 5420 KB Output is correct
15 Correct 176 ms 6212 KB Output is correct
16 Correct 204 ms 10568 KB Output is correct
17 Incorrect 64 ms 4760 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 340 ms 3968 KB Output is correct
2 Correct 1480 ms 4496 KB Output is correct
3 Incorrect 3704 ms 5156 KB Output isn't correct
4 Halted 0 ms 0 KB -