結果
| 問題 | No.875 Range Mindex Query |
| コンテスト | |
| ユーザー |
tanimani364
|
| 提出日時 | 2021-04-12 16:15:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,184 bytes |
| 記録 | |
| コンパイル時間 | 2,031 ms |
| コンパイル使用メモリ | 198,580 KB |
| 最終ジャッジ日時 | 2025-01-20 16:17:02 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 WA * 15 |
ソースコード
#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define fi first
#define se second
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll mod_998244353 = 998244353;
constexpr ll INF = 1LL << 60;
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
//using lll=boost::multiprecision::cpp_int;
//using Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<128>>;//仮数部が1024桁
template <class T>
inline bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
ll mypow(ll x, ll n, const ll &p = -1)
{ //x^nをmodで割った余り
if (p != -1)
{
x =(x%p+p)%p;
}
ll ret = 1;
while (n > 0)
{
if (n & 1)
{
if (p != -1)
ret = (ret * x) % p;
else
ret *= x;
}
if (p != -1)
x = (x * x) % p;
else
x *= x;
n >>= 1;
}
return ret;
}
using namespace std;
//using namespace atcoder;
template <class T>
class SegmentTree
{
using F = function<T(T, T)>;
private:
int n;
vector<T> v;
const F f;
const T e;
public:
SegmentTree(int _n, const F f, const T &e) : f(f),e(e)
{
n = 1;
while (n < _n)
n <<= 1;
v = vector<T>(2 * n, e);
}
void set(const int &k, const T &x)
{
v[k + n] = x;
}
void build()
{ //setが終わったら必ず呼ぶこと
for (int i = n - 1; i > 0; --i)
{
v[i] = f(v[2 * i], v[2 * i + 1]);
}
}
void update(int k, const T &x)
{
k += n;
v[k] = x;
while (k > 0)
{
k >>= 1;
v[k] = f(v[2 * k], v[2 * k + 1]);
}
}
T query(int a, int b)
{
T l = e, r = e;
for (a += n, b += n; a < b; a >>= 1, b >>= 1)
{
if (a & 1)
l = f(l, v[a++]);
if (b & 1)
r = f(v[--b], r);
}
return f(l, r);
}
T operator[](const int &k)
{
return v[k + n];
}
template <typename C>
int find_subtree(int a, const C &check, T &M, bool type)
{
while (a < n)
{
T nxt = type ? f(v[2 * a + 1], M) : f(M, v[2 * a]);
if (check(nxt))
a = 2 * a + type;
else
M = nxt, a = 2 * a + 1 - type;
}
return a - n;
}
template <typename C>
int find_first(int a, const C &check)
{
T L = e;
if (a <= 0)
{
if (check(f(L, v[1])))
return find_subtree(1, check, L, false);
return -1;
}
int b = n;
for (a += n, b += n; a < b; a >>= 1, b >>= 1)
{
if (a & 1)
{
T nxt = f(L, v[a]);
if (check(nxt))
return find_subtree(a, check, L, false);
L = nxt;
++a;
}
}
return -1;
}
template <typename C>
int find_last(int b, const C &check)
{
T R = e;
if (b >= n)
{
if (check(f(v[1], R)))
return find_subtree(1, check, R, true);
return -1;
}
int a = n;
for (b += n; a < b; a >>= 1, b >>= 1)
{
if (b & 1)
{
T nxt = f(v[--b], R);
if (check(nxt))
return find_subtree(b, check, R, true);
R = nxt;
}
}
return -1;
}
};
void solve()
{
int n,q;
cin>>n>>q;
auto f=[](pair<int,int> a,pair<int,int> b)->pair<int,int>{
if(a.first<b.first)return a;
else return b;
};
constexpr int inf=1e9;
SegmentTree<pair<int,int>>seg(n,f,make_pair(inf,inf));
rep(i,n){
int a;
cin>>a;
seg.set(i,make_pair(a,i));
}
seg.build();
while(q--){
int query,l,r;
cin>>query>>l>>r;
l--;
if(query==1){
int x=seg[l].first,y=seg[r].second;
seg.update(l,make_pair(y,l));
seg.update(r-1,make_pair(x,r-1));
}else{
cout<<seg.query(l,r).second+1<<"\n";
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
solve();
return 0;
}
tanimani364