結果
| 問題 |
No.875 Range Mindex Query
|
| コンテスト | |
| ユーザー |
onigawara_kypr
|
| 提出日時 | 2019-09-06 21:53:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,914 bytes |
| コンパイル時間 | 1,081 ms |
| コンパイル使用メモリ | 109,584 KB |
| 実行使用メモリ | 10,368 KB |
| 最終ジャッジ日時 | 2024-06-24 17:39:01 |
| 合計ジャッジ時間 | 3,567 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | WA * 10 RE * 8 |
ソースコード
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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;}
const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;
template < typename T >
struct SegmentTree {
vector<T> data;
long long n;
SegmentTree(vector<T> vec) {
long long sz = vec.size();
n=1;
while(n<sz) n<<=1;
data.resize(2*n-1, make_pair(0, HIGHINF));
for (long long i=0; i<sz; i++) data[i+n-1] = vec[i];
for (long long i=n-2; i>=0; i--) {
if (data[2*i+1].second > data[2*i+2].second) data[i] = data[2*i+2];
else data[i] = data[2*i+1];
}
}
void update(ll val1, ll val2) {
val1 += (n-1);
val2 += (n-1);
ll tmp = data[val1].second;
data[val1].second = data[val2].second;
data[val2].second = tmp;
while(val1 > 0) {
val1 = (val1-1) / 2;
if (data[2*val1+1].second > data[2*val1+2].second) data[val1] = data[2*val1*2];
else data[val1] = data[2*val1*1];
}
while(val2 > 0) {
val2 = (val2-1) / 2;
if (data[2*val2+1].second > data[2*val2+2].second) data[val2] = data[2*val2*2];
else data[val2] = data[2*val2*1];
}
}
T query(long long a, long long b, long long k=0, long long l=0, long long r=-1) {
if (r<0) r=n;
if (b<=l || r<=a) return make_pair(0, HIGHINF);
if(a <= l && r <= b) return data[k];
P<ll, ll> vl = query(a, b, 2*k+1, l, (l+r)/2);
P<ll, ll> vr = query(a, b, 2*k+2, (l+r)/2, r);
if (vl.second < vr.second) return vl;
else return vr;
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, q; cin >> n >> q;
V<P<ll, ll> > a(n);
REP(i, n) {
ll tmpa; cin >> tmpa;
a[i] = make_pair(i, tmpa);
}
SegmentTree<P<ll, ll> > seg = SegmentTree<P<ll, ll> >(a);
REP(_, q) {
ll qi, l, r; cin >> qi >> l >> r;
if (qi == 1) {
seg.update(l-1, r-1);
} else {
P<ll, ll> ans = seg.query(l-1, r);
cout << ans.first+1 << '\n';
}
}
return 0;
}
onigawara_kypr