結果
問題 | No.992 最長増加部分列の数え上げ |
ユーザー | koi_kotya |
提出日時 | 2020-02-14 23:17:09 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,782 bytes |
コンパイル時間 | 1,801 ms |
コンパイル使用メモリ | 188,048 KB |
実行使用メモリ | 28,472 KB |
最終ジャッジ日時 | 2024-10-06 13:17:50 |
合計ジャッジ時間 | 11,175 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | WA | - |
testcase_04 | AC | 104 ms
12,984 KB |
testcase_05 | AC | 70 ms
10,368 KB |
testcase_06 | AC | 126 ms
14,908 KB |
testcase_07 | AC | 92 ms
12,112 KB |
testcase_08 | AC | 47 ms
8,064 KB |
testcase_09 | AC | 91 ms
12,368 KB |
testcase_10 | AC | 128 ms
14,908 KB |
testcase_11 | AC | 168 ms
17,656 KB |
testcase_12 | AC | 32 ms
6,816 KB |
testcase_13 | AC | 93 ms
11,936 KB |
testcase_14 | AC | 91 ms
11,840 KB |
testcase_15 | AC | 31 ms
6,820 KB |
testcase_16 | AC | 276 ms
26,268 KB |
testcase_17 | AC | 46 ms
8,064 KB |
testcase_18 | AC | 87 ms
11,876 KB |
testcase_19 | AC | 167 ms
17,644 KB |
testcase_20 | AC | 328 ms
28,304 KB |
testcase_21 | AC | 310 ms
28,300 KB |
testcase_22 | AC | 305 ms
28,264 KB |
testcase_23 | AC | 310 ms
28,212 KB |
testcase_24 | AC | 314 ms
28,172 KB |
testcase_25 | AC | 319 ms
28,248 KB |
testcase_26 | AC | 326 ms
28,472 KB |
testcase_27 | AC | 338 ms
28,284 KB |
testcase_28 | AC | 335 ms
28,188 KB |
testcase_29 | AC | 317 ms
28,264 KB |
testcase_30 | AC | 192 ms
27,204 KB |
testcase_31 | AC | 185 ms
26,820 KB |
testcase_32 | AC | 185 ms
26,816 KB |
testcase_33 | AC | 188 ms
27,172 KB |
testcase_34 | AC | 196 ms
25,576 KB |
testcase_35 | AC | 200 ms
26,984 KB |
testcase_36 | AC | 206 ms
26,992 KB |
testcase_37 | AC | 198 ms
26,984 KB |
testcase_38 | AC | 213 ms
26,984 KB |
testcase_39 | AC | 198 ms
26,992 KB |
testcase_40 | AC | 183 ms
27,116 KB |
testcase_41 | AC | 187 ms
27,500 KB |
testcase_42 | AC | 188 ms
27,484 KB |
testcase_43 | AC | 187 ms
27,452 KB |
testcase_44 | WA | - |
ソースコード
#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])%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; }