[LOJ # 2985. "WC2019" I Jun shops

LOJ # 2985. "WC2019" I Jun shops

It's a fairy theme ah QAQ

IQ is actually not a problem ...... fucks or big data

We can use a maximum of 2N ask 1

Then, for any two values \ (x + y \) and \ (A \) Comparative

If \ (X + Y \ Leq A \) , where the minimum is then \ (0 \)

If \ (x + y \ geq a \) then the maximum value of which is 1

We compared the \ (X \) and (Y \) \ size, the total can be obtained to determine the value of a number

This is \ (7N \) of

And if we direct elections three numbers \ (x, y, a \ )

2 such that a cost of \ (x \ geq y \)

If $ x + y \ leq a $

So \ (y \) must be 0

Otherwise, the now \ (a \) thrown in a sequence, \ (x \) to become the new \ (a \) , \ (the y-\) to become the new \ (x \)

In this case we get an increasing sequence and a single value out, by this single binary value out into the sequence, all of a necessity in this sequence in

Then we can dichotomy, identify the possible position of the last zero, or this location and its previous location is 00 or 11 is the last one must be 1, by the position of the last to find a zero, followed by a sequence of it is all a 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 ;
}

Guess you like

Origin www.cnblogs.com/ivorysi/p/10938491.html