結果

問題 No.875 Range Mindex Query
ユーザー yuliicppyyuliicppy
提出日時 2019-09-06 22:16:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 2,893 bytes
コンパイル時間 1,169 ms
コンパイル使用メモリ 98,576 KB
実行使用メモリ 8,524 KB
最終ジャッジ日時 2023-09-07 00:45:25
合計ジャッジ時間 3,301 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,284 KB
testcase_01 AC 3 ms
7,232 KB
testcase_02 AC 4 ms
7,352 KB
testcase_03 AC 4 ms
7,200 KB
testcase_04 AC 4 ms
7,196 KB
testcase_05 AC 4 ms
7,348 KB
testcase_06 AC 5 ms
7,196 KB
testcase_07 AC 4 ms
7,408 KB
testcase_08 AC 3 ms
7,188 KB
testcase_09 AC 4 ms
7,236 KB
testcase_10 AC 4 ms
7,336 KB
testcase_11 AC 119 ms
8,424 KB
testcase_12 AC 102 ms
7,988 KB
testcase_13 AC 80 ms
8,464 KB
testcase_14 AC 80 ms
8,420 KB
testcase_15 AC 112 ms
8,524 KB
testcase_16 AC 173 ms
8,424 KB
testcase_17 AC 185 ms
8,424 KB
testcase_18 AC 184 ms
8,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

VI A(1123456,INF);

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];
  }
};

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q; cin >> N >> Q;
    REP(i,N) cin >> A[i];
    SegmentTree<int> seg(N,[](int a, int b){
        if(A[a] < A[b]) return a;
        else return b;
    },1123455);
    REP(i,N){
        seg.set(i,i);
    }
    seg.build();


    REP(i,Q){
        int a,b,c; cin >> a >> b >> c;
        b--; c--;
        if(a == 1){
            //swap(A[b],A[c]);
            int tmp = A[c];
            A[c] = A[b];
            A[b] = tmp;
            seg.update(b,b);
            seg.update(c,c);
        }else{
            cout << seg.query(b,c+1)+1 << endl;
        }
    }

}
0