結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー kotatsugamekotatsugame
提出日時 2021-11-26 22:48:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,642 bytes
コンパイル時間 1,377 ms
コンパイル使用メモリ 99,876 KB
実行使用メモリ 46,672 KB
最終ジャッジ日時 2023-09-12 05:48:49
合計ジャッジ時間 6,394 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 186 ms
22,404 KB
testcase_13 WA -
testcase_14 AC 187 ms
22,476 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 201 ms
42,948 KB
testcase_20 AC 200 ms
42,852 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 224 ms
46,668 KB
testcase_27 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:37:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   37 | main()
      | ^~~~

ソースコード

diff #

#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;
				j++;
			}
			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");
	}
}
0