結果

問題 No.992 最長増加部分列の数え上げ
ユーザー Plan8Plan8
提出日時 2020-05-05 16:47:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 3,388 bytes
コンパイル時間 2,399 ms
コンパイル使用メモリ 212,572 KB
実行使用メモリ 708,700 KB
最終ジャッジ日時 2023-09-09 04:09:36
合計ジャッジ時間 26,734 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 341 ms
171,888 KB
testcase_05 AC 222 ms
109,768 KB
testcase_06 AC 465 ms
235,140 KB
testcase_07 AC 294 ms
147,472 KB
testcase_08 AC 119 ms
57,688 KB
testcase_09 AC 301 ms
151,488 KB
testcase_10 AC 450 ms
231,432 KB
testcase_11 AC 651 ms
327,352 KB
testcase_12 AC 73 ms
34,140 KB
testcase_13 AC 286 ms
138,268 KB
testcase_14 AC 288 ms
139,896 KB
testcase_15 AC 74 ms
34,948 KB
testcase_16 MLE -
testcase_17 AC 125 ms
59,044 KB
testcase_18 AC 279 ms
133,852 KB
testcase_19 AC 640 ms
319,288 KB
testcase_20 MLE -
testcase_21 MLE -
testcase_22 MLE -
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
testcase_26 MLE -
testcase_27 MLE -
testcase_28 MLE -
testcase_29 MLE -
testcase_30 AC 134 ms
18,856 KB
testcase_31 AC 132 ms
18,856 KB
testcase_32 AC 133 ms
19,148 KB
testcase_33 AC 130 ms
18,984 KB
testcase_34 AC 128 ms
18,844 KB
testcase_35 AC 129 ms
18,844 KB
testcase_36 AC 118 ms
19,128 KB
testcase_37 AC 127 ms
18,832 KB
testcase_38 AC 138 ms
18,840 KB
testcase_39 AC 117 ms
18,864 KB
testcase_40 AC 128 ms
19,720 KB
testcase_41 AC 129 ms
19,636 KB
testcase_42 AC 129 ms
19,776 KB
testcase_43 AC 130 ms
19,588 KB
testcase_44 AC 131 ms
19,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int func(int a, int b){return (a+b)%MOD;}
int init_v = 0;

template<typename T>
struct BIT{

    int n;
    vector<T> node;

    public:

        BIT(int N) {
            n = N + 1;

            node.resize(n, init_v);
            for(int i=1; i<n; i++) if((i+(i&-i)) < n) node[i+(i&-i)] = func(node[i+(i&-i)], node[i]);
        }

        BIT() {}

        void add(int pos, T v) {
            // 1-indexed
            if(pos == 0) return;
            while(pos < n){
                node[pos] = func(node[pos], v);
                pos += pos & -pos;
            }
        }

        T sum(int pos){
            // 1-indexed
            T res = init_v;
            while(pos > 0){
                res = func(res, node[pos]);
                pos = pos & (pos-1);
            }
            return res;
        }
};

void compress(vector<int> &v){
    int N = v.size(), mn = 1000000000;
    vector<pair<int,int>> a(N);
    for(int i=0; i<N; ++i){
        a[i].first = v[i];
        a[i].second = i;
        mn = min(mn, v[i]);
    }
    sort(a.begin(), a.end());
    
    int prev = mn-1, n = -1;
    for(int i=0; i<N; ++i){
        if(a[i].first == prev) v[a[i].second] = n;
        else{
            n++;
            prev = a[i].first;
            v[a[i].second] = n;
        }
    }
}

int main(void){
    int N; cin >> N;
    VI A(N); REP(i,N) cin >> A[i];
    compress(A);
    VI dp, len(N), mx(N+1,0);
    int maxlen = 0;
    REP(i,N){
        int t = LB(dp, A[i]);
        if(t < dp.size()) chmin(dp[t], A[i]);
        else dp.push_back(A[i]);
        len[i] = t+1;
        chmax(mx[len[i]], A[i]+1);
        chmax(maxlen, len[i]);
    }

    vector<BIT<int>> v(N+1);
    REP(i,N+1) v[i] = BIT<int>(mx[i]);

    REP(i,N){
        int idx = min(v[len[i]-1].n-1, A[i]);
        int n = len[i]>1 ? v[len[i]-1].sum(idx) : 1;
        v[len[i]].add(A[i]+1, n);
    }

    int ans = v[maxlen].sum(mx[maxlen]);
    cout << ans << en;
    return 0;
}
0