結果
| 問題 | No.875 Range Mindex Query |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-28 01:15:47 |
| 言語 | C++17(clang) (17.0.6 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 108 ms / 2,000 ms |
| コード長 | 2,920 bytes |
| 記録 | |
| コンパイル時間 | 1,121 ms |
| コンパイル使用メモリ | 145,800 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2024-11-30 14:59:49 |
| 合計ジャッジ時間 | 2,790 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <tuple>
#include <queue>
#include <vector>
#include <cmath>
#include <random>
#include <math.h>
#include <random>
#include <functional>
#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define rREP(i, n) for(int (i) = (n) - 1; (i) >= 0; --(i))
#define ALL(TheArray) TheArray.begin(), TheArray.end()
using lli = long long int;
using pii = std::pair<int, int>;
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<typename T>
class SegTree{
#define rep(i, n) for(int (i) = 0; (i) < (n); ++(i))
const int N;
const int n;
const std::function<T(T, T)> F;
const T identityValue;
std::vector<T> theTree;
int computeLength(int m){
int res = 1; while(res < m) res <<= 1;
return res;
}
T preGetValue(int a, int b, int k, int l, int r){
if(r <= a or b <= l) return identityValue;
if(a <= l and r <= b) return theTree[k];
T vl = preGetValue(a, b, 2*k+1, l, (l+r)/2);
T vr = preGetValue(a, b, 2*k+2, (l+r)/2, r);
return F(vl, vr);
}
public:
SegTree(std::vector<T>& V, std::function<T(T, T)> f1, T idV) :n(V.size()), N(computeLength(V.size())), F(f1), identityValue(idV)
{
theTree.resize(2 * N - 1);
int i;
for(i = 0; i < n; ++i) theTree[i + N - 1] = V[i];
for(i = n; i < N; ++i) theTree[i + N - 1] = identityValue;
for(i = N - 2;i >= 0; --i) theTree[i] = F(theTree[2*i+1], theTree[2*i+2]);
}
bool update(int x, T val){
if(x < 0 or x >= n) return false;
int y = x + N - 1;
theTree[y] = val;
while(y > 0){
(--y) >>= 1;
theTree[y] = F(theTree[2*y+1], theTree[2*y+2]);
}
return true;
}
T at(int idx){return theTree[idx + N - 1];}
T getValue(int a, int b){
return preGetValue(a, b, 0, 0, N);
}
#undef rep
};
constexpr int inf = 2e9;
constexpr pii infP = {inf, inf};
const std::function<pii(pii, pii)> minfunc = [](pii x, pii y){return x > y ? y : x;};
std::vector<pii> A;
int main(void){
int n, Q; scanf("%d%d", &n, &Q);
A.resize(n); REP(i, n) {scanf("%d", &A[i].first); A[i].second = i;}
SegTree<pii> ST(A, minfunc, infP);
while(Q--){
int q, l, r; scanf("%d%d%d", &q, &l, &r); l--; r--;
if(q == 1){
pii vL = ST.at(l);
pii vR = ST.at(r);
ST.update(l, {vR.first, l});
ST.update(r, {vL.first, r});
}
else{
printf("%d\n", ST.getValue(l, r+1).second + 1);
}
}
return 0;
}