結果
問題 | No.2978 Lexicographically Smallest and Largest Subarray |
ユーザー |
![]() |
提出日時 | 2024-12-02 00:17:20 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 232 ms / 2,000 ms |
コード長 | 1,833 bytes |
コンパイル時間 | 3,292 ms |
コンパイル使用メモリ | 255,432 KB |
実行使用メモリ | 25,464 KB |
平均クエリ数 | 1499.00 |
最終ジャッジ日時 | 2024-12-02 00:17:38 |
合計ジャッジ時間 | 18,094 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 57 |
ソースコード
#include <bits/stdc++.h>// #include <atcoder/all>using namespace std;// using namespace atcoder;// using mint = modint1000000007;// const int mod = 1000000007;// using mint = modint998244353;// const int mod = 998244353;const int INF = 1e9;const long long LINF = 1e18;#define rep(i, n) for (int i = 0; i < (n); ++i)#define rep2(i, l, r) for (int i = (l); i < (r); ++i)#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)#define rrep2(i, l, r) for (int i = (r) - 1; i >= (l); --i)#define all(x) (x).begin(), (x).end()#define allR(x) (x).rbegin(), (x).rend()#define P pair<int, int>bool dbg = false;vector<int> v = { 2,3,1,4 };bool test(vector<int>q) {vector<int>v0, v1;rep2(i, q[0], q[1] + 1)v0.push_back(v[i]);rep2(i, q[2], q[3] + 1)v1.push_back(v[i]);return v0 < v1;}bool query(std::vector<int>v, int add = 1) {std::cout << "? ";rep(i, 4)cout << v[i] + 1 << " ";cout << endl;if (dbg) return test(v);int n; cin >> n;return n;}void answer(std::vector<int>v, int add = 1) {std::cout << "! ";rep(i, 4)cout << v[i] + 1 << " ";cout << endl;fflush(stdout);}int main() {int n, q; cin >> n >> q;queue<int>mn, mx;rep(i, n / 2) {int p = i * 2;int q = p + 1;auto get = query({ p,n - 1,q,n - 1 });if (get) {mn.push(p);mx.push(q);}else {mn.push(q);mx.push(p);}}while (mn.size() >= 2) {auto p = mn.front();mn.pop();auto q = mn.front();mn.pop();auto get = query({ p,p,q,q });if (get) {mn.push(p);}else {mn.push(q);}}while (mx.size() >= 2) {auto p = mx.front();mx.pop();auto q = mx.front();mx.pop();auto get = query({ p,n - 1,q,n - 1 });if (get) {mx.push(q);}else {mx.push(p);}}int mni = mn.front();int mxi = mx.front();answer({ mni, mni, mxi, n - 1 });return 0;}