結果

問題 No.875 Range Mindex Query
ユーザー first_vil
提出日時 2019-09-11 14:51:13
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 2,878 bytes
コンパイル時間 1,712 ms
コンパイル使用メモリ 174,568 KB
実行使用メモリ 6,656 KB
最終ジャッジ日時 2024-07-02 16:46:38
合計ジャッジ時間 3,348 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
struct p {int num, itr;};
bool operator < (const p& a, const p& b) { return a.num < b.num; }
bool operator > (const p& a, const p& b) { return a.num > b.num; }
bool operator == (const p& a, const p& b) { return a.num == b.num; }
template<class T>
class segtree {
vector<T> dat;
int n = 1;
public:
#define def {INF,-1}
segtree(int _n){
while (n < _n)n *= 2;
dat.resize(2 * n - 1 , def);
}
segtree(vector<T> a) {
int size = a.size();
while (n < size)n *= 2;
dat.resize(2 * n - 1, def);
FOR(i, 0, size)dat[i + n - 1] = a[i];
rFOR(i, 0, n - 1)dat[i] = fun(dat[2 * i + 1], dat[2 * i + 2]);
}
T fun(T x, T y) { return min(x, y); }
void update(int i, T x) {
i += n - 1;
dat[i] = x;
while (i > 0) {
--i /= 2;
dat[i] = fun(dat[i * 2 + 1], dat[i * 2 + 2]);
}
}
T query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)return def;
else if (a <= l && r <= b)return dat[k];
else {
T s = query(a, b, k * 2 + 1, l, (l + r) / 2);
T t = query(a, b, k * 2 + 2, (l + r) / 2, r);
return fun(s, t);
}
}
T query(int a, int b) { return query(a, b, 0, 0, n); }
void datswap(int a, int b) {
a += n - 1, b += n - 1;
swap(dat[a].num, dat[b].num);
while (a > 0) {
--a /= 2;
dat[a] = fun(dat[a * 2 + 1], dat[a * 2 + 2]);
}
while (b > 0) {
--b /= 2;
dat[b] = fun(dat[b * 2 + 1], dat[b * 2 + 2]);
}
}
};
int main() {
init();
int n, q;
cin >> n >> q;
vector<p> in(n);
FOR(i, 0, n) {
cin >> in[i].num;
in[i].itr = i;
}
segtree<p> seg(in);
int num, l, r;
while (q--) {
cin >> num >> l >> r;
if (num == 1)seg.datswap(--l, --r);
else cout << seg.query(--l, r).itr+1 << "\n";
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0