結果
問題 | No.875 Range Mindex Query |
ユーザー |
|
提出日時 | 2021-02-10 00:55:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,828 bytes |
コンパイル時間 | 708 ms |
コンパイル使用メモリ | 95,732 KB |
実行使用メモリ | 7,972 KB |
最終ジャッジ日時 | 2024-07-07 06:10:54 |
合計ジャッジ時間 | 3,823 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | WA * 18 |
ソースコード
#include<iostream>#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cmath>#include <vector>#include <set>#include <map>#include <unordered_set>#include <unordered_map>#include <queue>#include <string>#include <cstring>using namespace std;typedef long long ll;const ll siz = 2e5 + 7;pair<int, int> t[4 * siz];int n, q;pair<int, int> combine(pair<int, int>a, pair<int, int>b) {if (a.first > b.first)return b;return a;}void build(int a[], int v, int tl, int tr) {if (tl == tr) {t[v] = {a[tl], tl};} else {int tm = (tl + tr) / 2;build(a, v * 2, tl, tm);build(a, v * 2 + 1, tm + 1, tr);t[v] = combine(t[v * 2], t[v * 2 + 1]);}}pair<int, int> query(int v, int tl, int tr , int l , int r) {if (l > r)return {0, 0};if (l == tl && r == tr) {return t[v];}int tm = (tr + tl) / 2;return combine(query(2 * v, tl, tm, l, min(r, tm)) , query(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));}void update(int v, int tl, int tr, int pos, int new_val) {if (tl == tr) {t[v] = {new_val, pos};} else {int tm = (tl + tr) / 2;if (pos <= tm)update(v * 2, tl, tm, pos, new_val);elseupdate(v * 2 + 1, tm + 1, tr, pos, new_val);t[v] = combine(t[v * 2] , t[v * 2 + 1]);}}int main() {ios_base::sync_with_stdio(false);cin.tie(NULL);cin >> n >> q;int a[n];for (int i = 0; i < n; i++) {cin >> a[i];}pair<int, int>y = combine({1, 0}, {0, 3});build(a, 1, 0, n - 1 );for (int i = 0; i < q; i++) {int type;cin >> type;int l, r;cin >> l >> r;--l, --r;if (type == 1) {int Prev_l = a[l];int Prev_r = a[r];swap(a[l], a[r]);update(1, 0, n - 1, l, Prev_r);update(1, 0, n - 1, r, Prev_l);} else {pair<int, int>x = query(1, 0, n - 1 , l , r);cout << x.second + 1 << endl;}}}