結果

問題 No.3782 Synchronized Subsequences
コンテスト
ユーザー askr58
提出日時 2026-07-18 20:24:46
言語 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  
実行時間 253 ms / 3,000 ms
+ 187µs
コード長 860 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,526 ms
コンパイル使用メモリ 190,532 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2026-10-30 20:50:24
合計ジャッジ時間 9,268 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;
using ll=long long;
int op(int x,int y){
	return max(x,y);
}
int e(){
	return 0;
}
int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int ttt;
	cin>>ttt;
	while(ttt--){
		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]--;
		auto segs=vector(n,atcoder::segtree<int,op,e>(n));
		for(int i=0;i<n;i++){
			atcoder::segtree<int,op,e> segl(n),segh(n);
			vector<int> res(n);
			for(int j=0;j<n;j++){
				res[j]=max(segl.prod(0,q[j]),segh.prod(q[j]+1,n))+1;
				segl.set(q[j],segs[j].prod(0,p[i]));segh.set(q[j],segs[j].prod(p[i]+1,n));
			}
			for(int j=0;j<n;j++)segs[j].set(p[i],res[j]);
		}
		int ans=0;
		for(int i=0;i<n;i++)ans=max(ans,segs[i].all_prod());
		cout<<ans<<endl;
	}
}
				
			
		
0