結果
| 問題 | No.875 Range Mindex Query |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-07 14:13:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 199 ms / 2,000 ms |
| コード長 | 3,181 bytes |
| コンパイル時間 | 1,744 ms |
| コンパイル使用メモリ | 174,792 KB |
| 実行使用メモリ | 8,088 KB |
| 最終ジャッジ日時 | 2024-06-26 09:59:28 |
| 合計ジャッジ時間 | 4,048 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
struct valueIdx{
ll value, idx;
};
template<class Monoid> struct SegTree {
using Func = function<Monoid(Monoid, Monoid)>;
const Func F;
const Monoid UNITY;
int SIZE_R;
vector<Monoid> dat;
SegTree(int n, const Func f, const Monoid &unity): F(f), UNITY(unity) { init(n); }
void init(int n) {
SIZE_R = 1;
while (SIZE_R < n) SIZE_R *= 2;
dat.assign(SIZE_R * 2, UNITY);
}
/* set, a is 0-indexed */
void set(int a, const Monoid &v) { dat[a + SIZE_R] = v; }
void build() {
for (int k = SIZE_R - 1; k > 0; --k)
dat[k] = F(dat[k*2], dat[k*2+1]);
}
/* update a, a is 0-indexed */
void update(int a, const Monoid &v) {
int k = a + SIZE_R;
dat[k] = v;
while (k >>= 1) dat[k] = F(dat[k*2], dat[k*2+1]);
}
/* get [a, b), a and b are 0-indexed */
Monoid get(int a, int b) {
Monoid vleft = UNITY, vright = UNITY;
for (int left = a + SIZE_R, right = b + SIZE_R; left < right; left >>= 1, right >>= 1) {
if (left & 1) vleft = F(vleft, dat[left++]);
if (right & 1) vright = F(dat[--right], vright);
}
return F(vleft, vright);
}
inline Monoid operator [] (int a) { return dat[a + SIZE_R]; }
/* debug */
void print() {
for (int i = 0; i < SIZE_R; ++i) {
cout << (*this)[i];
if (i != SIZE_R-1) cout << ",";
}
cout << endl;
}
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N, Q;
cin >> N >> Q;
//使うとき
// セグツリーの構築
SegTree<valueIdx> st(N, [](valueIdx a, valueIdx b){
return (a.value < b.value ? a : b);},
valueIdx{INF,0});
vector<long long> A(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
st.set(i, {A[i],i});
}
st.build();
REP(i,Q){
int q, l, r;
cin >> q >> l >> r;
--l, --r;
if(q==1){
auto L = st.get(l, l + 1).value;
auto R = st.get(r, r + 1).value;
st.update(l, {R,l});
st.update(r, {L,r});
}
else cout << st.get(l, r + 1).idx + 1 << endl;
}
}