結果

問題 No.1441 MErGe
ユーザー SSRSSSRS
提出日時 2021-03-26 21:45:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,486 bytes
コンパイル時間 1,981 ms
コンパイル使用メモリ 174,272 KB
実行使用メモリ 22,824 KB
最終ジャッジ日時 2024-05-06 15:09:09
合計ジャッジ時間 29,077 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 5 ms
6,940 KB
testcase_04 AC 5 ms
6,944 KB
testcase_05 AC 21 ms
6,944 KB
testcase_06 AC 21 ms
6,944 KB
testcase_07 AC 21 ms
6,940 KB
testcase_08 AC 300 ms
7,936 KB
testcase_09 AC 297 ms
8,064 KB
testcase_10 AC 545 ms
7,936 KB
testcase_11 AC 479 ms
6,940 KB
testcase_12 AC 555 ms
8,064 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 AC 985 ms
21,736 KB
testcase_19 TLE -
testcase_20 AC 870 ms
21,728 KB
testcase_21 AC 782 ms
13,184 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000;
template <typename T>
struct lazy_segment_tree{
	int N;
	vector<T> ST;
	vector<T> lazy;
	lazy_segment_tree(vector<T> &A){
		int n = A.size();
		N = 1;
		while (N < n){
			N *= 2;
		}
		ST = vector<T>(N * 2 - 1, 0);
		lazy = vector<T>(N * 2 - 1, INF);
		for (int i = 0; i < n; i++){
			ST[N - 1 + i] = A[i];
		}
		for (int i = N - 2; i >= 0; i--){
			ST[i] = ST[i * 2 + 1] + ST[i * 2 + 2];
		}
	}
	void eval(int i, int l, int r){
		if (lazy[i] != INF){
			if (i < N - 1){
				lazy[i * 2 + 1] = lazy[i];
				lazy[i * 2 + 2] = lazy[i];
			}
			ST[i] = lazy[i] * (r - l);
			lazy[i] = INF;
		}
	}
	void range_update(int L, int R, T x, int i, int l, int r){
		eval(i, l, r);
		if (R <= l || r <= L){
			return;
		} else if (L <= l && r <= R){
			lazy[i] = x;
			eval(i, l, r);
		} else {
			int m = (l + r) / 2;
			range_update(L, R, x, i * 2 + 1, l, m);
			range_update(L, R, x, i * 2 + 2, m, r);
			ST[i] = ST[i * 2 + 1] + ST[i * 2 + 2];
		}
	}
	void range_update(int L, int R, T x){
		range_update(L, R, x, 0, 0, N);
	}
	T range_sum(int L, int R, int i, int l, int r){
		eval(i, l, r);
		if (R <= l || r <= L){
			return 0;
		} else if (L <= l && r <= R){
			return ST[i];
		} else {
			int m = (l + r) / 2;
			return range_sum(L, R, i * 2 + 1, l, m) + range_sum(L, R, i * 2 + 2, m, r);
		}
	}
	T range_sum(int L, int R){
		return range_sum(L, R, 0, 0, N);
	}
};
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, Q;
  cin >> N >> Q;
  vector<long long> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<long long> B(N, 1);
  lazy_segment_tree<long long> ST1(A), ST2(B);
  for (int i = 0; i < Q; i++){
    int T, l, r;
    cin >> T >> l >> r;
    l--;
    r--;
    int tv1 = N, fv1 = -1;
    while (tv1 - fv1 > 1){
      int mid = (tv1 + fv1) / 2;
      if (ST2.range_sum(0, mid + 1) > l){
        tv1 = mid;
      } else {
        fv1 = mid;
      }
    }
    l = tv1;
    int tv2 = N, fv2 = -1;
    while (tv2 - fv2 > 1){
      int mid = (tv2 + fv2) / 2;
      if (ST2.range_sum(0, mid + 1) > r){
        tv2 = mid;
      } else {
        fv2 = mid;
      }
    }
    r = tv2;
    if (T == 1){
      long long S = ST1.range_sum(l, r + 1);
      ST1.range_update(l, l + 1, S);
      ST1.range_update(l + 1, r + 1, 0);
      ST2.range_update(l + 1, r + 1, 0);
    }
    if (T == 2){
      long long S = ST1.range_sum(l, r + 1);
      cout << S << "\n";
    }
  }
}
0