結果
| 問題 |
No.875 Range Mindex Query
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-06 21:27:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 343 ms / 2,000 ms |
| コード長 | 1,932 bytes |
| コンパイル時間 | 1,205 ms |
| コンパイル使用メモリ | 110,112 KB |
| 実行使用メモリ | 13,056 KB |
| 最終ジャッジ日時 | 2024-06-24 16:44:05 |
| 合計ジャッジ時間 | 4,942 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <fstream>
#include <bitset>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const long long MOD = 1000000007LL;
const long long MAX = 500000LL;
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
struct SegmentTree {
private:
ll n;
vector<ll> node;
public:
SegmentTree(vector<ll> v) {
ll sz = v.size();
n = 1; while (sz > n) n *= 2;
node.resize(2 * n - 1, INF);
for (ll i = 0; i < sz; i++) {
node[i + n - 1] = v[i];
}
for (ll i = n - 2; i >= 0; i--) {
node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
}
}
void update(ll x, ll val) {
x += n - 1;
node[x] = val;
while (x > 0) {
x = (x - 1) / 2;
node[x] = min(node[x * 2 + 1], node[x * 2 + 2]);
}
}
ll getmin(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
if (r < 0) r = n;
if (r <= a || b <= l) return INF;
if (a <= l && r <= b) return node[k];
ll vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
ll vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
};
int main()
{
ll N, Q;
cin >> N >> Q;
vector<ll> a(N);
map<ll, ll> mp;
for (ll i = 0; i < N; i++) {
cin >> a[i];
mp[a[i]] = i;
}
SegmentTree seg(a);
for (ll i = 0; i < Q; i++) {
ll x, l, r;
cin >> x >> l >> r;
l--;
r--;
if (x == 1) {
ll a = seg.getmin(l, l + 1);
ll b = seg.getmin(r, r + 1);
ll temp = mp[a];
mp[a] = mp[b];
mp[b] = temp;
seg.update(l, b);
seg.update(r, a);
}
else {
cout << mp[seg.getmin(l, r + 1)] + 1 << '\n';
}
}
return 0;
}