結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー 沙耶花沙耶花
提出日時 2021-11-26 22:57:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,076 ms / 3,000 ms
コード長 1,496 bytes
コンパイル時間 4,797 ms
コンパイル使用メモリ 268,056 KB
実行使用メモリ 11,280 KB
最終ジャッジ日時 2023-09-12 05:49:34
合計ジャッジ時間 13,519 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 10 ms
4,376 KB
testcase_02 AC 10 ms
4,380 KB
testcase_03 AC 9 ms
4,380 KB
testcase_04 AC 9 ms
4,376 KB
testcase_05 AC 10 ms
4,376 KB
testcase_06 AC 344 ms
5,272 KB
testcase_07 AC 371 ms
7,032 KB
testcase_08 AC 329 ms
6,528 KB
testcase_09 AC 337 ms
5,064 KB
testcase_10 AC 346 ms
6,888 KB
testcase_11 AC 417 ms
7,100 KB
testcase_12 AC 340 ms
7,252 KB
testcase_13 AC 295 ms
7,312 KB
testcase_14 AC 323 ms
7,172 KB
testcase_15 AC 382 ms
7,100 KB
testcase_16 AC 459 ms
10,956 KB
testcase_17 AC 461 ms
11,124 KB
testcase_18 AC 470 ms
10,952 KB
testcase_19 AC 343 ms
11,280 KB
testcase_20 AC 440 ms
11,064 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 137 ms
4,376 KB
testcase_25 AC 1,076 ms
11,052 KB
testcase_26 AC 524 ms
11,048 KB
testcase_27 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000001

int op(int a,int b){
	return max(a,b);
}
int opm(int a,int b){
	return min(a,b);
}
int em(){
	return Inf;
}

int e(){
	return 0;
}
int solve(){
	int n;
	cin>>n;
	vector<int> a(n),b(n);
	vector<pair<int,int>> p(n);
	rep(i,n){
		cin>>a[i];
	}
	rep(i,n){
		cin>>b[i];
		p[i] = make_pair(b[i],i);
	}
	
	segtree<int,op,e> seg(a);
	segtree<int,opm,em> segm(n);
	
	sort(p.begin(),p.end());
	
	rep(i,n){
		int ind = p[i].second;
		//cout<<ind<<endl;
		if(seg.get(ind)>b[ind]){
			cout<<"No"<<endl;
			return 0;
		}
		int ok = ind+1,ng = n+1;
		while(ng-ok>1){
			int mid = (ok+ng)/2;
			if(seg.prod(ind,mid)>b[ind] || segm.prod(ind,mid)<b[ind])ng = mid;
			else ok = mid;
		}
		if(seg.prod(ind,ok)==b[ind]){

			seg.set(ind,b[ind]);
			segm.set(ind,b[ind]);
			continue;
		}
		ok = ind+1,ng = -1;
		while(ok-ng>1){
			int mid = (ok+ng)/2;
			if(seg.prod(mid,ind+1)>b[ind] || segm.prod(mid,ind+1)<b[ind])ng = mid;
			else ok = mid;
		}
		/*
		cout<<ok<<','<<ind+1<<','<<seg.prod(ok,ind+1)<<endl;
		rep(j,n){
			cout<<seg.get(j)<<',';
		}
		cout<<endl;*/
		if(seg.prod(ok,ind+1)==b[ind]){
			seg.set(ind,b[ind]);
			segm.set(ind,b[ind]);
			continue;
		}
		cout<<"No"<<endl;
		return 0;
	}
	
	cout<<"Yes"<<endl;
	return 0;
}

int main(){
	
	int _t;
	cin>>_t;
	rep(_,_t){
		solve();
	}
	
	return 0;
}
0