結果

問題 No.1734 Decreasing Elements
ユーザー milanis48663220milanis48663220
提出日時 2021-11-05 22:50:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,439 bytes
コンパイル時間 1,603 ms
コンパイル使用メモリ 136,476 KB
実行使用メモリ 10,808 KB
最終ジャッジ日時 2024-04-24 06:47:05
合計ジャッジ時間 4,757 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,040 KB
testcase_01 AC 4 ms
7,168 KB
testcase_02 AC 4 ms
7,040 KB
testcase_03 AC 4 ms
7,040 KB
testcase_04 AC 4 ms
7,040 KB
testcase_05 AC 5 ms
7,040 KB
testcase_06 AC 4 ms
7,040 KB
testcase_07 AC 77 ms
9,992 KB
testcase_08 AC 74 ms
9,452 KB
testcase_09 AC 74 ms
9,436 KB
testcase_10 AC 75 ms
9,704 KB
testcase_11 AC 88 ms
10,168 KB
testcase_12 AC 57 ms
8,844 KB
testcase_13 AC 81 ms
9,564 KB
testcase_14 WA -
testcase_15 AC 93 ms
9,836 KB
testcase_16 WA -
testcase_17 AC 107 ms
10,384 KB
testcase_18 AC 108 ms
10,252 KB
testcase_19 AC 125 ms
10,124 KB
testcase_20 WA -
testcase_21 AC 97 ms
10,256 KB
testcase_22 AC 113 ms
10,636 KB
testcase_23 WA -
testcase_24 AC 124 ms
9,996 KB
testcase_25 WA -
testcase_26 AC 109 ms
10,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 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];
    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, 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;
}
0