結果
| 問題 |
No.878 Range High-Element Query
|
| コンテスト | |
| ユーザー |
mtsd
|
| 提出日時 | 2019-09-06 22:47:10 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 3,813 bytes |
| コンパイル時間 | 667 ms |
| コンパイル使用メモリ | 87,944 KB |
| 最終ジャッジ日時 | 2024-06-24 20:19:16 |
| 合計ジャッジ時間 | 1,238 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In constructor ‘segtreemx<T>::segtreemx(std::vector<_Tp>&)’:
main.cpp:85:28: error: ‘numeric_limits’ was not declared in this scope
85 | node.resize(2*n-1, numeric_limits<T>::min());
| ^~~~~~~~~~~~~~
main.cpp:85:44: error: expected primary-expression before ‘>’ token
85 | node.resize(2*n-1, numeric_limits<T>::min());
| ^
main.cpp:85:50: error: no matching function for call to ‘min()’
85 | node.resize(2*n-1, numeric_limits<T>::min());
| ~~~~~^~
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:230:5: note: candidate: ‘template<class _Tp> const _Tp& std::min(const _Tp&, const _Tp&)’
230 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/11/bits/stl_algobase.h:230:5: note: template argument deduction/substitution failed:
main.cpp:85:50: note: candidate expects 2 arguments, 0 provided
85 | node.resize(2*n-1, numeric_limits<T>::min());
| ~~~~~^~
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:278:5: note: candidate: ‘template<class _Tp, class _Compare> const _Tp& std::min(const _Tp&, const _Tp&, _Compare)’
278 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/11/bits/stl_algobase.h:278:5: note: template argument deduction/substitution failed:
main.cpp:8
ソースコード
#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)
#define int long long
template<typename T> class segtree{
private:
int n,sz;
vector<T> node;
public:
segtree(vector<T>& v) : sz((int)v.size()){
n = 1;
while(n < sz){
n *= 2;
}
node.resize(2*n-1,0);
for(int i = 0; i < sz; i++){
node[i+n-1] = v[i];
}
for(int i=n-2; i>=0; i--){
node[i] = node[i*2+1]+node[i*2+2];
}
}
void update(int k,T a){
k += n-1;
node[k] = a;
while(k>0){
k = (k-1)/2;
node[k] = node[2*k+1]+node[2*k+2];
}
}
T query(int a,int b,int k=0,int l=0,int r=-1){
if(r < 0) r = n;
if(r <= a || b <= l){
return 0;
}
if(a <= l && r <= b){
return node[k];
}else{
T vl = query(a,b,2*k+1,l,(l+r)/2);
T vr = query(a,b,2*k+2,(l+r)/2,r);
return vl+vr;
}
}
void print(){
for(int i = 0; i < sz; i++){
cout<<query(i,i+1)<< " ";
}
cout<<endl;
}
};
template<typename T> class segtreemx{
private:
int n,sz;
vector<T> node;
public:
segtreemx(vector<T>& v) : sz((int)v.size()){
n = 1;
while(n < sz){
n *= 2;
}
node.resize(2*n-1, numeric_limits<T>::min());
for(int i = 0; i < sz; i++){
node[i+n-1] = v[i];
}
for(int i=n-2; i>=0; i--){
node[i] = max(node[i*2+1], node[i*2+2]);
}
}
void update(int k,T a){
k += n-1;
node[k] = a;
while(k>0){
k = (k-1)/2;
node[k] = max(node[2*k+1],node[2*k+2]);
}
}
T query(int a,int b,int k=0,int l=0,int r=-1){
if(r < 0) r = n;
if(r <= a || b <= l){
return numeric_limits<T>::min();
}
if(a <= l && r <= b){
return node[k];
}else{
T vl = query(a,b,2*k+1,l,(l+r)/2);
T vr = query(a,b,2*k+2,(l+r)/2,r);
return max(vl,vr);
}
}
void print(){
for(int i = 0; i < sz; i++){
cout<<query(i,i+1)<< " ";
}
cout<<endl;
}
};
signed main(){
int n,q;
cin >> n >> q;
vector<int>a(n);
rep(i,n)cin >> a[i];
set<pair<int,int> > st;
vector<int>b(n);
segtreemx<int>sgg(a);
rep(i,n){
int ng = -1;
int ok = i;
while(ok-ng>1){
int mid = (ok+ng)/2;
if(sgg.query(mid,i)>a[i]){
ng = mid;
}else{
ok = mid;
}
}
b[i] = ok;
//cerr << b[i] << endl;
}
vector<pair<pair<int,int>,int> > s;
rep(i,q){
int a,l,r;
cin >> a >> l >> r;
l--;
r--;
s.push_back(MP(MP(l,r),inf+i));
}
rep(i,n){
s.push_back(MP(MP(b[i],-1),i));
}
sort(s.begin(),s.end());
vector<int>c(n);
segtree<int>sg(c);
vector<int>res(q);
rep(i,n+q){
if(s[i].first.second==-1){
//cerr << i << " " << s[i].second << endl;
sg.update(s[i].second,1);
}else{
res[s[i].second-inf] = sg.query(s[i].first.first,s[i].first.second+1);
}
}
rep(i,q){
cout << res[i] << endl;
}
return 0;
}
mtsd