結果
| 問題 |
No.1768 The frog in the well knows the great ocean.
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-26 23:03:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,773 bytes |
| コンパイル時間 | 1,575 ms |
| コンパイル使用メモリ | 102,764 KB |
| 実行使用メモリ | 53,164 KB |
| 最終ジャッジ日時 | 2024-06-29 18:58:12 |
| 合計ジャッジ時間 | 10,404 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 24 WA * 3 |
コンパイルメッセージ
main.cpp:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
36 | 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;
main()
{
cin>>T;
vector<pair<int,int> >A,B;
vector<int>PA;
multiset<int>S;
for(;T--;)
{
cin>>N;
A.resize(N);
PA.resize(N);
for(int i=0;i<N;i++)
{
cin>>PA[i];
A[i]=make_pair(PA[i],i);
}
B.resize(N);
for(int i=0;i<N;i++)
{
cin>>B[i].first;
B[i].second=i;
}
sort(A.begin(),A.end());
sort(B.begin(),B.end());
rangefreq<int>P(PA);
S.clear();
S.insert(-1);
S.insert(N);
for(int i=0;i<N;i++)S.insert(i);
bool out=false;
int ai=0;
for(int i=0;i<B.size();)
{
int b=B[i].first;
int j=i;
while(j<B.size()&&b==B[j].first)j++;
while(ai<A.size()&&A[ai].first<=b)
{
S.erase(S.find(A[ai++].second));
}
for(int k=i;k<j;k++)
{
auto it=S.lower_bound(B[k].second);
int R=*it;
it--;
int L=*it+1;
if(P.query(L,R,b+1)==P.query(L,R,b))out=true;
}
while(i<j)
{
S.insert(B[i++].second);
}
}
cout<<(out?"No\n":"Yes\n");
}
}