結果

問題 No.1734 Decreasing Elements
ユーザー SSRSSSRS
提出日時 2021-11-05 22:16:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 147 ms / 3,000 ms
コード長 1,673 bytes
コンパイル時間 2,067 ms
コンパイル使用メモリ 175,772 KB
実行使用メモリ 11,508 KB
最終ジャッジ日時 2024-04-24 06:04:37
合計ジャッジ時間 5,290 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,816 KB
testcase_01 AC 5 ms
6,912 KB
testcase_02 AC 4 ms
6,784 KB
testcase_03 AC 5 ms
6,784 KB
testcase_04 AC 5 ms
6,912 KB
testcase_05 AC 5 ms
6,784 KB
testcase_06 AC 4 ms
6,784 KB
testcase_07 AC 59 ms
10,296 KB
testcase_08 AC 61 ms
9,608 KB
testcase_09 AC 62 ms
9,692 KB
testcase_10 AC 62 ms
10,040 KB
testcase_11 AC 80 ms
10,756 KB
testcase_12 AC 54 ms
9,416 KB
testcase_13 AC 81 ms
9,860 KB
testcase_14 AC 117 ms
11,412 KB
testcase_15 AC 94 ms
10,224 KB
testcase_16 AC 119 ms
10,512 KB
testcase_17 AC 120 ms
10,732 KB
testcase_18 AC 119 ms
10,728 KB
testcase_19 AC 139 ms
10,100 KB
testcase_20 AC 147 ms
10,356 KB
testcase_21 AC 111 ms
10,480 KB
testcase_22 AC 122 ms
11,508 KB
testcase_23 AC 136 ms
10,096 KB
testcase_24 AC 136 ms
10,096 KB
testcase_25 AC 127 ms
10,580 KB
testcase_26 AC 128 ms
10,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct dual_segment_tree{
	int N;
	vector<T> ST;
	dual_segment_tree(vector<T> A){
		int n = A.size();
		N = 1;
		while (N < n){
			N *= 2;
		}
		ST = vector<T>(N * 2 - 1, 0);
		for (int i = 0; i < n; i++){
			ST[N - 1 + i] = A[i];
		}
	}
	T operator [](int k){
		k += N - 1;
		T ans = ST[k];
		while (k > 0){
			k = (k - 1) / 2;
			ans += ST[k];
		}
		return ans;
	}
	void range_add(int L, int R, T x, int i, int l, int r){
		if (R <= l || r <= L){
			return;
		} else if (L <= l && r <= R){
			ST[i] += x;
			return;
		} else {
			int m = (l + r) / 2;
			range_add(L, R, x, i * 2 + 1, l, m);
			range_add(L, R, x, i * 2 + 2, m, r);
			return;
		}
	}
	void range_add(int L, int R, T x){
		range_add(L, R, x, 0, 0, N);
	}
	void all_add(T x){
		ST[0] += x;
	}
};
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<int> B(200001);
  for (int i = 0; i <= 200000; i++){
    B[i] = i;
  }
  dual_segment_tree<int> ST(B);
  priority_queue<tuple<int, int, int>> pq;
  pq.push(make_tuple(200001, 0, 200001));
  int ans = 0;
  for (int i = 0; i < N; i++){
    if (ST[A[i]] > 0){
      ans++;
      int c = ST[A[i]];
      vector<tuple<int, int, int>> tmp;
      while (get<0>(pq.top()) > c){
        int L = get<1>(pq.top());
        int R = get<2>(pq.top());
        pq.pop();
        pq.push(make_tuple(c, L, L + c));
        tmp.push_back(make_tuple(R - L - c, L + c, R));
        ST.range_add(L + c, R, -c);
      }
      int cnt = tmp.size();
      for (int j = 0; j < cnt; j++){
        pq.push(tmp[j]);
      }
    }
  }
  cout << ans << endl;
}
0