結果
| 問題 |
No.875 Range Mindex Query
|
| コンテスト | |
| ユーザー |
koi_kotya
|
| 提出日時 | 2019-09-06 21:36:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 293 ms / 2,000 ms |
| コード長 | 1,837 bytes |
| コンパイル時間 | 2,201 ms |
| コンパイル使用メモリ | 176,080 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-24 17:04:20 |
| 合計ジャッジ時間 | 4,765 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)
int const INF = INT_MAX;
struct SegmentTree {
private:
int n;
vector<P> node;
public:
SegmentTree(vector<P> v) {
int sz = v.size();
n = 1;
while (n < sz) n *= 2;
node.resize(2*n-1,P(INF,-1));
for (int i = 0;i < sz;++i) node[i+n-1] = v[i];
for (int i = n-2;i >= 0;--i) node[i] = min(node[2*i+1],node[2*i+2]);
}
void update(int x,P val) {
x += (n-1);
node[x] = val;
while (x > 0) {
x = (x-1)/2;
node[x] = min(node[2*x+1],node[2*x+2]);
}
}
P getmin(int a,int b,int k = 0,int l = 0,int r = -1) {
if (r < 0) r = n;
if (r <= a || b <= l) return P(INF,-1);
if (a <= l && r <= b) return node[k];
P vl = getmin(a,b,2*k+1,l,(l+r)/2);
P vr = getmin(a,b,2*k+2,(l+r)/2,r);
return min(vl,vr);
}
};
int main() {
int n,q;
cin >> n >> q;
vector<P> a(n);
for (int i = 0;i < n;++i) {
cin >> a[i].first;
a[i].second = i;
}
SegmentTree seg(a);
for (int z = 0;z < q;++z) {
int c,l,r;
cin >> c >> l >> r;
if (c == 1) {
P u = seg.getmin(l-1,l),v = seg.getmin(r-1,r);
u.second = r-1;
v.second = l-1;
seg.update(l-1,v);
seg.update(r-1,u);
} else cout << seg.getmin(l-1,r).second+1 << endl;
}
}
koi_kotya