結果
問題 | No.905 Sorted? |
ユーザー | ate |
提出日時 | 2019-11-18 16:21:49 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,477 bytes |
コンパイル時間 | 2,069 ms |
コンパイル使用メモリ | 199,268 KB |
最終ジャッジ日時 | 2024-11-14 21:51:16 |
合計ジャッジ時間 | 3,440 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In instantiation of 'std::istream& operator>>(std::istream&, std::vector<_Tp>&) [with T = std::pair<long long int, long long int>; std::istream = std::basic_istream<char>]': main.cpp:79:8: required from here main.cpp:14:84: error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'std::pair<long long int, long long int>') 14 | template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;} | ~~^~~~~~~~ In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54, from main.cpp:1: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:120:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__istream_type& (*)(__istream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' 120 | operator>>(__istream_type& (*__pf)(__istream_type&)) | ^~~~~~~~ /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:120:36: note: no known conversion for argument 1 from 'std::pair<long long int, long long int>' to 'std::basic_istream<char>::__istream_type& (*)(std::basic_istream<char>::__istream_type&)' {aka 'std::basic_istream<char>& (*)(std::basic_istream<char>&)'} 120 | operator>>(__istream_type& (*__pf)(__istream_type&)) | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(ll i=0;i<(n);++i) using ll = long long; using pll = pair<ll,ll>; constexpr ll INF = (1LL<<60); constexpr ll MOD = (1e9+7); //constexpr ll MOD = (998244353); template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;} template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;} void dump(){cout<<endl;} template<class T,class... Ts> void dump(T&& h, Ts&&... t){cout<<h<<", ";dump(forward<Ts>(t)...);} template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;} template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;} template<class T>vector<T> make_vector(size_t a){return vector<T>(a);} template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));} void solve1();void solve2(); int main(){ solve1(); return 0; } template<class T> class segtree { private: ll n=1; T unit; std::vector<T> dat; std::function<T(T,T)> func; public: segtree(){} segtree(std::vector<T>& a,T v,std::function<T(T,T)> f){ build(a,v,f); } void build(std::vector<T>& a,T v,std::function<T(T,T)> f){ ll sz=a.size(); unit=v; func=f; while(n<sz)n<<=1LL; dat.resize(2*n-1,unit); for(int i=0;i<sz;++i)dat[i+n-1]=a[i]; for(int i=n-2;i>=0;--i){ dat[i]=func(dat[i*2+1],dat[i*2+2]); } } void update(ll idx,T val){ idx+=n-1; dat[idx]=val; while(idx){ idx--;idx>>=1LL; dat[idx]=func(dat[idx*2+1],dat[idx*2+2]); } } T query(ll a,ll b,ll k=0,ll l=0,ll r=-1){ if(r<0)r=n; if( b<=l || r<=a )return unit; if( a<=l && r<=b )return dat[k]; else{ auto left=query(a,b,2*k+1,l,(l+r)/2); auto right=query(a,b,2*k+2,(l+r)/2,r); return func(left,right); } } }; void solve1(){ ll n; cin>>n; vector<ll> a(n); cin>>a; ll q; cin>>q; vector<pll> lr(q); cin>>lr; vector<ll>dif(n-1); rep(i,n-1)dif[i]=a[i+1]-a[i]; segtree<ll> seg_min(dif,INF,[](auto a,auto b){return min(a,b);}); segtree<ll> seg_max(dif,-INF,[](auto a,auto b){return max(a,b);}); for(auto [l,r]:lr){ ll mn = seg_min.query(l,r); ll mx = seg_max.query(l,r); if((mn==mx&&mn==0)||l==r)cout<<"1 1"<<endl; else if(mn>=0)cout<<"1 0"<<endl; else if(mx<=0)cout<<"0 1"<<endl; else cout<<"0 0"<<endl; } }