結果
| 問題 | No.875 Range Mindex Query |
| コンテスト | |
| ユーザー |
Ricky_pon
|
| 提出日時 | 2019-10-09 15:03:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 88 ms / 2,000 ms |
| コード長 | 1,782 bytes |
| 記録 | |
| コンパイル時間 | 2,343 ms |
| コンパイル使用メモリ | 200,816 KB |
| 最終ジャッジ日時 | 2025-01-07 21:22:49 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:50:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
50 | scanf("%d%d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:56:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
56 | scanf("%d", &a);
| ~~~~~^~~~~~~~~~
main.cpp:62:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
62 | scanf("%d%d%d", &c, &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pil;
typedef complex<double> xy_t;
const lint mod = 1e9 + 7;
template<class T> struct SegTree{
typedef function<T(T, T)> F;
int n = 1;
vector<T> node;
T et;
F f, g;
SegTree(int n_, T et_, F f_, F g_):
et(et_), f(f_), g(g_){
while(n < n_) n *= 2;
node.resize(n*2-1, et);
}
void update(int i, T x){
i += n-1;
node[i] = g(node[i], x);
while(i){
i = (i-1) / 2;
node[i] = f(node[i*2+1], node[i*2+2]);
}
}
T query(int a, int b){
T vl = et, vr = et;
for(a+=n-1, b+=n-1; a<b; a=(a-1)/2, b=(b-1)/2){
if(!(a&1)) vl = f(vl, node[a++]);
if(!(b&1)) vr = f(node[--b], vr);
}
return f(vl, vr);
}
};
int main(){
int n, q;
scanf("%d%d", &n, &q);
auto f = [](const pii &p, const pii &q){if(p < q){return p;} return q;};
auto g = [](const pii &p, const pii &q){return q;};
SegTree<pii> st(n, pii(100010, -1), f, g);
rep(i, n){
int a;
scanf("%d", &a);
st.update(i, pii(a, i));
}
while(q--){
int c, l, r;
scanf("%d%d%d", &c, &l, &r);
--l; --r;
if(c == 1) {
int vl = st.node[l+st.n-1].fi;
int vr = st.node[r+st.n-1].fi;
st.update(l, pii(vr, l));
st.update(r, pii(vl, r));
}
else printf("%d\n", st.query(l, r+1).se+1);
}
}
Ricky_pon