結果

問題 No.3782 Synchronized Subsequences
コンテスト
ユーザー askr58
提出日時 2026-07-20 02:27:26
言語 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  
実行時間 272 ms / 3,000 ms
+ 410µs
コード長 1,163 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,618 ms
コンパイル使用メモリ 212,128 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2026-10-30 20:51:08
合計ジャッジ時間 8,922 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <cassert>
#include <vector>
#include <ranges>
#include <algorithm>
#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;
	assert(1<=ttt&&ttt<=1000);
	int sum=0;
	while(ttt--){
		int n;
		cin>>n;
		assert(1<=n&&n<=1000);
		sum+=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<int> sp=p,sq=q;
			ranges::sort(sp);
			ranges::sort(sq);
			for(int i=0;i<n;i++){
				assert(sp[i]==i);
				assert(sq[i]==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;
	}
	assert(sum<=1000);
}
				
			
		
0