結果
| 問題 | No.875 Range Mindex Query |
| コンテスト | |
| ユーザー |
Plan8
|
| 提出日時 | 2020-01-18 16:54:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 297 ms / 2,000 ms |
| コード長 | 3,583 bytes |
| 記録 | |
| コンパイル時間 | 1,749 ms |
| コンパイル使用メモリ | 177,964 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-27 19:41:20 |
| 合計ジャッジ時間 | 5,570 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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>
struct SegmentTree {
private:
using Func = function<T(T, T)>;
int n;
vector<T> node;
T init_v;
Func func;
public:
SegmentTree(vector<T> a, Func _func, T _init_v) {
int sz = a.size();
n = 1;
init_v = _init_v;
func = _func;
while (n < sz) n <<= 1;
node.resize(2 * n - 1, init_v);
for (int i = 0; i < sz; i++) node[i + n - 1] = a[i];
for (int i = n - 2; i >= 0; i--) node[i] = func(node[i * 2 + 1], node[i * 2 + 2]);
}
void update(int pos, T v) {
int k = pos + n - 1;
node[k].first = v.first;
while (k > 0) {
k = (k - 1) / 2;
node[k] = func(node[k * 2 + 1], node[k * 2 + 2]);
}
}
T get(int pos) {
int k = pos + n - 1;
return node[k];
}
T query(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0) r = n;
if (r <= a || b <= l) return init_v;
if (a <= l && r <= b) return node[k];
T lv = query(a, b, k * 2 + 1, l, (l + r) / 2);
T rv = query(a, b, k * 2 + 2, (l + r) / 2, r);
return func(lv, rv);
}
int size(){
return n;
}
};
P _calc(P a, P b){
return a.first > b.first ? b : a;
}
int main(void){
int n, q; cin >> n >> q;
vector<P> a(n); REP(i,n){cin >> a[i].first; a[i].second = i+1;}
SegmentTree<P> st(a, _calc, P(n+1, n+1));
REP(i,q){
int c, l, r; cin >> c >> l >> r;
l--; r--;
if(c == 2) cout << st.query(l, r+1, 0, 0, st.size()).second << endl;
else{
P al = st.get(l), ar = st.get(r);
st.update(l, ar); st.update(r, al);
}
}
return 0;
}
Plan8