-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10611 - The Playboy Chimp.cpp
193 lines (153 loc) · 5.56 KB
/
10611 - The Playboy Chimp.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/**********************************************************************
* BISMILLAHIR RAHMANIR RAHIM *
* *
* "There's a benefit to losing, you get to learn from your mistakes" *
* *
* UVa: 10611 - The Playboy Chimp *
**********************************************************************/
#include<bits/stdc++.h>
using namespace std;
//#include<algorithm>
//#include<cstdio>
//#include<sstream>
//#include<cstdlib>
//#include<cctype>
//#include<cmath>
//#include<set>
//#include<queue>
//#include<stack>
//#include<list>
//#include<iostream>
//#include<fstream>
//#include<numeric>
//#include<string>
//#include<vector>
//#include<cstring>
//#include<map>
//#include<iterator>
//#include<deque>
//#include<climits>
//#include<complex>
#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(ch) scanf("%s",ch)
#define chr getchar()
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d %d",x,y)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld %lld",x,y)
#define ps(ch) printf("%s",ch)
#define pc(ch) printf("%c",ch)
#define sf scanf
#define pf printf
#define pcs(x,y) printf("Case %d: %s", x, y)
#define pci(x,y) printf("Case %d: %d", x, y)
#define NL printf("\n")
#define nl '\n'
#define debug(x) printf("Debug %d !!\n",x)
#define mod 1000000007
#define FI freopen("in.txt","r",stdin)
#define FO freopen("out.txt","w",stdout)
#define FOR(i,j,k) for(i = j; i < k; i++)
#define rep(l,n) FOR(l,0,n)
#define REV(i,j,k) for(i = j; i > k; i--)
#define PI acos(-1.0)
#define INF_MAX 2147483647
#define INF_MIN -2147483647
//#define sz 100
#define pb(x) push_back(x)
#define sz(x) x.size()
#define mem(ara,val) memset(ara,val,sizeof(ara))
#define ssz(a) strlen(a)
#define eps 1e-9
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector< PII > VII;
//template <typename T> T BigMod (T b,T p,T m){if (p == 0) return 1;if (p%2 == 0){T s = BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;}
//template <typename T> T ModInv (T b,T m){return BigMod(b,m-2,m);}
//template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9') break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9') break;}return (ng?-n:n);}
//template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1); else return SQR(POW(B,P/2));}
//template <typename T> T Bigmod(T b,T p,T m){ if(p==0) return 1; else if (!(p&1)) return SQR(Bigmod(b,p/2,m)) % m;else return ((b % m) * Bigmod(b,p-1,m)) % m;}
//template <typename T> T Dis(T x1,T y1,T x2, T y2){return sqrt( SQR(x1-x2) + SQR(y1-y2) );}
//template <typename T> T Angle(T x1,T y1,T x2, T y2){ return atan( double(y1-y2) / double(x1-x2));}
//template <typename T> T DIFF(T a,T b) { T d = a-b;if(d<0)return -d;else return d;}
//template <typename T> T ABS(T a) {if(a<0)return -a;else return a;}
//template <typename T> T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
//template <typename T> T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
//template <typename T> T euclide(T a,T b,T &x,T &y) {if(a<0){T d=euclide(-a,b,x,y);x=-x;return d;} if(b<0){T d=euclide(a,-b,x,y);y=-y;return d;} if(b==0){x=1;y=0;return a;}else{T d=euclide(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}
//template <typename T> void ia (T a[],int n){for (int i=0; i<n; i++) cin >> a[i];}
//template <typename T> void pa (T a[],int n){for (int i=0; i<n-1; i++) cout << a[i] << " ";cout << a[n-1] << endl;}
//template <typename T> LL isLeft(T a,T b,T c) { return (a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y); }
//template<class T> inline T GCD(T a, T b) { if(a<0) return GCD(-a,b); if(b<0)return GCD(a,-b); while(b){b^=a^=b^=a%=b;} return a; }
//template<class T> inline T LCM(T a, T b) { return a/GCD(a,b)*b; }
//#define CFw
const int siz = 100000 + 10;
VI v;
map<int,int> M;
int bsl(int c, int sz){
int m, h = sz-1, l = 0, k = -1;
while(l <= h){
m = (h + l) >> 1;
if(v[m] < c){
l = m + 1;
k = m;
}
else
h = m - 1;
}
return k;
}
int bsu(int c, int sz){
int m, h = sz-1, l = 0, k = -1;
while(l <= h){
m = (h + l) >> 1;
if(v[m] > c){
h = m - 1;
k = m;
}
else
l = m + 1;
}
return k;
}
int main(){
//std::ios_base::sync_with_stdio(0);
#ifdef CFw
while(1){
#endif
//FI;FO;
int t, z = 0, l, i, n, len;
v.clear();
M.clear();
si(t);
rep(l,t){
si(n);
if(!M[n]){
v.pb(n);
M[n] = 1;
}
}
si(n);
while(n--){
si(t);
z = bsl(t,v.size());
if(z == -1) ps("X");
else pi(v[z]);
ps(" ");
z = bsu(t,v.size());
if(z == -1) ps("X");
else pi(v[z]);
NL;
}
#ifdef CFw
NL;
}
#endif
return 0;
}