LOJ番号2985. "WC2019" I 6月のお店
それは、妖精のテーマああQAQです
IQは、実際に問題が......ファックやビッグデータではありません
私たちは、1を尋ねる2Nの最大値を使用することができます
次いで、任意の二つの値のための\(X + Y \)と\(\)比較
もし\(X + Y \のLeq A \)最小その後で、\(0 \)
場合\は(X + Y \ GEQ A \) その後の最大値は1であります
我々は比較\(X \)及び(Y \)\のサイズを、合計数の値を決定するために得ることができます
これは、\(7N \)の
そして、我々は選挙に3つの数字を直接場合は\(X、Y、\ )
2その結果のコスト\(x \ GEQ Y \)
$ X + Yの\は$をLEQ場合
だから、\(のy \)は 0でなければなりません
そうでなければ、今\(\)の順序で投げ、\(X \)は、新たなになるために\(\)、\ (y軸の\)新になるための\(X \)
このケースでは、このシーケンスの中で、シーケンスに必要のすべてをこの単一のバイナリ値によって増加するシーケンスと出て単一の値を、出
その後、我々は、二分法の最後のゼロの可能な位置、またはこの場所を特定し、その以前の位置は、00または11であることができ、最後の一つのシーケンスが続くゼロを見つけること最後の位置で、1でなければなりませんでそれはすべて1であります
#include "shop.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
#define ba 47
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
vector<int> line,possible;
int S[5],T[5],k,res[MAXN];
int cmp(int a,int b) {// return a >= b
S[0] = b;T[0] = a;
return query(S,1,T,1);
}
void Binary() {
possible.clear();
for(int i = -1 ; i < (int)line.size() - 1 ; i++) {
int t = (line.size() - i - 1) ^ k ^ 1;
if(t & 1) possible.pb(i);
}
int l = 0,r = possible.size() - 1;
while(l < r) {
int mid = (l + r + 1) >> 1;
int x = possible[mid];
S[0] = line[x];S[1] = line[x - 1];T[0] = line.back();
if(query(S,2,T,1)) l = mid;
else r = mid - 1;
}
int x = possible[l];
for(int i = x + 1 ; i < line.size() ; ++i) res[line[i]] = 1;
}
void find_price(int task_id, int N, int K, int ans[]) {
memset(res,0,sizeof(res));
k = K;
if(N == 1) {ans[0] = 1;return;}
line.clear();
if(task_id == 3) {
if(cmp(N - 1,0)) {
for(int i = 0 ; i < N ; ++i) line.pb(i);
}
else {
for(int i = N - 1 ; i >= 0 ; --i) line.pb(i);
}
}
else {
int a = 0,x = 1,y;
for(int i = 2 ; i < N ; ++i) {
y = i;
if(cmp(y,x)) swap(y,x);
S[0] = x;S[1] = y;T[0] = a;
if(query(S,2,T,1)) {//x + y <= a
}
else {
line.pb(a);
a = x;x = y;
}
}
line.pb(a);
int l = 0,r = line.size() - 1;
if(cmp(x,line[r])) line.pb(x);
else {
while(l < r) {
int mid = (l + r) >> 1;
if(cmp(line[mid],x)) r = mid;
else l = mid + 1;
}
line.insert(line.begin() + l,x);
}
}
Binary();
for(int i = 0 ; i < N ; ++i) {
ans[i] = res[i];
}
return ;
}