結果
| 問題 |
No.875 Range Mindex Query
|
| コンテスト | |
| ユーザー |
utsumi_pg
|
| 提出日時 | 2019-09-06 23:36:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,338 bytes |
| コンパイル時間 | 395 ms |
| コンパイル使用メモリ | 36,836 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-24 21:27:51 |
| 合計ジャッジ時間 | 1,913 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | WA * 18 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:41:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
41 | scanf("%d %d", &N, &Q);
| ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:45:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
45 | scanf("%d", &a);
| ~~~~~^~~~~~~~~~
main.cpp:50:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
50 | scanf("%d", &op);
| ~~~~~^~~~~~~~~~~
main.cpp:53:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
53 | scanf("%d %d", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:60:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
60 | scanf("%d %d", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
static const int MAX_N = 100000;
static const int INF = 1 <<30;
int N,Q;
int A[MAX_N];
int n_;
P dat[4 * MAX_N];
void init(){
n_ = 1;
while(n_ < N) n_ *= 2;
for(int i = 0; i < 2 * n_ - 1; i++){
dat[i] = P(INF, -1);
}
}
void update(int i, int x){
dat[i + n_ - 1] = P(x, i);
int k = i + n_ - 1;
while(k > 0){
k = (k - 1) / 2;
//if(dat[k].first <= x) break;
dat[k] = P(x, i);
}
}
P find(int a, int b, int k, int l, int r){
if(r <= a || b <= l) return P(INF, -1);
if(a <= l && r <= b) return P(dat[k].first, dat[k].second);
P vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
P vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
if(vl.first < vr.first) return P(vl.first, vl.second);
else return P(vr.first, vr.second);
}
int main(){
scanf("%d %d", &N, &Q);
init();
for(int i = 0; i < N; i++){
int a;
scanf("%d", &a);
update(i, a);
}
for(int i = 0; i < Q; i++){
int op;
scanf("%d", &op);
if(op == 1){
int l, r;
scanf("%d %d", &l, &r);
l--; r--;
int bf = find(l, l + 1, 0, 0, n_).first;
update(l, find(r, r + 1, 0, 0, n_).first);
update(r, bf);
}else{
int l, r;
scanf("%d %d", &l, &r);
l--; r--;
printf("%d\n", find(l, r + 1, 0 , 0 , n_).second + 1);
}
}
return 0;
}
utsumi_pg