結果
| 問題 |
No.875 Range Mindex Query
|
| コンテスト | |
| ユーザー |
mtsd
|
| 提出日時 | 2019-09-06 21:28:06 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,257 bytes |
| コンパイル時間 | 630 ms |
| コンパイル使用メモリ | 80,116 KB |
| 最終ジャッジ日時 | 2024-06-24 16:45:47 |
| 合計ジャッジ時間 | 1,233 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In constructor ‘segtree<T>::segtree(std::vector<_Tp>&)’:
main.cpp:37:36: error: ‘numeric_limits’ was not declared in this scope
37 | node.resize(2*n, make_pair(numeric_limits<T>::max(), -1));
| ^~~~~~~~~~~~~~
main.cpp:37:52: error: expected primary-expression before ‘>’ token
37 | node.resize(2*n, make_pair(numeric_limits<T>::max(), -1));
| ^
main.cpp:37:58: error: no matching function for call to ‘max()’
37 | node.resize(2*n, make_pair(numeric_limits<T>::max(), -1));
| ~~~~~^~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
from /usr/include/c++/11/ios:40,
from /usr/include/c++/11/ostream:38,
from /usr/include/c++/11/iostream:39,
from main.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: candidate: ‘template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)’
254 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: template argument deduction/substitution failed:
main.cpp:37:58: note: candidate expects 2 arguments, 0 provided
37 | node.resize(2*n, make_pair(numeric_limits<T>::max(), -1));
| ~~~~~^~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
from /usr/include/c++/11/ios:40,
from /usr/include/c++/11/ostream:38,
from /usr/include/c++/11/iostream:39,
from main.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:300:5: note: candidate: ‘template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’
300 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/11/bits/stl_algob
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
template<typename T> class segtree {
private:
int n,sz;
vector<pair<T, int> > node;
public:
segtree(vector<T>& v) : sz((int)v.size()){
n = 1;
while(n < sz){
n *= 2;
}
node.resize(2*n, make_pair(numeric_limits<T>::max(), -1));
for(int i = 0; i < sz; i++){
node[i+n] = make_pair(v[i], i);
}
for(int i=n-1; i>=1; i--){
node[i] = min(node[2*i], node[2*i+1]);
}
}
void update(int k, T a)
{
node[k+n] = make_pair(a, k);
k+=n;
while(k>>=1){
node[k] = min(node[2*k], node[2*k+1]);
}
}
pair<T, int> query(int a,int b,int k=0,int l=0,int r=-1)
{
pair<T, int> res1 = make_pair(numeric_limits<T>::max(), -1);
pair<T, int> res2 = make_pair(numeric_limits<T>::max(), -1);
a += n, b += n;
while(a != b){
if(a % 2) res1 = min(res1, node[a++]);
if(b % 2) res2 = min(res2, node[--b]);
a >>= 1, b>>= 1;
}
return min(res1, res2);
}
void print()
{
for(int i = 0; i < sz; i++){
pair<T, int> p;
p = query(i,i+1);
cout << "st[" << i << "]: " << p.fi << " " << p.se << endl;
}
}
};
int main(){
int n,q;
cin >> n >> q;
vector<int>a(n);
rep(i,n)cin >> a[i];
segtree<int>sg(a);
rep(i,q){
int c,l,r;
cin >> c >> l >> r;
l--;r--;
if(c==1){
int p = sg.query(l,l+1).first;
int q = sg.query(r,r+1).first;
sg.update(l,q);
sg.update(r,p);
}else{
cout << sg.query(l,r+1).second+1 << endl;
}
}
return 0;
}
mtsd