結果
問題 | No.1734 Decreasing Elements |
ユーザー | milanis48663220 |
提出日時 | 2021-11-05 23:00:00 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 125 ms / 3,000 ms |
コード長 | 2,808 bytes |
コンパイル時間 | 1,355 ms |
コンパイル使用メモリ | 135,912 KB |
実行使用メモリ | 10,812 KB |
最終ジャッジ日時 | 2024-04-24 06:58:57 |
合計ジャッジ時間 | 4,431 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
7,168 KB |
testcase_01 | AC | 4 ms
7,040 KB |
testcase_02 | AC | 4 ms
7,148 KB |
testcase_03 | AC | 5 ms
7,168 KB |
testcase_04 | AC | 5 ms
7,040 KB |
testcase_05 | AC | 5 ms
7,040 KB |
testcase_06 | AC | 5 ms
7,040 KB |
testcase_07 | AC | 76 ms
9,996 KB |
testcase_08 | AC | 75 ms
9,328 KB |
testcase_09 | AC | 76 ms
9,436 KB |
testcase_10 | AC | 76 ms
9,832 KB |
testcase_11 | AC | 84 ms
10,324 KB |
testcase_12 | AC | 56 ms
8,736 KB |
testcase_13 | AC | 85 ms
9,696 KB |
testcase_14 | AC | 103 ms
10,812 KB |
testcase_15 | AC | 92 ms
9,836 KB |
testcase_16 | AC | 107 ms
10,060 KB |
testcase_17 | AC | 106 ms
10,636 KB |
testcase_18 | AC | 108 ms
10,252 KB |
testcase_19 | AC | 125 ms
10,252 KB |
testcase_20 | AC | 125 ms
10,124 KB |
testcase_21 | AC | 91 ms
10,252 KB |
testcase_22 | AC | 99 ms
10,636 KB |
testcase_23 | AC | 125 ms
10,124 KB |
testcase_24 | AC | 121 ms
10,124 KB |
testcase_25 | AC | 111 ms
10,380 KB |
testcase_26 | AC | 115 ms
10,376 KB |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #include <random> #include <atcoder/lazysegtree> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } vector<int> gen_array(int n, int l, int r){ int d = r-l; random_device rnd; mt19937 mt(rnd()); vector<int> ans(n); int x = mt(); for(int i = 0; i < n; i++) ans[i] = l+(mt()%d); return ans; } const int MX = 200000; using P = pair<int, int>; int e() { return 0; } int add(int l, int r) { return l+r; } int id() { return 0; } int naive(vector<int> a){ int n = a.size(); int ans = 0; for(int i = 0; i < n; i++){ if(a[i] == 0) continue; for(int j = i+1; j < n; j++){ if(a[j] >= a[i]) a[j] -= a[i]; } a[i] = 0; ans++; } return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector<int> a(n); for(int i = 0; i < n; i++) cin >> a[i]; // a = gen_array(n, 0, 10); // print_vector(a); // cout << naive(a) << endl; vector<int> v(MX+1); for(int i = 0; i <= MX; i++) v[i] = i; atcoder::lazy_segtree<int, add, e, int, add, add, id> sgt(v); priority_queue<P> que; que.push(P(MX+1, 0)); int ans = 0; for(int i = 0; i < n; i++){ int x = sgt.get(a[i]); if(x == 0) continue; ans++; vector<P> p; while(!que.empty() && que.top().first >= x+1){ p.push_back(que.top()); que.pop(); } // debug_value(p.size()); for(auto [len, l]: p){ que.push(P(x, l)); que.push(P(len-x, l+x)); sgt.apply(l+x, l+len, -x); } } cout << ans << endl; }