您的位置:首页 > 其它

Ural1613-For Fans of Statistics

2016-11-19 10:08 363 查看
给定一串数字,一个区间和一个数x,问区间内是否有一个数正好等于x。

#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

map<int, vector<int> > m;
vector<int> ans;

int main(int argc, char const *argv[]) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int val;
scanf("%d", &val);
m[val].push_back(i);
}
int q;
scanf("%d", &q);
for (int i = 0; i < q; i++) {
int l, r, x;
scanf("%d%d%d", &l, &r, &x);
if (m.find(x) != m.end()) {
vector<int>::iterator it = lower_bound(m[x].begin(), m[x].end(), l);
if (it != m[x].end() && *it <= r) {
ans.push_back(1);
} else {
ans.push_back(0);
}
} else {
ans.push_back(0);
}
}
for (int i = 0; i < ans.size(); i++) {
printf("%d", ans[i]);
}
putchar('\n');
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: