input | output |
---|---|
5 1234567 666666 3141593 666666 4343434 5 1 5 3141593 1 5 578202 2 4 666666 4 4 7135610 1 1 1234567 |
10101 |
题意:
给出l, r, num,查找l到r中是否有数字 num;
代码如下:
#include <cstdio> #include <cmath> #include <cstring> #include <string> #include <vector> #include <set> #include <map> #include <iostream> #include <algorithm> using namespace std; map <int, vector<int> > mm; int main() { int n; while(~scanf("%d",&n)) { int tt; for(int i = 1; i <= n; i++) { scanf("%d",&tt); mm[tt].push_back(i); } int m; scanf("%d",&m); int l, r; int ans[70017]; vector<int> ::iterator iter; for(int i = 0; i < m; i++) { scanf("%d%d%d",&l,&r,&tt); int len = mm[tt].size(); if(len == 0) { ans[i] = 0; continue; } iter = lower_bound(mm[tt].begin(), mm[tt].end(),l); if(iter == mm[tt].end() || *iter > r) { ans[i] = 0; } else { ans[i] = 1; } } for(int i = 0; i < m; i++) { printf("%d",ans[i]); } printf("\n"); } return 0; } /* 5 1234567 999999999 1000000000 666666 4343434 5 1 5 3141593 1 5 578202 2 4 666666 1 5 1000000000 1 1 1234567 */
URAL 1613. For Fans of Statistics(STL 数学啊 )
原文地址:http://blog.csdn.net/u012860063/article/details/44498559