結果

問題 No.1734 Decreasing Elements
ユーザー chocoruskchocorusk
提出日時 2021-11-05 23:16:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 213 ms / 3,000 ms
コード長 2,165 bytes
コンパイル時間 3,266 ms
コンパイル使用メモリ 191,972 KB
実行使用メモリ 23,296 KB
最終ジャッジ日時 2024-04-24 07:16:39
合計ジャッジ時間 7,940 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
8,832 KB
testcase_01 AC 9 ms
8,704 KB
testcase_02 AC 10 ms
8,704 KB
testcase_03 AC 10 ms
8,704 KB
testcase_04 AC 9 ms
8,960 KB
testcase_05 AC 9 ms
8,832 KB
testcase_06 AC 9 ms
8,704 KB
testcase_07 AC 149 ms
19,072 KB
testcase_08 AC 149 ms
19,072 KB
testcase_09 AC 154 ms
19,200 KB
testcase_10 AC 162 ms
23,040 KB
testcase_11 AC 173 ms
19,840 KB
testcase_12 AC 110 ms
16,768 KB
testcase_13 AC 165 ms
20,224 KB
testcase_14 AC 210 ms
21,888 KB
testcase_15 AC 190 ms
20,096 KB
testcase_16 AC 213 ms
19,712 KB
testcase_17 AC 211 ms
18,944 KB
testcase_18 AC 209 ms
20,480 KB
testcase_19 AC 162 ms
18,816 KB
testcase_20 AC 156 ms
18,944 KB
testcase_21 AC 144 ms
17,920 KB
testcase_22 AC 173 ms
22,272 KB
testcase_23 AC 169 ms
18,944 KB
testcase_24 AC 194 ms
18,944 KB
testcase_25 AC 209 ms
23,296 KB
testcase_26 AC 208 ms
23,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
using mint=modint998244353;
template<typename T>
struct BIT{
    vector<T> bit;
    int size;
    BIT(int n):size(n), bit(n+1, 0){}
    T sum(int i){ //[0, i)
        T s=0;
        while(i>0){
            s+=bit[i];
            i-=(i&(-i));
        }
        return s;
    }
    T sum(int l, int r){ //[l, r)
        return sum(r)-sum(l);
    }
    void add(int i, T x){
		i++;
        while(i<=size){
            bit[i]+=x;
            i+=(i&(-i));
        }
    }
};
template<typename T>
struct RangeAddPointGet{
	BIT<T> bit;
	RangeAddPointGet(int n):bit(n){}
	void add(int l, int r, T x){
		bit.add(l, x);
		bit.add(r, -x);	
	}
	T get(int i){
		return bit.sum(i+1);
	}
};
const int MAX=200000;
int n;
int a[200020];
int p[200020];
int mn[200020];
vector<int> v[200020];

int main()
{
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    set<P> st;
    st.insert({MAX, 0});
    RangeAddPointGet<int> seg(MAX+1);
    for(int i=1; i<=MAX; i++) seg.add(i, i+1, i);
    int ans=0;
    for(int i=0; i<n; i++){
        int v=seg.get(a[i]);
        if(v==0) continue;
        ans++;
        auto itr=st.lower_bound({v, 0});
        set<P> st1;
        for(; itr!=st.end(); ){
            int k=itr->second;
            int x=itr->first;
            seg.add(k+v, k+x+1, -v);
            st1.insert({v-1, k});
            st1.insert({x-v, k+v});
            itr=st.erase(itr);
        }
        for(auto p:st1) st.insert(p);
        // cout<<i<<endl;
        // for(auto p:st)cout<<p.first<<" "<<p.second<<endl;
    }
    cout<<ans<<endl;
    return 0;
}
0