結果

問題 No.1804 Intersection of LIS
ユーザー penguinmanpenguinman
提出日時 2021-12-21 00:45:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 2,877 bytes
コンパイル時間 2,605 ms
コンパイル使用メモリ 207,908 KB
実行使用メモリ 18,992 KB
最終ジャッジ日時 2024-04-26 18:20:19
合計ジャッジ時間 5,802 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 81 ms
10,276 KB
testcase_04 AC 83 ms
10,276 KB
testcase_05 AC 81 ms
10,324 KB
testcase_06 AC 84 ms
10,148 KB
testcase_07 AC 84 ms
10,196 KB
testcase_08 AC 83 ms
10,276 KB
testcase_09 AC 83 ms
10,404 KB
testcase_10 AC 83 ms
10,152 KB
testcase_11 AC 82 ms
10,276 KB
testcase_12 AC 85 ms
10,276 KB
testcase_13 AC 85 ms
10,276 KB
testcase_14 AC 83 ms
10,272 KB
testcase_15 AC 82 ms
10,272 KB
testcase_16 AC 81 ms
10,404 KB
testcase_17 AC 81 ms
10,152 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 106 ms
18,988 KB
testcase_36 AC 108 ms
18,992 KB
testcase_37 AC 48 ms
10,120 KB
testcase_38 AC 47 ms
10,252 KB
testcase_39 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
//using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i, j, n) for(int i = int(j); i < int(n); i++)
#define REP(i, j, n) for(int i = int(j); i <= int(n); i++)
#define per(i, j, n) for(int i = int(j); int(n) <= i; i--)
#define ALL(a) (a).begin(),(a).end()
#define revALL(a) (a).rbegin(),(a).rend()
#define pb push_back
#define mp std::make_pair
#define mtp std::make_tuple
#define ln "\n"
using std::endl;
using std::cin;
using std::cout;
#define ll long long
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
const ll MOD = int(1e9+7);
const ll MAX = 1e6+10;
const ll inf = (1ll << 60);

//modpow
ll modpow(ll X, ll Y, ll mod){
    ll ret = 1;
    while(Y){
        if(Y & 1){
            ret *= X;
            ret %= mod;
        }
        X *= X;
        X %= mod;
        Y >>= 1;
    }
    return ret % mod;
}

//binary_indexed_tree
template<typename T>
struct binary_indexed_tree{
    int N;
    vector<T> bit;
    binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    T addition(T a, T b){
        return a+b;
    }
    void add(int x,T a){
        x++;
        for(; x<=N; x+=(x&-x)) bit[x] = addition(bit[x], a);
    }
    T sum(int x){
        x++;
        T ret=0;
        for(; x>0; x-=(x&-x)) ret = addition(ret, bit[x]);
        return ret;
    }
    ll lower_bound(T X){
        if(sum(N-1)<X) return -1;
        ll ret=0, memo=1;
        T sum=0;
        while(memo*2 <= N) memo *= 2;
        while(0 < memo){
            if(memo+ret<=N && addition(sum, bit[memo+ret])<X){
                sum = addition(sum, bit[memo+ret]);
                ret+=memo;
            }
            memo/=2;
        }
        return ret;
    }
};

//main
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    cout << std::fixed << std::setprecision(15);
    ll N; cin >> N;
    vector<ll> P(N);
    rep(i,0,N) cin >> P[i];
    vector<vector<ll>> lis(2);
    rep(t,0,2){
        vector<ll> dp(N+1,inf);
        dp[0] = 0;
        vector<ll> rev(N);
        rep(i,0,N){
            ll idx = lower_bound(ALL(dp),P[i])-dp.begin();
            rev[i] = dp[idx-1];
            dp[idx] = P[i];
        }
        ll now = dp[lower_bound(ALL(dp),inf)-dp.begin()-1];
        per(i,N-1,0){
            if(P[i] == now){
                lis[t].pb(now);
                now = rev[i];
            }
        }
        rep(i,0,N) P[i] = N+1-P[i];
        reverse(ALL(P));
    }
    reverse(ALL(lis[0]));
    vector<ll> ans;
    rep(i,0,lis[0].size()){
        if(lis[0][i]+lis[1][i] == N+1) ans.push_back(lis[0][i]);
    }
    cout << ans.size() << ln;
    rep(i,0,ans.size()) cout << ans[i] << " ";
    cout << ln;
}

0