結果

問題 No.255 Splarrraaay スプラーレェーーイ
ユーザー SSRSSSRS
提出日時 2022-01-07 08:01:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,542 bytes
コンパイル時間 3,373 ms
コンパイル使用メモリ 186,208 KB
実行使用メモリ 68,420 KB
最終ジャッジ日時 2024-11-08 15:52:33
合計ジャッジ時間 10,460 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 618 ms
68,416 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000000000000009;
struct lazy_segment_tree{
  int N;
  vector<long long> sz;
  vector<array<long long, 5>> sum;
  vector<int> lazy_color, lazy_cnt;
  lazy_segment_tree(vector<long long> &A){
    int N2 = A.size();
    N = 1;
    while (N < N2){
      N *= 2;
    }
    sz = vector<long long>(N * 2 - 1, 0);
    for (int i = 0; i < N2; i++){
      sz[N - 1 + i] = A[i];
    }
    for (int i = N - 2; i >= 0; i--){
      sz[i] = sz[i * 2 + 1] + sz[i * 2 + 2];
    }
    sum = vector<array<long long, 5>>(N * 2 - 1);
    for (int i = 0; i < N * 2 - 1; i++){
      for (int j = 0; j < 5; j++){
        sum[i][j] = 0;
      }
    }
    lazy_color = vector<int>(N * 2 - 1, -1);
    lazy_cnt = vector<int>(N * 2 - 1, 0);
  }
  void push(int i){
    if (lazy_color[i] != -1){
      if (i < N - 1){
        if (lazy_color[i * 2 + 1] != lazy_color[i]){
          lazy_color[i * 2 + 1] = lazy_color[i];
          lazy_cnt[i * 2 + 1] = 0;
        }
        lazy_cnt[i * 2 + 1] += lazy_cnt[i];
        if (lazy_color[i * 2 + 2] != lazy_color[i]){
          lazy_color[i * 2 + 2] = lazy_color[i];
          lazy_cnt[i * 2 + 2] = 0;
        }
        lazy_cnt[i * 2 + 2] += lazy_cnt[i];
      }
      sum[i][lazy_color[i]] += sz[i] * lazy_cnt[i];
      for (int j = 0; j < 5; j++){
        if (j != lazy_color[i]){
          sum[i][j] = 0;
        }
      }
      lazy_color[i] = -1;
      lazy_cnt[i] = 0;
    }
  }
  void range_apply(int L, int R, int x, int i, int l, int r){
    push(i);
    if (r <= L || R <= l){
    } else if (L <= l && r <= R){
      lazy_color[i] = x;
      lazy_cnt[i] = 1;
      push(i);
    } else {
      int m = (l + r) / 2;
      range_apply(L, R, x, i * 2 + 1, l, m);
      range_apply(L, R, x, i * 2 + 2, m, r);
      for (int j = 0; j < 5; j++){
        sum[i][j] = sum[i * 2 + 1][j] + sum[i * 2 + 2][j];
      }
    }
  }
  void range_apply(int L, int R, int x){
    range_apply(L, R, x, 0, 0, N);
  }
  array<long long, 5> range_sum(int L, int R, int i, int l, int r){
    push(i);
    if (r <= L || R <= l){
      array<long long, 5> res;
      for (int j = 0; j < 5; j++){
        res[j] = 0;
      }
      return res;
    } else if (L <= l && r <= R){
      return sum[i];
    } else {
      int m = (l + r) / 2;
      array<long long, 5> A = range_sum(L, R, i * 2 + 1, l, m);
      array<long long, 5> B = range_sum(L, R, i * 2 + 2, m, r);
      for (int j = 0; j < 5; j++){
        A[j] += B[j];
      }
      return A;
    }
  }
  array<long long, 5> range_sum(int L, int R){
    return range_sum(L, R, 0, 0, N);
  }
  array<long long, 5> all_sum(){
    push(0);
    return sum[0];
  }
};
int main(){
  long long N;
  cin >> N;
  int Q;
  cin >> Q;
  vector<int> x(Q);
  vector<long long> l(Q), r(Q);
  for (int i = 0; i < Q; i++){
    cin >> x[i] >> l[i] >> r[i];
    r[i]++;
  }
  vector<long long> X;
  X.push_back(0);
  X.push_back(N);
  for (int i = 0; i < Q; i++){
    X.push_back(l[i]);
    X.push_back(r[i]);
  }
  sort(X.begin(), X.end());
  X.erase(unique(X.begin(), X.end()), X.end());
  int cnt = X.size();
  for (int i = 0; i < Q; i++){
    l[i] = lower_bound(X.begin(), X.end(), l[i]) - X.begin();
    r[i] = lower_bound(X.begin(), X.end(), r[i]) - X.begin();
  }
  vector<long long> w(cnt - 1);
  for (int i = 0; i < cnt - 1; i++){
    w[i] = X[i + 1] - X[i];
  }
  lazy_segment_tree ST(w);
  array<long long, 5> sum;
  for (int i = 0; i < 5; i++){
    sum[i] = 0;
  }
  for (int i = 0; i < Q; i++){
    if (x[i] == 0){
      array<long long, 5> res = ST.range_sum(l[i], r[i]);
      long long mx = 0;
      for (int j = 0; j < 5; j++){
        mx = max(mx, res[j]);
      }
      int mxcnt = 0;
      for (int j = 0; j < 5; j++){
        if (res[j] == mx){
          mxcnt++;
        }
      }
      if (mxcnt == 1){
        for (int j = 0; j < 5; j++){
          if (res[j] == mx){
            sum[j] += res[j];
            sum[j] %= MOD;
          }
        }
      }
    }
    if (x[i] == 1){
      ST.range_apply(l[i], r[i], 0);
    }
    if (x[i] == 2){ 
      ST.range_apply(l[i], r[i], 1);
    }
    if (x[i] == 3){
      ST.range_apply(l[i], r[i], 2);
    }
    if (x[i] == 4){
      ST.range_apply(l[i], r[i], 3);
    }
    if (x[i] == 5){
      ST.range_apply(l[i], r[i], 4);
    }
  }
  array<long long, 5> res = ST.all_sum();
  for (int i = 0; i < 5; i++){
    sum[i] += res[i];
    sum[i] %= MOD;
  }
  for (int i = 0; i < 5; i++){
    cout << sum[i];
    if (i < 4){
      cout << ' ';
    }
  }
  cout << endl;
}
0