結果
問題 | No.992 最長増加部分列の数え上げ |
ユーザー | NOSS |
提出日時 | 2020-02-14 22:51:09 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 246 ms / 2,000 ms |
コード長 | 2,128 bytes |
コンパイル時間 | 1,888 ms |
コンパイル使用メモリ | 174,976 KB |
実行使用メモリ | 13,184 KB |
最終ジャッジ日時 | 2024-04-16 02:47:12 |
合計ジャッジ時間 | 10,526 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 88 ms
7,936 KB |
testcase_05 | AC | 62 ms
5,888 KB |
testcase_06 | AC | 108 ms
8,192 KB |
testcase_07 | AC | 78 ms
7,936 KB |
testcase_08 | AC | 40 ms
5,504 KB |
testcase_09 | AC | 81 ms
7,936 KB |
testcase_10 | AC | 109 ms
8,064 KB |
testcase_11 | AC | 139 ms
8,192 KB |
testcase_12 | AC | 27 ms
5,376 KB |
testcase_13 | AC | 76 ms
7,936 KB |
testcase_14 | AC | 77 ms
7,936 KB |
testcase_15 | AC | 27 ms
5,376 KB |
testcase_16 | AC | 220 ms
13,056 KB |
testcase_17 | AC | 39 ms
5,504 KB |
testcase_18 | AC | 75 ms
7,808 KB |
testcase_19 | AC | 137 ms
8,192 KB |
testcase_20 | AC | 243 ms
13,056 KB |
testcase_21 | AC | 243 ms
12,928 KB |
testcase_22 | AC | 243 ms
12,928 KB |
testcase_23 | AC | 246 ms
12,928 KB |
testcase_24 | AC | 243 ms
13,056 KB |
testcase_25 | AC | 242 ms
12,928 KB |
testcase_26 | AC | 241 ms
13,056 KB |
testcase_27 | AC | 245 ms
13,056 KB |
testcase_28 | AC | 243 ms
13,056 KB |
testcase_29 | AC | 242 ms
12,928 KB |
testcase_30 | AC | 210 ms
13,184 KB |
testcase_31 | AC | 212 ms
12,928 KB |
testcase_32 | AC | 211 ms
12,928 KB |
testcase_33 | AC | 209 ms
13,056 KB |
testcase_34 | AC | 208 ms
12,928 KB |
testcase_35 | AC | 221 ms
13,056 KB |
testcase_36 | AC | 221 ms
12,928 KB |
testcase_37 | AC | 221 ms
13,056 KB |
testcase_38 | AC | 221 ms
12,928 KB |
testcase_39 | AC | 221 ms
12,928 KB |
testcase_40 | AC | 204 ms
13,056 KB |
testcase_41 | AC | 205 ms
13,056 KB |
testcase_42 | AC | 206 ms
12,928 KB |
testcase_43 | AC | 204 ms
12,928 KB |
testcase_44 | AC | 206 ms
13,056 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long int; using P = pair<int, int>; using P3 = pair<int,P>; using PP = pair<P, P>; constexpr int INF = 1<<30; constexpr ll MOD = ll(1e9)+7; constexpr int di[] = {0,1,0,-1}; constexpr int dj[] = {1,0,-1,0}; template <typename Monoid> struct SegmentTree{ private: using F = function<Monoid(Monoid, Monoid)>; int N; vector<Monoid> node; F f; Monoid e; // identity element public: SegmentTree(){} SegmentTree(F f, Monoid e):f(f), e(e){} void init(int sz){ N = 1; while(N < sz) N <<= 1; node.assign(2*N-1, e); } void build(vector<Monoid>& v){ int sz = int(v.size()); init(sz); for(int i=0; i<sz; i++){ node[i+N-1] = v[i]; } for(int i=N-2; i>=0; i--){ node[i] = f(node[i*2+1], node[i*2+2]); } } void update(int k, Monoid x){ k += N-1; node[k] = x; while(k > 0){ k = (k-1)/2; node[k] = f(node[2*k+1], node[2*k+2]); } } // [a,b) Monoid query(int a, int b){return query(a, b, 0, 0, N);} Monoid query(int a, int b, int k, int l, int r){ if(b <= l || r <= a) return e; if(a <= l && r <= b) return node[k]; Monoid vl, vr; vl = query(a, b, 2*k+1, l, (l+r)/2); vr = query(a, b, 2*k+2, (l+r)/2, r); return f(vl, vr); } }; struct T{ ll maxi=0, cnt=0; T(){} T(ll m, ll c):maxi(m),cnt(c){} }; auto f = [](T a, T b){ if(a.maxi > b.maxi) return a; else if(a.maxi < b.maxi) return b; else return T(a.maxi, (a.cnt+b.cnt)%MOD); }; SegmentTree<T> seg(f, T()); int main(){ int n; cin >> n; vector<P> a(n); for(int i=0;i<n;i++){ cin >> a[i].first; a[i].second = -i; } sort(a.begin(),a.end()); seg.init(n+1); seg.update(0,T(0,1)); for(int i=0;i<n;i++){ int idx = abs(a[i].second)+1; auto res = seg.query(0,idx); res.maxi++; seg.update(idx,res); } cout << seg.query(0,n+1).cnt << endl; return 0; }