結果
問題 | No.875 Range Mindex Query |
ユーザー | suika_p |
提出日時 | 2019-09-06 22:37:27 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,763 bytes |
コンパイル時間 | 1,800 ms |
コンパイル使用メモリ | 176,116 KB |
実行使用メモリ | 6,784 KB |
最終ジャッジ日時 | 2024-06-24 20:06:48 |
合計ジャッジ時間 | 4,583 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i, m, n) for (int i = (m); i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define reps(i, n) for (int i = 0; i <= (int)(n); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb push_back typedef long long ll; const ll INF = 1LL << 60; const ll mod = 1e9 + 7; class UnionFind { public: vector<ll> par; vector<ll> siz; UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } ll root(ll x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; ll modpow(ll a, ll p) { if (p == 0) return 1; if (!(p % 2)) { ll halfP = p / 2; ll half = modpow(a, halfP); return half * half % mod; } else { return a * modpow(a, p - 1) % mod; } } ll comb(int a, int b) { if (b > a - b) return comb(a, a - b); ll ansMul = 1; ll ansDiv = 1; for (int i = 0; i < b; i++) { ansMul *= a - i; ansDiv *= i + 1; ansMul %= mod; ansDiv %= mod; } ll ans = ansMul * modpow(ansDiv, mod - 2) % mod; return ans; } /* int num = 200010; vector<ll> fact(num), ifact(num); fact[0] = 1; fact[1] = 1; for (int i = 2; i < num; i++) { fact[i] = fact[i-1] * i; fact[i] %= mod; } for (int i = 0; i < num; i++) { ifact[i] = modpow(ifact[i], mod-2); ifact[i] %= mod; } */ int const inf = INT_MAX; struct SegmentTree { private: int n; vector<pair<int, int>> node; public: SegmentTree(vector<pair<int, int>> v) { int sz = v.size(); n = 1; // 2の累乗の大きさにする while (n < sz) n *= 2; // 余りをinfで埋める //node.resize(2*n-1, inf); node.resize(2*n-1); rep(i, 2*n-1) { node[i].first = inf; node[i].second = -1; } // 葉を構築 for (int i = 0; i < sz; i++) { node[i+n-1].first = v[i].first; node[i+n-1].second = v[i].second; } // 親を構築 for (int i = n - 2; i >= 0; i--) { if (node[2*i+1].first < node[2*i+2].first) { node[i].first = node[2*i+1].first; node[i].second = node[2*i+1].second; } else { node[i].first = node[2*i+2].first; node[i].second = node[2*i+2].second; } //node[i].first = min(node[2*i+1].first, node[2*i+2].first); } } void update(int x, int val, int ind) { x += (n - 1); node[x].first = val; node[x].second = ind; while (x > 0) { x = (x - 1) / 2; if (node[2*x+1].first < node[2*x+2].first) { node[x].first = node[2*x+1].first; node[x].second = node[2*x+1].second; } else { node[x].first = node[2*x+2].first; node[x].second = node[2*x+2].second; } //node[x].first = min(node[2*x+1].first, node[2*x+2].first); } } pair<int, int> getmin(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) { pair<int, int> c = make_pair(inf, -1); return c; } if (a <= l && r <= b) return node[k]; pair<int, int> vl = getmin(a, b, 2*k+1, l, (l+r) / 2); pair<int, int> vr = getmin(a, b, 2*k+2, (l+r) / 2, r); if (vl.first > vr.first) { return vr; } else { return vl; } } }; int main() { int N, Q; cin >> N >> Q; vector<pair<int, int>> a(N); rep(i, N) { int x; cin >> x; a[i] = make_pair(x, i+1); } SegmentTree seg(a); rep(_, Q) { int k, l, r; cin >> k >> l >> r; if (k == 1) { seg.update(l, a[r].first, r); seg.update(r, a[l].first, l); } else { pair<int, int> z = seg.getmin(l, r+1); cout << z.second << endl; } } return 0; }