結果

問題 No.2978 Lexicographically Smallest and Largest Subarray
ユーザー sibasyun
提出日時 2024-12-16 17:31:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 5,444 bytes
コンパイル時間 5,399 ms
コンパイル使用メモリ 279,352 KB
最終ジャッジ日時 2025-02-26 14:46:39
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 57
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
#include <atcoder/all>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <random>
#include <chrono>
#include <cstdint>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace atcoder;
using namespace __gnu_pbds;
using mint = modint998244353;
// using mint = modint1000000007;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vvvl = vector<vector<vector<long long>>>;
using vm = vector<mint>;
using vvm = vector<vector<mint>>;
using vvvm = vector<vector<vector<mint>>>;
using ll = long long;
using pd_ds_set_int = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
using pd_ds_set_ll = tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> using max_heap = priority_queue<T>;
template <class T> using min_heap = priority_queue<T, vector<T>, greater<>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, f, n) for (int i = (int) f; i < (int)(n); i++)
#define repd(i, n, l) for (int i = (int) n; i >= (int) l; i--)
#define all(p) p.begin(),p.end()
vector<pair<int, int>> dydx{{-1, 0}, {1, 0}, {0, -1 }, {0, 1}};
const ll inf = 1LL << 60;
void print(){ putchar(' '); }
void print(bool a){ printf("%d", a); }
void print(int a){ printf("%d", a); }
void print(unsigned a){ printf("%u", a); }
void print(long a){ printf("%ld", a); }
void print(long long a){ printf("%lld", a); }
void print(unsigned long long a){ printf("%llu", a); }
void print(char a){ printf("%c", a); }
void print(char a[]){ printf("%s", a); }
void print(const char a[]){ printf("%s", a); }
void print(float a){ printf("%.15f", a); }
void print(double a){ printf("%.15f", a); }
void print(long double a){ printf("%.15Lf", a); }
void print(const string& a){ for(auto&& i : a) print(i); }
template<class T> void print(const complex<T>& a){ if(a.real() >= 0) print('+'); print(a.real()); if(a.imag() >= 0) print('+'); print(a.imag());
    print('i'); }
template<class T> void print(const vector<T>&);
template<class T, size_t size> void print(const array<T, size>&);
template<class T, class L> void print(const pair<T, L>& p);
template<class T, size_t size> void print(const T (&)[size]);
template<class T> void print(const vector<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print
    (*i); } }
template<class T> void print(const deque<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i
    ); } }
template<class T, size_t size> void print(const array<T, size>& a){ print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i);
    } }
template<class T, class L> void print(const pair<T, L>& p){ print(p.first); putchar(' '); print(p.second); }
template<class T, size_t size> void print(const T (&a)[size]){ print(a[0]); for(auto i = a; ++i != end(a); ){ putchar(' '); print(*i); } }
template<class T> void print(const T& a){ cout << a; }
constexpr ll ten(int n){
return n==0?1:ten(n-1)*10;
}
template <typename T>
vector<T> compress_coordinate(vector<T> &A){
int n = A.size();
vector<T> B(n);
rep(i, n) B[i] = A[i];
sort(B.begin(), B.end());
B.erase(unique(B.begin(), B.end()), B.end());
return B;
}
vector<vector<int>> unweighted_graph(int n, int m){
vector<vector<int>> ret(n);
while (m--){
int a, b;
cin >> a >> b;
a--; b--;
ret[a].push_back(b);
ret[b].push_back(a);
}
return ret;
}
vector<vector<pair<int, long long>>> weighted_graph(int n, int m){
vector<vector<pair<int, long long>>> ret(n);
while (m--){
int a, b;
long long c;
cin >> a >> b >> c;
a--, b--;
ret[a].push_back({b, c});
ret[b].push_back({a, c});
}
return ret;
}
template<typename T>
int argmin(vector<T> &a){
T mi = *min_element(all(a));
for (int i = 0; i < a.size(); i++){
if (a[i] == mi) return i;
}
}
template<typename T>
int argmax(vector<T> &a){
T ma = *max_element(all(a));
for (int i = 0; i < a.size(); i++){
if (a[i] == ma) return i;
}
}
int query(int l, int r, int L, int R){
cout << "? " << l << ' ' << r << ' ' << L << ' ' << R << endl;
int ret;
cin >> ret;
return ret;
}
void answer(int l, int r, int L, int R){
cout << "! " << l << ' ' << r << ' ' << L << ' ' << R << endl;
}
int main() {
int n, q;
cin >> n >> q;
vi smaller, larger;
for (int i = 1; i <= n; i+=2){
int x = query(i, n, i+1, n);
if (x == 1){
smaller.push_back(i);
larger.push_back(i+1);
} else if (x == 0){
smaller.push_back(i+1);
larger.push_back(i);
} else {
return 0;
}
}
int smallest = smaller[0];
int largest = larger[0];
for (int i = 1; i < smaller.size(); i++){
int x = query(smallest, n, smaller[i], n);
if (x == 0){
smallest = smaller[i];
}
}
for (int i = 1; i < larger.size(); i++){
int x = query(largest, n, larger[i], n);
if (x == 1){
largest = larger[i];
}
}
answer(smallest, smallest, largest, n);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0