結果

問題 No.875 Range Mindex Query
ユーザー misora192misora192
提出日時 2020-05-15 08:30:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,651 bytes
コンパイル時間 4,067 ms
コンパイル使用メモリ 174,592 KB
実行使用メモリ 5,580 KB
最終ジャッジ日時 2023-10-17 14:44:22
合計ジャッジ時間 5,197 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 78 ms
5,580 KB
testcase_12 AC 61 ms
4,524 KB
testcase_13 AC 58 ms
5,580 KB
testcase_14 AC 56 ms
5,580 KB
testcase_15 AC 75 ms
5,580 KB
testcase_16 AC 74 ms
5,580 KB
testcase_17 AC 81 ms
5,580 KB
testcase_18 AC 77 ms
5,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }
};


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, q;
	cin >> n >> q;

	vector<int> a(n);
	rep(i, n) cin >> a[i];

	int INF = INT_MAX / 2;
	SegmentTree<pii> seg(n, [](pii a, pii b){
    if(a.first < b.first) return a;
    return b;
  }, make_pair(INF, n));

	rep(i, n) seg.update(i, {a[i], i});
	while(q--){
		int t, l, r;
		cin >> t >> l >> r;
		l--;
		r--;

		if(t == 1){
			pii x = seg.query(l, l + 1);
			pii y = seg.query(r, r + 1);
			seg.update(l, {y.first, l});
			seg.update(r, {x.first, r});
		}else{
			cout << seg.query(l, r + 1).second + 1 << "\n";
		}
	}
}
0