結果
問題 | No.2978 Lexicographically Smallest and Largest Subarray |
ユーザー |
![]() |
提出日時 | 2024-12-02 02:05:39 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 207 ms / 2,000 ms |
コード長 | 1,878 bytes |
コンパイル時間 | 3,112 ms |
コンパイル使用メモリ | 251,392 KB |
実行使用メモリ | 25,728 KB |
平均クエリ数 | 1499.00 |
最終ジャッジ日時 | 2024-12-02 02:05:58 |
合計ジャッジ時間 | 18,159 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 57 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define FOR(i,m,n) for(int i=(m);i<(n);++i)#define REP(i,n) FOR(i,0,n)using ll = long long;constexpr int INF = 0x3f3f3f3f;constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;constexpr double EPS = 1e-8;constexpr int MOD = 998244353;// constexpr int MOD = 1000000007;constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};template <typename T, typename U>inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }template <typename T, typename U>inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }struct IOSetup {IOSetup() {std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);std::cout << fixed << setprecision(20);}} iosetup;int main() {int n, q; cin >> n >> q;const auto is_greater_than = [n](const int l, const int r) -> bool {cout << "? " << l + 1 << ' ' << n << ' ' << r + 1 << ' ' << n << endl;int x; cin >> x;assert(x != -1);return x == 1;};vector<pair<int, int>> minmaxs;for (int i = 1; i < n; i += 2) {minmaxs.emplace_back(is_greater_than(i - 1, i) ? make_pair(i - 1, i) : make_pair(i, i - 1));}if (n % 2 == 1) minmaxs.emplace_back(n - 1, n - 1);while (minmaxs.size() > 1) {vector<pair<int, int>> nxt;nxt.reserve((minmaxs.size() + 1) / 2);for (int i = 1; i < minmaxs.size(); i += 2) {const auto [l1, r1] = minmaxs[i - 1];const auto [l2, r2] = minmaxs[i];nxt.emplace_back(is_greater_than(l1, l2) ? l1 : l2, is_greater_than(r1, r2) ? r2 : r1);}if (minmaxs.size() % 2 == 1) nxt.emplace_back(minmaxs.back());minmaxs.swap(nxt);}const auto& [l, r] = minmaxs.front();cout << "! " << l + 1 << ' ' << l + 1 << ' ' << r + 1 << ' ' << n << endl;return 0;}