結果
問題 | No.1734 Decreasing Elements |
ユーザー |
![]() |
提出日時 | 2021-11-05 23:00:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 141 ms / 3,000 ms |
コード長 | 2,808 bytes |
コンパイル時間 | 1,398 ms |
コンパイル使用メモリ | 132,080 KB |
最終ジャッジ日時 | 2025-01-25 13:40:15 |
ジャッジサーバーID (参考情報) |
judge6 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#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;}