比赛 20160415x 评测结果 WWWWTTTTTTTTTTTTTTTT
题目名称 数字查询 最终得分 0
用户昵称 KZNS 运行时间 32.549 s
代码语言 C++ 内存使用 0.34 MiB
提交时间 2016-04-15 16:12:34
显示代码纯文本
//KZNS
#include <fstream>
#include <map>
using namespace std;
//
ifstream fin ("numquery.in");
ofstream fout ("numquery.out");
const int Nmax = 40003;
//
int main() {
	int N, M;
	int A[Nmax];
	fin >> N >> M;
	for (int i = 1; i <= N; i++)
		fin >> A[i];
	int a, b;
	map<int, int> mp;
	map<int, int> ::iterator mpi;
	for (int i = 0; i < M; i++) {
		fin >> a >> b;
		mp.clear();
		for (int i = a; i <= b; i++)
			mp[A[i]]++;
		a = 0;
		b = 0;
		for (mpi = mp.begin(); mpi != mp.end(); mpi++) {
			if (mpi->second > a) {
				a = mpi->second;
				b = mpi->first;
			}
		}
		fout << b << endl;
	}
	return 0;
}
//UBWH