結果
問題 | No.1435 Mmm...... |
ユーザー | yuto1115 |
提出日時 | 2020-10-22 18:01:42 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 371 ms / 2,000 ms |
コード長 | 4,173 bytes |
コンパイル時間 | 2,261 ms |
コンパイル使用メモリ | 210,632 KB |
実行使用メモリ | 14,848 KB |
最終ジャッジ日時 | 2024-07-21 09:25:37 |
合計ジャッジ時間 | 8,880 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 180 ms
12,928 KB |
testcase_07 | AC | 232 ms
13,696 KB |
testcase_08 | AC | 267 ms
14,592 KB |
testcase_09 | AC | 243 ms
14,208 KB |
testcase_10 | AC | 209 ms
13,568 KB |
testcase_11 | AC | 203 ms
13,440 KB |
testcase_12 | AC | 187 ms
13,184 KB |
testcase_13 | AC | 184 ms
13,056 KB |
testcase_14 | AC | 133 ms
8,960 KB |
testcase_15 | AC | 277 ms
14,720 KB |
testcase_16 | AC | 224 ms
13,824 KB |
testcase_17 | AC | 151 ms
9,344 KB |
testcase_18 | AC | 280 ms
14,848 KB |
testcase_19 | AC | 199 ms
13,312 KB |
testcase_20 | AC | 252 ms
14,208 KB |
testcase_21 | AC | 371 ms
14,720 KB |
testcase_22 | AC | 358 ms
14,848 KB |
testcase_23 | AC | 290 ms
14,848 KB |
testcase_24 | AC | 296 ms
14,848 KB |
testcase_25 | AC | 293 ms
14,848 KB |
testcase_26 | AC | 290 ms
14,720 KB |
testcase_27 | AC | 291 ms
14,848 KB |
ソースコード
//@formatter:off #include<bits/stdc++.h> #define rep(i,n) for (int i = 0; i < int(n); ++i) #define rrep(i,n) for (int i = int(n)-1; i >= 0; i--) #define rep2(i,s,n) for (int i = int(s); i < int(n); ++i) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define pb push_back #define eb emplace_back #define vi vector<int> #define vvi vector<vector<int>> #define vl vector<ll> #define vvl vector<vector<ll>> #define vd vector<double> #define vvd vector<vector<double>> #define vs vector<string> #define vc vector<char> #define vvc vector<vector<char>> #define vb vector<bool> #define vvb vector<vector<bool>> #define vp vector<P> #define vvp vector<vector<P>> using namespace std; using ll = long long; using P = pair<int,int>; using LP = pair<ll,ll>; template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; } template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; } template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; } template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; } void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; } void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; } template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;} template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;} const int inf = 1001001001; const ll linf = 1001001001001001001; //@formatter:on template<class Monoid> class segtree { using T = typename Monoid::value_type; int n; vector <T> val; public: constexpr segtree(int _n) { n = 1; while (n < _n) n *= 2; val = vector<T>(2 * n, Monoid::identity); } constexpr segtree(vector <T> init) { int _n = init.size(); n = 1; while (n < _n) n *= 2; val = vector<T>(2 * n, Monoid::identity); rep(i, _n) val[i + n] = init[i]; rrep(i, n) val[i] = Monoid::operate(val[i * 2], val[i * 2 + 1]); } // segment [l,r) T fold(int l, int r) { l += n, r += n; T fold_l = Monoid::identity; T fold_r = Monoid::identity; while (l < r) { if (l & 1) fold_l = Monoid::operate(fold_l, val[l++]); if (r & 1) fold_r = Monoid::operate(val[--r], fold_r); l >>= 1, r >>= 1; } return Monoid::operate(fold_l, fold_r); } template<class F> void update(int i, const F &f) { i += n; val[i] = f(val[i]); while (i > 1) { i >>= 1; val[i] = Monoid::operate(val[i * 2], val[i * 2 + 1]); } } }; class Node { public: // min, second_min, max using value_type = tuple<int, int, int>; value_type value; Node(value_type value) : value(value) {} static constexpr value_type identity = {inf, inf, 0}; static constexpr value_type operate(const value_type &l, const value_type &r) { auto[lm, ls, lM] = l; auto[rm, rs, rM] = r; int m = 0, s = 0, M = 0; if (lm > rm) { m = rm; s = min(lm, rs); M = max(lM, rM); } else { m = lm; s = min(ls, rm); M = max(lM, rM); } return make_tuple(m, s, M); } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; vi p(n); cin >> p; vector <tuple<int, int, int>> init(n); rep(i, n) init[i] = make_tuple(p[i], inf, p[i]); segtree<Node> st(init); ll ans = 0; rep(l, n - 1) { int ok = l + 1, ng = n; auto f = [&](int x) -> bool { auto t = st.fold(l, x + 1); auto[m, s, M] = t; return M <= m + s; }; while (abs(ok - ng) > 1) { int mid = (ng + ok) / 2; if (f(mid)) ok = mid; else ng = mid; } ans += ok - l; } cout << ans << endl; }