結果
問題 | No.992 最長増加部分列の数え上げ |
ユーザー | koi_kotya |
提出日時 | 2020-02-14 23:19:51 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 323 ms / 2,000 ms |
コード長 | 3,784 bytes |
コンパイル時間 | 2,173 ms |
コンパイル使用メモリ | 188,084 KB |
実行使用メモリ | 28,320 KB |
最終ジャッジ日時 | 2024-10-06 13:20:58 |
合計ジャッジ時間 | 11,247 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 108 ms
12,988 KB |
testcase_05 | AC | 78 ms
10,368 KB |
testcase_06 | AC | 132 ms
14,832 KB |
testcase_07 | AC | 91 ms
12,112 KB |
testcase_08 | AC | 46 ms
8,064 KB |
testcase_09 | AC | 93 ms
12,360 KB |
testcase_10 | AC | 131 ms
14,908 KB |
testcase_11 | AC | 168 ms
17,740 KB |
testcase_12 | AC | 32 ms
6,816 KB |
testcase_13 | AC | 89 ms
11,944 KB |
testcase_14 | AC | 88 ms
11,840 KB |
testcase_15 | AC | 30 ms
6,816 KB |
testcase_16 | AC | 276 ms
26,188 KB |
testcase_17 | AC | 47 ms
8,064 KB |
testcase_18 | AC | 88 ms
11,744 KB |
testcase_19 | AC | 172 ms
17,640 KB |
testcase_20 | AC | 318 ms
28,272 KB |
testcase_21 | AC | 310 ms
28,296 KB |
testcase_22 | AC | 307 ms
28,252 KB |
testcase_23 | AC | 311 ms
28,320 KB |
testcase_24 | AC | 302 ms
28,116 KB |
testcase_25 | AC | 315 ms
28,268 KB |
testcase_26 | AC | 323 ms
28,304 KB |
testcase_27 | AC | 323 ms
28,276 KB |
testcase_28 | AC | 319 ms
28,240 KB |
testcase_29 | AC | 317 ms
28,192 KB |
testcase_30 | AC | 188 ms
27,204 KB |
testcase_31 | AC | 187 ms
26,820 KB |
testcase_32 | AC | 186 ms
26,824 KB |
testcase_33 | AC | 188 ms
27,172 KB |
testcase_34 | AC | 196 ms
25,584 KB |
testcase_35 | AC | 201 ms
26,980 KB |
testcase_36 | AC | 200 ms
26,988 KB |
testcase_37 | AC | 203 ms
27,108 KB |
testcase_38 | AC | 200 ms
26,988 KB |
testcase_39 | AC | 199 ms
27,116 KB |
testcase_40 | AC | 189 ms
27,116 KB |
testcase_41 | AC | 188 ms
27,500 KB |
testcase_42 | AC | 184 ms
27,612 KB |
testcase_43 | AC | 199 ms
27,632 KB |
testcase_44 | AC | 186 ms
27,768 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; ll const mod = 1e9+7; #define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) struct SegmentTree { private: int n; vector<int> node; public: SegmentTree(vector<int> v) { int sz = v.size(); n = 1; while (n < sz) n *= 2; node.resize(2*n-1,0); for (int i = 0;i < sz;++i) node[i+n-1] = v[i]; for (int i = n-2;i >= 0;--i) node[i] = max(node[2*i+1],node[2*i+2]); } void update(int x,int val) { x += (n-1); node[x] = val; while (x > 0) { x = (x-1)/2; node[x] = max(node[2*x+1],node[2*x+2]); } } int getmax(int a,int b,int k = 0,int l = 0,int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return 0; if (a <= l && r <= b) return node[k]; int vl = getmax(a,b,2*k+1,l,(l+r)/2); int vr = getmax(a,b,2*k+2,(l+r)/2,r); return max(vl,vr); } // [a,b)でxより大きい要素の最左位置 int find(int a,int b,int x,int k = 0,int l = 0,int r = -1) { if (r < 0) r = n; if (r <= a || b <= l || node[k] <= x) return -1; if (k >= n-1) return k-n+1; int vl = find(a,b,x,2*k+1,l,(l+r)/2); if (vl != -1) return vl; return find(a,b,x,2*k+2,(l+r)/2,r); } }; struct BinaryIndexedTree { private: int n,b; vector<ll> bit; public: BinaryIndexedTree(int n_) { n = n_+10; b = 1; while (b < n) b <<= 1; b >>= 1; bit = vector<ll>(n,0); } void add(int a,ll w) { a++; for (int x = a;x < n;x += x&-x) bit[x] += w; } ll sum(int a) { a++; ll ret = 0; for (int x = a;x > 0;x -= x&-x) ret += bit[x]; return ret; } void update(int a,ll w) { // a++; ll v = w-sum(a)+sum(a-1); add(a,v); } int lower_bound(int w) { if (w <= 0) return 0; int x = 0; for (int k = b;k > 0;k /= 2) { if (x+k < n && bit[x+k] < w) { w -= bit[x+k]; x += k; } } return x; } }; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0;i < n;++i) cin >> a[i]; map<int,int> mp; for (int i = 0;i < n;++i) mp[a[i]] = 0; { int i = 1; for (auto& p : mp) { p.second = i; i++; } } vector<int> b(n),c(n); for (int i = 0;i < n;++i) b[i] = mp[a[i]]; SegmentTree seg(vector<int>(n+1,0)); for (int i = 0;i < n;++i) { c[i] = seg.getmax(0,b[i])+1; seg.update(b[i],c[i]); } BinaryIndexedTree bit(n); vector<vector<pair<int,ll>>> p(n+1); p[0].push_back(make_pair(-1,1)); for (int i = 0;i < n;++i) p[c[i]].push_back(make_pair(i,0)); for (int i = 0;i < n;++i) { int j = 0,m = p[i].size(); for (pair<int,ll>& q : p[i+1]) { while (j < m && p[i][j].first < q.first) { bit.add((i ? b[p[i][j].first] : 0),p[i][j].second); j++; } q.second = bit.sum(b[q.first]-1)%mod; } if (i) for (pair<int,ll>& q : p[i]) bit.update(b[q.first],0); else bit.update(0,0); } int mx = 0; for (int i = 0;i < n;++i) mx = max(c[i],mx); ll ans = 0; for (auto q : p[mx]) (ans += q.second) %= mod; cout << ans << endl; }