結果
問題 | No.875 Range Mindex Query |
ユーザー |
![]() |
提出日時 | 2023-05-05 20:37:12 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 68 ms / 2,000 ms |
コード長 | 2,917 bytes |
コンパイル時間 | 3,408 ms |
コンパイル使用メモリ | 249,436 KB |
実行使用メモリ | 6,272 KB |
最終ジャッジ日時 | 2024-11-23 05:10:43 |
合計ジャッジ時間 | 6,546 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 18 |
ソースコード
#line 2 "library/src/template.hpp"#include<bits/stdc++.h>#define rep(i, N) for (int i = 0; i < (N); i++)#define all(x) (x).begin(),(x).end()#define popcount(x) __builtin_popcount(x)using i128=__int128_t;using ll = long long;using ld = long double;using graph = std::vector<std::vector<int>>;using P = std::pair<int, int>;constexpr int inf = 1e9;constexpr ll infl = 1e18;constexpr ld eps = 1e-6;const long double pi = acos(-1);constexpr uint64_t MOD = 1e9 + 7;constexpr uint64_t MOD2 = 998244353;constexpr int dx[] = { 1,0,-1,0 };constexpr int dy[] = { 0,1,0,-1 };template<class T>constexpr inline void chmax(T&x,T y){if(x<y)x=y;}template<class T>constexpr inline void chmin(T&x,T y){if(x>y)x=y;}#line 3 "library/src/data-structure/segtree.hpp"namespace kyopro {/// @brief Segment Treetemplate <class S, S (*op)(S, S), S (*e)()>class segtree {int lg, sz, n;std::vector<S> dat;public:segtree() {}segtree(int n) : segtree(std::vector<S>(n, e())) {}segtree(const std::vector<S>& vec) : n((int)vec.size()) {sz = 1, lg = 0;while (sz <= n) {sz <<= 1;lg++;}dat = std::vector<S>(sz << 1, e());for (int i = 0; i < n; i++) {set(i, vec[i]);}build();}void set(int p, const S& v) { dat[sz + p] = v; }void build() {for (int i = sz - 1; i > 0; i--) {dat[i] = op(dat[(i << 1) | 0], dat[(i << 1) | 1]);}}S operator[](int p) const { return dat[sz + p]; }void update(int p, const S& v) {p += sz;dat[p] = v;while (p >>= 1) {dat[p] = op(dat[(p << 1) | 0], dat[(p << 1) | 1]);}}S prod(int l, int r) const {if (l == 0 && r == n) {return dat[1];}l += sz, r += sz;S sml = e(), smr = e();while (l != r) {if (l & 1) sml = op(sml, dat[l++]);if (r & 1) smr = op(dat[--r], smr);l >>= 1, r >>= 1;}return op(sml, smr);}void apply(int p, const S& v) { update(p, op(dat[sz + p], v)); }};}; // namespace kyopro/// @docs docs/data-structure/segtree.md#line 3 "main.cpp"using namespace std;constexpr inline P op(P a, P b) { return min(a, b); }constexpr inline P e() { return {inf, inf}; }int main() {int n,q;scanf("%d%d", &n, &q);kyopro::segtree<P, op, e> seg(n + 1);for (int i = 1; i <= n; ++i) {int a;scanf("%d",&a);seg.set(i, {a, i});}seg.build();while(q--){int t,l,r;scanf("%d%d%d", &t, &l, &r);if (t == 1) {auto [a, b] = P{seg[l].first, seg[r].first};swap(a, b);seg.update(l, {a, l}), seg.update(r, {b, r});}else{printf("%d\n", seg.prod(l, r + 1).second);}}}