結果

問題 No.875 Range Mindex Query
ユーザー TAISA_TAISA_
提出日時 2019-09-06 21:59:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 208 ms / 2,000 ms
コード長 3,029 bytes
コンパイル時間 1,590 ms
コンパイル使用メモリ 172,192 KB
実行使用メモリ 4,448 KB
最終ジャッジ日時 2023-09-06 23:51:20
合計ジャッジ時間 3,941 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 126 ms
4,380 KB
testcase_12 AC 106 ms
4,376 KB
testcase_13 AC 87 ms
4,380 KB
testcase_14 AC 87 ms
4,380 KB
testcase_15 AC 121 ms
4,380 KB
testcase_16 AC 189 ms
4,380 KB
testcase_17 AC 208 ms
4,384 KB
testcase_18 AC 202 ms
4,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
struct Segtree {
    int n;
    vector<int> dat;
    Segtree(int n_) {
        n = 1;
        while (n < n_) {
            n <<= 1;
        }
        dat.resize(2 * n, INF);
    }
    void upd(int k, int x) {
        k += n;
        dat[k] = x;
        k >>= 1;
        while (k > 0) {
            dat[k] = min(dat[k << 1], dat[k << 1 | 1]);
            k >>= 1;
        }
    }
    int get(int a, int b, int k, int l, int r) {
        if (b <= l || r <= a) {
            return INF;
        }
        if (a <= l && r <= b) {
            return dat[k];
        }
        return min(get(a, b, 2 * k, l, (l + r) / 2),
                   get(a, b, 2 * k + 1, (l + r) / 2, r));
    }
    int get(int a, int b) {
        if (a >= b) {
            return INF;
        }
        return get(a, b, 1, 0, n);
    }
    int find(int a, int b, int x, int k, int l, int r) {
        if (dat[k] > x || r <= a || b <= l) {
            return (-1);
        }
        if (k >= n) {
            return (k - n);
        }
        int rv = find(a, b, x, 2 * k + 1, (l + r) / 2, r);
        if (rv != -1) {
            return (rv);
        }
        return (find(a, b, x, 2 * k, l, (l + r) / 2));
    }
    int find(int a, int b, int x) { return find(a, b, x, 1, 0, n); }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    Segtree seg(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        seg.upd(i, a[i]);
    }
    while (q--) {
        int t, l, r;
        cin >> t >> l >> r;
        --l;
        if (t == 1) {
            --r;
            seg.upd(l, a[r]);
            seg.upd(r, a[l]);
            swap(a[l], a[r]);
        } else {
            int mi = seg.get(l, r);
            cout << seg.find(l, r, mi) + 1 << endl;
        }
    }
}
0