#include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct node{ int id , k ; } p[80000]; bool cmp(node a,node b) { return a.k<b.k || ( a.k==b.k && a.id < b.id ); } void f(int l,int r,int x,int n) { int low = 0 , top = n-1 ; while(low <= top) { int mid = (low+top)/2 ; if( p[mid].k == x && p[mid].id >= l && p[mid].id <= r ) { printf("1"); return ; } else if( p[mid].k < x || ( p[mid].k == x && p[mid].id < l ) ) low = mid+1 ; else top = mid - 1 ; } printf("0"); return ; } int main() { int i , n , m , l , r , x ; while(scanf("%d", &n)!=EOF) { for(i = 0 ; i < n ; i++) { scanf("%d", &p[i].k); p[i].id = i+1 ; } sort(p,p+n,cmp); scanf("%d", &m); while(m--) { scanf("%d %d %d", &l, &r, &x); f(l,r,x,n); } printf("\n"); } }
STL--G - For Fans of Statistics(两个判断条件-二分),布布扣,bubuko.com
STL--G - For Fans of Statistics(两个判断条件-二分)
原文:http://blog.csdn.net/winddreams/article/details/38375499