結果

問題 No.3782 Synchronized Subsequences
コンテスト
ユーザー askr58
提出日時 2026-10-26 09:00:48
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 245 ms / 3,000 ms
+ 379µs
コード長 810 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,411 ms
コンパイル使用メモリ 190,468 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2026-10-30 20:57:37
合計ジャッジ時間 8,331 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <atcoder/segtree>
using namespace std;

int op(int x,int y){
	return max(x,y);
}
int e(){
	return 0;
}
int main(){
	int T;
	cin>>T;
	while(T--){
		int n;
		cin>>n;
		vector<int> p(n),q(n);
		for(int i=0;i<n;i++)cin>>p[i],p[i]--;
		for(int i=0;i<n;i++)cin>>q[i],q[i]--;
		vector<atcoder::segtree<int,op,e>> seg(n,atcoder::segtree<int,op,e>(n));
		int ans=0;
		for(int i=0;i<n;i++){
			vector<int> hi(n),lo(n);
			for(int j=0;j<n;j++){
				hi[j]=seg[j].prod(p[i],n);
				lo[j]=seg[j].prod(0,p[i]);
			}
			atcoder::segtree<int,op,e> segh(n),segl(n);
			for(int j=0;j<n;j++){
				int res=max(segh.prod(q[j],n),segl.prod(0,q[j]))+1;
				ans=max(ans,res);
				seg[j].set(p[i],res);	
				segh.set(q[j],hi[j]);
				segl.set(q[j],lo[j]);
			}
		}
		cout<<ans<<endl;
	}
}
0