結果
| 問題 | No.875 Range Mindex Query |
| コンテスト | |
| ユーザー |
kyuna
|
| 提出日時 | 2019-10-06 04:35:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,843 bytes |
| 記録 | |
| コンパイル時間 | 744 ms |
| コンパイル使用メモリ | 68,328 KB |
| 最終ジャッジ日時 | 2024-11-14 21:44:27 |
| 合計ジャッジ時間 | 1,650 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:43:17: error: 'numeric_limits' was not declared in this scope
43 | const int INF = numeric_limits<int>::max();
| ^~~~~~~~~~~~~~
main.cpp:43:32: error: expected primary-expression before 'int'
43 | const int INF = numeric_limits<int>::max();
| ^~~
ソースコード
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
using namespace std;
template<typename Monoid>
struct SegmentTree {
using F = function<Monoid(Monoid, Monoid)>;
const F f;
const Monoid M1;
int sz;
vector<Monoid> dat;
SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1), sz(1) {
while (sz < n) sz <<= 1;
dat.assign(sz * 2, M1);
}
void set(int k, const Monoid &x) { dat[k + sz] = x; }
void build() {
for (int k = sz - 1; k > 0; k--) {
dat[k] = f(dat[2 * k], dat[2 * k + 1]);
}
}
void update(int k, const Monoid &x) {
dat[k += sz] = x;
while (k >>= 1) dat[k] = f(dat[2 * k], dat[2 * k + 1]);
}
Monoid get(int a, int b) { // [a, b)
Monoid L = M1, R = M1;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1) L = f(L, dat[a++]);
if (b & 1) R = f(dat[--b], R);
}
return f(L, R);
}
Monoid operator[](const int &k) const { return dat[k + sz]; }
friend ostream& operator<<(ostream& os, SegmentTree<Monoid> &seg) {
for (int i = 0; i < seg.sz; i++) os << seg[i] << " ";
return os;
}
};
const int INF = numeric_limits<int>::max();
int main() {
int n, q; cin >> n >> q;
using P = pair<int, int>;
SegmentTree<P> seg(n + 1, [](P a, P b) { return min(a, b); }, {INF, 0});
for (int i = 1; i <= n; i++) {
int a; cin >> a; seg.set(i, P(a, i));
}
seg.build();
while (q--) {
int com, l, r; cin >> com >> l >> r;
if (com == 1) {
int al = seg[l].first, ar = seg[r].first;
seg.update(l, P(ar, l));
seg.update(r, P(al, r));
} else {
cout << seg.get(l, r + 1).second << endl;
}
}
return 0;
}
kyuna