結果
問題 |
No.1768 The frog in the well knows the great ocean.
|
ユーザー |
|
提出日時 | 2021-11-26 22:49:49 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,633 bytes |
コンパイル時間 | 1,365 ms |
コンパイル使用メモリ | 99,776 KB |
実行使用メモリ | 51,648 KB |
最終ジャッジ日時 | 2024-06-29 18:55:04 |
合計ジャッジ時間 | 8,062 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 25 WA * 2 |
コンパイルメッセージ
main.cpp:37:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 37 | main() | ^~~~
ソースコード
#include<iostream> #include<set> #include<vector> #include<algorithm> using namespace std; #include<vector> #include<algorithm> template<typename T> struct rangefreq{ int n; vector<vector<T> >dat; rangefreq(const vector<T>&v={}) { n=1; while(n<v.size())n<<=1; dat.assign(2*n-1,{}); for(int i=0;i<v.size();i++)dat[i+n-1].push_back(v[i]); for(int i=n-2;i>=0;i--) { dat[i].resize(dat[i*2+1].size()+dat[i*2+2].size()); merge(dat[i*2+1].begin(),dat[i*2+1].end(), dat[i*2+2].begin(),dat[i*2+2].end(), dat[i].begin() ); } } int query(int a,int b,T x,int k=0,int l=0,int r=-1)const//[a,b) count(*<x) { if(r<0)r=n; if(b<=l||r<=a)return 0; else if(a<=l&&r<=b)return lower_bound(dat[k].begin(),dat[k].end(),x)-dat[k].begin(); else return query(a,b,x,k*2+1,l,(l+r)/2)+query(a,b,x,k*2+2,(l+r)/2,r); } }; int T,N; int A[2<<17]; main() { cin>>T; vector<pair<int,int> >B; set<int>S; for(;T--;) { cin>>N; for(int i=0;i<N;i++)cin>>A[i]; B.resize(N); for(int i=0;i<N;i++) { cin>>B[i].first; B[i].second=i; } sort(B.begin(),B.end()); rangefreq<int>P(vector<int>(A,A+N)); S.clear(); S.insert(-1); S.insert(N); bool out=false; for(int i=0;i<B.size();) { auto it=S.lower_bound(B[i].second); int R=*it; it--; int L=*it+1; int j=i; int b=B[i].first; while(j<B.size()&&b==B[j].first&&B[j].second<R) { int id=B[j++].second; if(A[id]>b)out=true; } if(P.query(L,R,b+1)>P.query(L,R,b)) { for(int k=i;k<j;k++)S.insert(B[k].second); } else { out=true; } if(out)break; i=j; } cout<<(out?"No\n":"Yes\n"); } }