题意:有一个长度为n的数组a被隐藏起来了,要求你找出该数组中第k小的数字,通过不到2*n次查询,1.查询i,j(i!=j)and的结果,2.查询i,j(i!=j)or的结果。
思路:结论题 a[i]+a[j]==a[i]&a[j]+a[i]|a[j],通过查询出1与其他所有数的and,or结果值之和,然后查询出除1外的两个数之和,并计算出所有ai的值,得出结果。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<bitset>
#include<cmath>
#include<array>
#include<atomic>
#include<sstream>
#include<stack>
#include<iomanip>
//#include<bits/stdc++.h>
//#define int ll
#define IOS std::ios::sync_with_stdio(false);std::cin.tie(0);
#define pb push_back
#define endl '\n'
#define x first
#define y second
#define Endl endl
#define pre(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,b,a) for(int i=b;i>=a;i--)
#define si(x) scanf("%d", &x);
#define sl(x) scanf("%lld", &x);
#define ss(x) scanf("%s", x);
#define YES {puts("YES");return;}
#define NO {puts("NO"); return;}
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;
typedef pair<char, int> PCI;
typedef pair<int, char> PIC;
typedef pair<double, double> PDD;
typedef pair<ll, ll> PLL;
const int N = 300010, M = 2 * N, B = N, MOD = 998244353;
const double eps = 1e-7;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
//int dx[8] = { 1,2,2,1,-1,-2,-2,-1 }, dy[8] = { 2,1,-1,-2,-2,-1,1,2 };
int n, m, k;
int a[N],b[N];
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll lowbit(ll x) { return x & -x; }
ll qmi(ll a, ll b, ll MOD) {
ll res = 1;
while (b) {
if (b & 1) res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
inline void init() {}
int ask(int type, int x, int y)
{
if (type == 1) {
cout << "and " << x << ' ' << y << endl;
fflush(stdout);
}
else {
cout << "or " << x << ' ' << y << endl;
fflush(stdout);
}
int res;
cin >> res;
return res;
}
inline void slove()
{
cin >> n >> k;
int ans = 0;
for (int i = 2; i <= n; i++)
{
int res1 = ask(1, 1, i);
int res2 = ask(2, 1, i);
b[i] = res1 + res2;
}
int a23 = ask(1, 2, 3) + ask(2, 2, 3);
a[1] = (b[2] + b[3] - a23) / 2;;
for (int i = 2; i <= n; i++)
{
a[i] = b[i] - a[1];
}
sort(a + 1, a + 1 + n);
ans = a[k];
cout << "finish " << ans << endl;
}
signed main()
{
//IOS;
int _ = 1;
//si(_);
init();
while (_--)
{
slove();
}
return 0;
}
/*
1
6 6
5 5 5 5 5 5
*/