접기
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <unistd.h>
using namespace std;
using int32 = int32_t;
using int64 = int64_t;
const int BUF_SIZE = 1 << 20; // 메모리 초과 가능, 적당히 조절할 것.
char input_buf[BUF_SIZE], output_buf[BUF_SIZE];
int input_buf_pos, output_buf_pos;
enum io_mode {READ, WRITE};
inline void char_io(io_mode mode, char &target)
{
if(mode == READ) {
if (input_buf_pos == BUF_SIZE)
{
fread(input_buf, sizeof(char), BUF_SIZE, stdin);
input_buf_pos = 0;
}
target = input_buf[input_buf_pos++];
}
else {
if(output_buf_pos == BUF_SIZE || target == EOF)
{
fwrite(output_buf, sizeof(char), output_buf_pos, stdout);
output_buf_pos = 0;
}
output_buf[output_buf_pos++] = target;
}
}
inline void char_io(io_mode mode, char &&target){
char_io(mode, target);
}
inline void int_io(io_mode mode, int &target)
{
char c;
if(mode == READ){
bool negative = false;
int ret = 0;
while(true)
{
char_io(READ, c);
if(c == '\n' || c == ' ') break;
if(c == '-') {
negative = true;
continue;
}
ret = ret * 10 + (c & 0b1111);
}
target = negative ? -ret : ret;
}
else {
int abs = target;
int div = 1'000'000'000;
char quotient = 0;
if(abs < 0) {
char_io(WRITE, '-');
abs *= -1;
}
while(abs < div && div != 1) { div /= 10; }
while(div != 0){
quotient = '0' + (char)((abs / div)%10);
char_io(WRITE, quotient);
div /= 10;
}
}
}
inline void int_io(io_mode mode, int &&target){
int_io(mode, target);
}
int32 N, A[100'000];
int32 M, MVal;
bool test(int32 idx){
return A[idx] <= MVal;
}
int main() {
int_io(READ, N);
for(int32 i=0; i<N; i++) int_io(READ, A[i]);
sort(A, A+N);
int_io(READ, M);
int32 start, end, mid, ret;
while(M--){
int_io(READ, MVal);
start = 0; end = N; ret = 0;
while(start < end){
mid = (start + end)/2;
if(test(mid)){
if(ret < mid) ret = mid;
start = mid+1;
}
else end = mid;
}
int_io(WRITE, A[ret] == MVal);
char_io(WRITE, '\n');
}
char_io(WRITE, EOF);
}
접기