답안 #5907

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
5907 2014-05-22T11:35:08 Z cki86201 역사적 조사 (JOI14_historical) C++
5 / 100
4000 ms 8052 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;
multiset <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("%d",p+i);
	for(i=0;i<qu;i++)scanf("%d%d",&q[i].s,&q[i].d), q[i].c = i;
	int L = 1, R = 0;
	for(i=0;i<qu;i++){
		while(L>q[i].s)S.insert(++M[p[--L]] * (ll)p[L]);
		while(R<q[i].d)S.insert(++M[p[++R]] * (ll)p[R]);
		while(L<q[i].s)S.erase(S.find(M[p[L]]-- * (ll)p[L++]));
		while(R>q[i].d)S.erase(S.find(M[p[R]]-- * (ll)p[R--]));
		ans[q[i].c] = *S.rbegin();
	}
	for(i=0;i<qu;i++)printf("%lld\n",ans[i]);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3568 KB Output is correct
2 Correct 0 ms 3568 KB Output is correct
3 Correct 0 ms 3568 KB Output is correct
4 Correct 0 ms 3568 KB Output is correct
5 Correct 0 ms 3568 KB Output is correct
6 Correct 0 ms 3568 KB Output is correct
7 Correct 0 ms 3568 KB Output is correct
8 Correct 0 ms 3568 KB Output is correct
9 Correct 0 ms 3568 KB Output is correct
10 Correct 0 ms 3568 KB Output is correct
11 Correct 0 ms 3568 KB Output is correct
12 Correct 0 ms 3568 KB Output is correct
13 Correct 0 ms 3568 KB Output is correct
14 Correct 0 ms 3568 KB Output is correct
15 Correct 0 ms 3568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3568 KB Output is correct
2 Correct 12 ms 3568 KB Output is correct
3 Correct 56 ms 3568 KB Output is correct
4 Correct 256 ms 3568 KB Output is correct
5 Correct 1144 ms 3700 KB Output is correct
6 Correct 2792 ms 3700 KB Output is correct
7 Correct 3100 ms 3700 KB Output is correct
8 Correct 2480 ms 3700 KB Output is correct
9 Correct 2536 ms 3700 KB Output is correct
10 Execution timed out 4000 ms 3832 KB Program timed out
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3568 KB Output is correct
2 Correct 0 ms 3568 KB Output is correct
3 Correct 0 ms 3568 KB Output is correct
4 Correct 8 ms 3568 KB Output is correct
5 Correct 228 ms 3568 KB Output is correct
6 Correct 68 ms 3700 KB Output is correct
7 Correct 180 ms 3832 KB Output is correct
8 Correct 60 ms 4228 KB Output is correct
9 Correct 920 ms 5020 KB Output is correct
10 Correct 1300 ms 5812 KB Output is correct
11 Execution timed out 4000 ms 8052 KB Program timed out
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4000 ms 3960 KB Program timed out
2 Halted 0 ms 0 KB -