-
Notifications
You must be signed in to change notification settings - Fork 0
/
1613. For Fans of Statisticsseg.cpp.bak
68 lines (68 loc) · 1.58 KB
/
1613. For Fans of Statisticsseg.cpp.bak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <cstdio>
#include <cctype>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <fstream>
#include <ctime>
#include <cassert>
#include <cstring>
using namespace std;
int a[70001];
vector<int> tree[70001*4];
void create(int pos,int low,int high){
int mid=(low+high)/2;
if(low==high){
tree[pos].push_back(a[low]);
return;
}
create(2*pos,low,mid);
create(2*pos+1,mid+1,high);
for(int i=0;i<tree[2*pos].size();i++){
tree[pos].push_back(tree[2*pos][i]);
}
for(int i=0;i<tree[2*pos+1].size();i++){
tree[pos].push_back(tree[2*pos+1][i]);
}
sort(tree[pos].begin(),tree[pos].end());
}
int querry(int pos,int ll,int lr,int low,int high,int x){
if(low>high || ll>lr)
return 0;
int mid=(ll+lr)/2;
if(ll==low && lr==high )
return (binary_search(tree[pos].begin(),tree[pos].end(),x));
else if(high<=mid)
return querry(2*pos,ll,mid,low,high,x);
else if(low>mid)
return querry(2*pos+1,mid+1,lr,low,high,x);
else
return (querry(2*pos,ll,mid,low,mid,x) || querry(2*pos+1,mid+1,lr,mid+1,high,x));
return 0;
}
int main()
{
register int t;
scanf("%d",&t);
register int k=0;
memset(a,0,sizeof(a));
while(k!=t){
scanf("%d",&a[k]);
k++;
}
create(1,0,t-1);
register int q,a,b,x;
scanf("%d",&q);
while(q--){
scanf("%d %d %d",&a,&b,&x);
printf("%d",querry(1,0,t-1,a-1,b-1,x));
}
return 0;
}