-
Notifications
You must be signed in to change notification settings - Fork 0
/
1613. For Fans of Statistics.cpp
77 lines (75 loc) · 1.63 KB
/
1613. For Fans of Statistics.cpp
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
69
70
71
72
73
74
75
76
77
#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cmath>
using namespace std;
int A[70000];
int main()
{
int t;
scanf("%d",&t);
int k=0;
while(t--){
scanf("%d",&A[k]);
k++;
}
int sqr=ceil(sqrt(k/1.0));
vector< vector<int> > cities(k/sqr+1);
for(int i=0;i<k;i++)
{
cities[i/sqr].push_back(A[i]);
//cout<<k/sqr;
}
//cout<<"YO";
for(int i=0;i<cities.size();i++)
sort(cities[i].begin(),cities[i].end());
int q;
scanf("%d",&q);
while(q--){
int l,r,x;
scanf("%d %d %d",&l,&r,&x);
l-=1;
r-=1;
int first=l/sqr;
int second=r/sqr;
if(first==second){
bool ya=0;
for(int i=l;i<=r;i++){
if(A[i]==x){
ya=1;
break;
}
}
if(ya)
cout<<1;
else
cout<<0;
}
else{
bool ya=0;
for(int i=l;i<(first+1)*sqr;i++){
if(A[i]==x){
ya=1;
break;
}
}
for(int j=first+1;j<second;j++){
if(binary_search(cities[j].begin(),cities[j].end(),x)){
ya=1;
break;
}
}
for(int i=(second)*sqr;i<=r;i++){
if(A[i]==x){
ya=1;
break;
}
}
if(ya)
cout<<1;
else
cout<<0;
}
}
}