結果
問題 | No.992 最長増加部分列の数え上げ |
ユーザー | face4 |
提出日時 | 2020-02-19 10:19:54 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 173 ms / 2,000 ms |
コード長 | 2,240 bytes |
コンパイル時間 | 1,086 ms |
コンパイル使用メモリ | 83,324 KB |
実行使用メモリ | 9,808 KB |
最終ジャッジ日時 | 2024-04-16 18:54:51 |
合計ジャッジ時間 | 9,274 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 2 ms
5,376 KB |
testcase_04 | AC | 65 ms
6,252 KB |
testcase_05 | AC | 47 ms
5,376 KB |
testcase_06 | AC | 79 ms
6,476 KB |
testcase_07 | AC | 59 ms
6,032 KB |
testcase_08 | AC | 32 ms
5,376 KB |
testcase_09 | AC | 60 ms
6,216 KB |
testcase_10 | AC | 81 ms
6,352 KB |
testcase_11 | AC | 101 ms
6,736 KB |
testcase_12 | AC | 21 ms
5,376 KB |
testcase_13 | AC | 56 ms
6,088 KB |
testcase_14 | AC | 57 ms
6,216 KB |
testcase_15 | AC | 21 ms
5,376 KB |
testcase_16 | AC | 151 ms
9,420 KB |
testcase_17 | AC | 31 ms
5,376 KB |
testcase_18 | AC | 56 ms
6,220 KB |
testcase_19 | AC | 96 ms
6,736 KB |
testcase_20 | AC | 171 ms
9,676 KB |
testcase_21 | AC | 168 ms
9,636 KB |
testcase_22 | AC | 167 ms
9,680 KB |
testcase_23 | AC | 167 ms
9,676 KB |
testcase_24 | AC | 173 ms
9,680 KB |
testcase_25 | AC | 171 ms
9,676 KB |
testcase_26 | AC | 170 ms
9,808 KB |
testcase_27 | AC | 168 ms
9,712 KB |
testcase_28 | AC | 166 ms
9,604 KB |
testcase_29 | AC | 169 ms
9,676 KB |
testcase_30 | AC | 158 ms
9,748 KB |
testcase_31 | AC | 160 ms
9,644 KB |
testcase_32 | AC | 159 ms
9,752 KB |
testcase_33 | AC | 159 ms
9,676 KB |
testcase_34 | AC | 158 ms
9,608 KB |
testcase_35 | AC | 166 ms
9,676 KB |
testcase_36 | AC | 167 ms
9,804 KB |
testcase_37 | AC | 167 ms
9,680 KB |
testcase_38 | AC | 167 ms
9,676 KB |
testcase_39 | AC | 170 ms
9,676 KB |
testcase_40 | AC | 153 ms
9,720 KB |
testcase_41 | AC | 154 ms
9,644 KB |
testcase_42 | AC | 156 ms
9,724 KB |
testcase_43 | AC | 154 ms
9,636 KB |
testcase_44 | AC | 156 ms
9,804 KB |
ソースコード
#include<iostream> #include<vector> #include<algorithm> using namespace std; typedef long long ll; const int mod = 1000000007; template<typename T, typename F> struct Seg{ private: vector<T> node; int n; F f; T def; public: Seg(int siz, T d, F f) : def(d), f(f) { n = 1; while(n < siz) n *= 2; node.resize(2*n-1, def); } Seg(vector<T> v, T d, F f) : def(d), f(f){ n = 1; while(n < v.size()) n *= 2; node.resize(2*n-1); for(int i = 0; i < v.size(); i++) node[n-1+i] = v[i]; for(int i = n-2; i >= 0; i--) node[i] = f(node[2*i+1], node[2*i+2]); } void update(int x, T val){ x += n-1; node[x] = val; /* ! */ while(x){ x = (x-1)/2; node[x] = f(node[2*x+1], node[2*x+2]); } } T query(int a, int b){ int L = a+n-1, R = b+n-1; T ret = def; while(L < R){ if((R&1) == 0) ret = f(ret, node[--R]); if((L&1) == 0) ret = f(ret, node[L++]); L >>= 1, R >>= 1; } return ret; } }; struct Box{ int length, count; bool operator<(const Box other) const{ if(length != other.length) return length < other.length; if(count != other.count) return count < other.count; return this; } }; int main(){ int n; cin >> n; vector<pair<int,int>> vp; for(int i = 0; i < n; i++){ int x; cin >> x; vp.push_back({x, -i}); } sort(vp.begin(), vp.end()); vector<int> a(n); for(int i = 0; i < n; i++){ a[-vp[i].second] = i; } auto f = [](Box a, Box b){ if(a.length < b.length){ return b; }else if(a.length > b.length){ return a; }else if(a.length == b.length){ (a.count += b.count) %= mod; return a; } return a; }; Seg<Box, decltype(f)> argmax(n+1, {0,0}, f); argmax.update(0, {0,1}); for(int i = 0; i < n; i++){ int pos = -vp[i].second+1; Box now = argmax.query(0, pos); now.length++; argmax.update(pos, now); } cout << argmax.query(1, n+1).count << endl; return 0; }