-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1eac08e
commit 1d9f4e3
Showing
7 changed files
with
560 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,239 @@ | ||
#include <algorithm> | ||
#include <bitset> | ||
#include <deque> | ||
#include <iostream> | ||
#include <queue> | ||
#include <set> | ||
#include <stack> | ||
#include <stdlib.h> | ||
#include <unordered_set> | ||
#include <vector> | ||
#include<functional> | ||
/// ordered sets support upperbound lowerbound too | ||
#include <map> | ||
#include <unordered_map> | ||
#include <cstring> | ||
#define len(v) (int)v.size() | ||
#define all(v) v.begin(), v.end() | ||
#define rall(v) v.rbegin(), v.rend() | ||
using namespace std; | ||
using ll = long long; | ||
#define pb push_back | ||
#define rep(i, a, b) for (int i = a; i < b; i++) | ||
#define f first | ||
#define mk make_pair | ||
#define in insert | ||
#define py cout << "YES\n" | ||
#define pn cout << "NO\n" | ||
#define fill(v,a,b) rep(i,a,b)cin>>v[i] | ||
template <typename T> void chkmin(T &x, T y) { | ||
if (x > y) | ||
x = y; | ||
} | ||
template <typename T> void chkmax(T &x, T y) { | ||
if (x < y) | ||
x = y; | ||
} | ||
|
||
#ifndef ONLINE_JUDGE | ||
#define debug(x) cout << #x << " = " << x << endl | ||
#define show1(v) \ | ||
for (auto i : v) \ | ||
cout << i << ' ' | ||
#define show(v) \ | ||
show1(v); \ | ||
cout << '\n' | ||
#define __gcd __algo_gcd | ||
#else | ||
#define debug(x) | ||
#endif | ||
const ll INF = 1e9; | ||
const ll LINF = INF * INF; | ||
|
||
// ------------------------------------------***-------------------------------------------------- | ||
|
||
|
||
|
||
void solve() { | ||
ll n;cin>>n; | ||
cout<<"? 0 0 1 1"<<endl; | ||
cout.flush(); | ||
char c;cin>>c; | ||
ll best; | ||
if(c == '>')best = 0; | ||
else best = 1; | ||
rep(i,2,n){ | ||
cout<<"? "<<i<<' '<<i<<' '<<best<<' '<<best<<endl; | ||
cout.flush(); | ||
cin>>c; | ||
if(c =='>')best = i; | ||
} | ||
ll bestans = 64 - __builtin_clzll(n); | ||
bestans = (1<<bestans) - 1; | ||
ll best2; | ||
cout<<"? "<<best<<" 0 1 "<<best<<endl; | ||
cout.flush(); | ||
vector<ll>possible; | ||
cin>>c; | ||
if(c=='>')possible.push_back(0); | ||
else if(c=='<')possible.push_back(1); | ||
else{ | ||
possible.push_back(0);possible.push_back(1); | ||
} | ||
best2 = possible.back(); | ||
rep(i,2,n){ | ||
if(i==best)continue; | ||
cout<<"? "<<i<<" "<<best<<" "<<best2<<' '<<best<<endl; | ||
cout.flush(); | ||
cin>>c; | ||
if(c=='>'){ | ||
possible.clear(); | ||
possible.push_back(i); | ||
best2 = i; | ||
} | ||
else if(c=='='){ | ||
possible.push_back(i); | ||
} | ||
} | ||
ll mn = possible[0]; | ||
rep(i,1,possible.size()){ | ||
cout<<"? "<<mn<<" "<<mn<<" "<<possible[i]<<" "<<possible[i]<<endl; | ||
cout.flush(); | ||
cin>>c; | ||
if(c=='>'){ | ||
mn = possible[i]; | ||
} | ||
} | ||
cout<<"! "<<best<<" "<<mn<<'\n'; | ||
cout.flush(); | ||
} | ||
|
||
int32_t main() { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
int t; | ||
cin >> t; | ||
while (t--) { | ||
solve(); | ||
} | ||
return 0; | ||
}#include <algorithm> | ||
#include <bitset> | ||
#include <deque> | ||
#include <iostream> | ||
#include <queue> | ||
#include <set> | ||
#include <stack> | ||
#include <stdlib.h> | ||
#include <unordered_set> | ||
#include <vector> | ||
#include<functional> | ||
/// ordered sets support upperbound lowerbound too | ||
#include <map> | ||
#include <unordered_map> | ||
#include <cstring> | ||
#define len(v) (int)v.size() | ||
#define all(v) v.begin(), v.end() | ||
#define rall(v) v.rbegin(), v.rend() | ||
using namespace std; | ||
using ll = long long; | ||
#define pb push_back | ||
#define rep(i, a, b) for (int i = a; i < b; i++) | ||
#define f first | ||
#define mk make_pair | ||
#define in insert | ||
#define py cout << "YES\n" | ||
#define pn cout << "NO\n" | ||
#define fill(v,a,b) rep(i,a,b)cin>>v[i] | ||
template <typename T> void chkmin(T &x, T y) { | ||
if (x > y) | ||
x = y; | ||
} | ||
template <typename T> void chkmax(T &x, T y) { | ||
if (x < y) | ||
x = y; | ||
} | ||
|
||
#ifndef ONLINE_JUDGE | ||
#define debug(x) cout << #x << " = " << x << endl | ||
#define show1(v) \ | ||
for (auto i : v) \ | ||
cout << i << ' ' | ||
#define show(v) \ | ||
show1(v); \ | ||
cout << '\n' | ||
#define __gcd __algo_gcd | ||
#else | ||
#define debug(x) | ||
#endif | ||
const ll INF = 1e9; | ||
const ll LINF = INF * INF; | ||
|
||
// ------------------------------------------***-------------------------------------------------- | ||
|
||
|
||
|
||
void solve() { | ||
ll n;cin>>n; | ||
cout<<"? 0 0 1 1"<<endl; | ||
cout.flush(); | ||
char c;cin>>c; | ||
ll best; | ||
if(c == '>')best = 0; | ||
else best = 1; | ||
rep(i,2,n){ | ||
cout<<"? "<<i<<' '<<i<<' '<<best<<' '<<best<<endl; | ||
cout.flush(); | ||
cin>>c; | ||
if(c =='>')best = i; | ||
} | ||
ll bestans = 64 - __builtin_clzll(n); | ||
bestans = (1<<bestans) - 1; | ||
ll best2; | ||
cout<<"? "<<best<<" 0 1 "<<best<<endl; | ||
cout.flush(); | ||
vector<ll>possible; | ||
cin>>c; | ||
if(c=='>')possible.push_back(0); | ||
else if(c=='<')possible.push_back(1); | ||
else{ | ||
possible.push_back(0);possible.push_back(1); | ||
} | ||
best2 = possible.back(); | ||
rep(i,2,n){ | ||
if(i==best)continue; | ||
cout<<"? "<<i<<" "<<best<<" "<<best2<<' '<<best<<endl; | ||
cout.flush(); | ||
cin>>c; | ||
if(c=='>'){ | ||
possible.clear(); | ||
possible.push_back(i); | ||
best2 = i; | ||
} | ||
else if(c=='='){ | ||
possible.push_back(i); | ||
} | ||
} | ||
ll mn = possible[0]; | ||
rep(i,1,possible.size()){ | ||
cout<<"? "<<mn<<" "<<mn<<" "<<possible[i]<<" "<<possible[i]<<endl; | ||
cout.flush(); | ||
cin>>c; | ||
if(c=='>'){ | ||
mn = possible[i]; | ||
} | ||
} | ||
cout<<"! "<<best<<" "<<mn<<'\n'; | ||
cout.flush(); | ||
} | ||
|
||
int32_t main() { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
int t; | ||
cin >> t; | ||
while (t--) { | ||
solve(); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define forn for(int i=0; i<n; i++) | ||
#define arr(a, n) velo a(n); for(int i=0; i<n; i++){cin >> a[i];} | ||
#define inp(b) ll b; cin >> b; | ||
#define rep(i, j, n) for(int i=j; i<n; i++) | ||
#define cyes cout << "YES" << "\n" | ||
#define cno cout << "NO" << "\n" | ||
#define pb push_back | ||
#define minpq priority_queue<int, vector<int>, greater<int>> | ||
#define pq priority_queue | ||
#define F first | ||
#define S second | ||
#define mx(a) max_element(a.begin(), a.end()) | ||
#define mn(a) min_element(a.begin(), a.end()) | ||
#define print(a, b) cout << a << " " << b << nl | ||
#define nl "\n" | ||
|
||
const int M = 1000000007; | ||
typedef long long ll; | ||
typedef vector<int> vi; | ||
typedef vector<long long> velo; | ||
|
||
|
||
int bin_search(velo &a, ll num){ | ||
int n = a.size(); | ||
int hi = n-1, lo = 0, mid, big = -1; | ||
while (lo <= hi){ | ||
mid = (lo + hi)/2; | ||
if (a[mid] == num){return mid;} | ||
else if (a[mid] > num){ | ||
big = mid; | ||
hi = mid - 1; | ||
} | ||
else{ | ||
lo = mid + 1; | ||
} | ||
} | ||
return big; | ||
} | ||
|
||
void print_vec(velo &a){ | ||
for(auto x : a){ | ||
cout << x << " ";} | ||
cout << "\n"; | ||
} | ||
|
||
//----------------------------------------------------------- | ||
|
||
void solve(){ | ||
ll n, q; cin >> n >> q; | ||
arr(a, n); | ||
string ans, s; | ||
forn{ | ||
ans += '0'; | ||
} | ||
auto check = [&] (int val){ | ||
s = ""; | ||
ll q1 = q; | ||
for(int i = 0; i < n; i++){ | ||
if(i < val){ | ||
if(a[i] <= q){ | ||
s += '1'; | ||
} | ||
else{ | ||
s += '0'; | ||
} | ||
} | ||
else{ | ||
if(q1 == 0) return false; | ||
if(a[i] > q1){ | ||
q1--; | ||
} | ||
s += '1'; | ||
} | ||
} | ||
return true; | ||
}; | ||
int lo = 0, hi = n-1; | ||
while(lo <= hi){ | ||
int mid = (lo + hi)/2; | ||
if(check(mid)){ | ||
ans = s; | ||
hi = mid-1; | ||
} | ||
else lo = mid + 1; | ||
} | ||
cout << ans << nl; | ||
} | ||
|
||
int main(){ | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
cout.tie(NULL); | ||
int t; | ||
cin >> t; | ||
while (t--){ | ||
solve(); | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.