結果

問題 No.3746 Swap and LIS
コンテスト
ユーザー V_Melville
提出日時 2026-09-25 23:21:20
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 248 ms / 2,000 ms
+ 622µs
コード長 961 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,873 ms
コンパイル使用メモリ 342,144 KB
実行使用メモリ 23,552 KB
最終ジャッジ日時 2026-09-25 23:21:32
合計ジャッジ時間 7,747 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;

void solve() {
    int n;
    cin >> n;
    
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    
    set<int> s1, s2;
    auto add = [&](int x) {
        auto it1 = s1.lower_bound(x);
        if (it1 == s1.end()) {
            s1.insert(x);
            return;
        }
        
        int y = *it1;
        
        s1.erase(it1);
        s1.insert(x);
        
        auto it2 = s2.lower_bound(y);
        if (it2 == s2.end()) {
            s2.insert(y);
            return;
        }
        
        s2.erase(it2);
        s2.insert(y);
    };
    
    rep(i, n) {
        auto [x, y] = minmax(a[i], b[i]);
        add(y);
        add(x);
    }
    
    int ans = s1.size()+s2.size();
    cout << ans << '\n';
}

int main() {
    int t;
    cin >> t;
    
    while (t--) solve();
    
    return 0;
}
0