結果
問題 | No.2374 ASKT Subsequences |
ユーザー | erbowl |
提出日時 | 2023-07-07 23:13:20 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 201 ms / 2,000 ms |
コード長 | 4,591 bytes |
コンパイル時間 | 2,108 ms |
コンパイル使用メモリ | 205,744 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-21 19:37:01 |
合計ジャッジ時間 | 3,377 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 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 | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 3 ms
5,376 KB |
testcase_18 | AC | 4 ms
5,376 KB |
testcase_19 | AC | 4 ms
5,376 KB |
testcase_20 | AC | 7 ms
5,376 KB |
testcase_21 | AC | 8 ms
5,376 KB |
testcase_22 | AC | 5 ms
5,376 KB |
testcase_23 | AC | 5 ms
5,376 KB |
testcase_24 | AC | 5 ms
5,376 KB |
testcase_25 | AC | 29 ms
5,376 KB |
testcase_26 | AC | 14 ms
5,376 KB |
testcase_27 | AC | 201 ms
5,376 KB |
testcase_28 | AC | 66 ms
5,376 KB |
testcase_29 | AC | 11 ms
5,376 KB |
testcase_30 | AC | 10 ms
5,376 KB |
ソースコード
typedef long long ll; typedef long double ld; #include <bits/stdc++.h> using namespace std; #define int long long // Segment Tree template<class Monoid> struct SegTree { using Func = function<Monoid(Monoid, Monoid)>; // core member int SIZE; Func F; Monoid IDENTITY; // data int offset; vector<Monoid> dat; // constructor SegTree() {} SegTree(int n, const Func &f, const Monoid &identity) : SIZE(n), F(f), IDENTITY(identity) { offset = 1; while (offset < n) offset *= 2; dat.assign(offset * 2, IDENTITY); } void init(int n, const Func &f, const Monoid &identity) { SIZE = n; F = f; IDENTITY = identity; offset = 1; while (offset < n) offset *= 2; dat.assign(offset * 2, IDENTITY); } int size() const { return SIZE; } // set, a is 0-indexed // // build(): O(N) void set(int a, const Monoid &v) { dat[a + offset] = v; } void build() { for (int k = offset - 1; k > 0; --k) dat[k] = F(dat[k*2], dat[k*2+1]); } void build(const vector<Monoid> &vec) { for (int a = 0; a < vec.size() && a + offset < dat.size(); ++a) set(a, vec[a]); build(); } // update a, a is 0-indexed, O(log N) void update(int a, const Monoid &v) { int k = a + offset; dat[k] = v; while (k >>= 1) dat[k] = F(dat[k*2], dat[k*2+1]); } // get [a, b), a and b are 0-indexed, O(log N) Monoid get(int a, int b) { Monoid vleft = IDENTITY, vright = IDENTITY; for (int left = a + offset, right = b + offset; left < right; left >>= 1, right >>= 1) { if (left & 1) vleft = F(vleft, dat[left++]); if (right & 1) vright = F(dat[--right], vright); } return F(vleft, vright); } Monoid get_all() { return dat[1]; } Monoid operator [] (int a) const { return dat[a + offset]; } // get max r that f(get(l, r)) = True (0-indexed), O(log N) // f(IDENTITY) need to be True int max_right(const function<bool(Monoid)> f, int l = 0) { if (l == SIZE) return SIZE; l += offset; Monoid sum = IDENTITY; do { while (l % 2 == 0) l >>= 1; if (!f(F(sum, dat[l]))) { while (l < offset) { l = l * 2; if (f(F(sum, dat[l]))) { sum = F(sum, dat[l]); ++l; } } return l - offset; } sum = F(sum, dat[l]); ++l; } while ((l & -l) != l); // stop if l = 2^e return SIZE; } // get min l that f(get(l, r)) = True (0-indexed), O(log N) // f(IDENTITY) need to be True int min_left(const function<bool(Monoid)> f, int r = -1) { if (r == 0) return 0; if (r == -1) r = SIZE; r += offset; Monoid sum = IDENTITY; do { --r; while (r > 1 && (r % 2)) r >>= 1; if (!f(F(dat[r], sum))) { while (r < offset) { r = r * 2 + 1; if (f(F(dat[r], sum))) { sum = F(dat[r], sum); --r; } } return r + 1 - offset; } sum = F(dat[r], sum); } while ((r & -r) != r); return 0; } // debug friend ostream& operator << (ostream &s, const SegTree &seg) { for (int i = 0; i < seg.size(); ++i) { s << seg[i]; if (i != seg.size()-1) s << " "; } return s; } }; signed main(){ std::cin.tie(0)->sync_with_stdio(0); ll n; std::cin >> n; vector<ll> a(n); vector<vector<ll>> p(n);//,p10(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; } for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) { if(a[i]+1==a[j]){ p[i].push_back(j); } } } ll ans = 0; vector<ll> sum(n+1); ll summ = 0; for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) { summ -= sum[j]; sum[j]=0; if(a[i]+10==a[j]){ ans += summ; } for (auto e : p[j]) { if(a[j]>=a[i]+11){ sum[e]++; summ++; } } } } std::cout << ans << std::endl; }