結果

問題 No.875 Range Mindex Query
ユーザー ゆにぽけゆにぽけ
提出日時 2023-10-14 18:29:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 2,332 bytes
コンパイル時間 2,366 ms
コンパイル使用メモリ 128,656 KB
実行使用メモリ 5,192 KB
最終ジャッジ日時 2023-10-14 18:29:43
合計ジャッジ時間 3,387 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 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 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 74 ms
5,192 KB
testcase_12 AC 60 ms
4,352 KB
testcase_13 AC 56 ms
5,160 KB
testcase_14 AC 83 ms
5,156 KB
testcase_15 AC 72 ms
5,140 KB
testcase_16 AC 67 ms
5,088 KB
testcase_17 AC 73 ms
5,152 KB
testcase_18 AC 70 ms
5,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cassert>
#include<cmath>
#include<ctime>
#include<iomanip>
#include<numeric>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<random>
using namespace std;
template<class T,T (*op)(T,T),T (*e)()> struct SegmentTree
{
    private:
    int siz;
    vector<T> node;

    public:
    SegmentTree(int n) noexcept
    {
        siz = 1;
        while(siz < n) siz <<= 1;

        node.assign(2*siz-1,e());
    }

    void replace(int pos,T x) noexcept {func_update(pos,x,[](T u,T v){return u = v;});}

    void add(int pos,T x) noexcept {func_update(pos,x,[](T u,T v){return u+v;});}

    void func_update(int pos,T x) noexcept {func_update(pos,x,op);}

    void func_update(int pos,T x,T (*func)(T,T)) noexcept
    {
        assert(0 <= pos && pos < siz);
        pos += siz - 1;

        node[pos] = func(node[pos],x);

        while(pos)
        {
            pos = (pos-1)/2;
            node[pos] = op(node[2*pos+1],node[2*pos+2]);
        }
    }

    T operator [](int pos) noexcept
    {
        assert(0 <= pos && pos < siz);
        return node[pos+siz-1];
    }

    T prod(int l,int r) noexcept
    {
        assert(0 <= l && l <= r && r <= siz);

        l += siz-1;
        r += siz-1;

        T Lval = e();
        T Rval = e();

        while(l < r)
        {
            if(!(l & 1)) Lval = op(Lval,node[l++]);
            if(!(r & 1)) Rval = op(node[--r],Rval);

            l >>= 1;
            r >>= 1;
        }

        return op(Lval,Rval);
    }

    T prod() noexcept {return node[0];}
};
pair<int,int> op(pair<int,int> a,pair<int,int> b) {return min(a,b);}
pair<int,int> e() {return make_pair((int)1e9,0);}
int N,Q;
void solve()
{
	cin >> N >> Q;
	SegmentTree<pair<int,int>,op,e> seg(N);
	for(int i = 0;i < N;i++)
	{
		int A;
		cin >> A;
		seg.replace(i,make_pair(A,i));
	}

	for(;Q--;)
	{
		int t,l,r;
		cin >> t >> l >> r;
		if(t == 1)
		{
			l--; r--;
			int a = seg[l].first;
			int b = seg[r].first;
			seg.replace(l,make_pair(b,l));
			seg.replace(r,make_pair(a,r));
		}
		else cout << seg.prod(--l,r).second+1 << "\n";
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	//cin >> tt;
	while(tt--) solve();
}
0