結果

問題 No.749 クエリ全部盛り
ユーザー KudeKude
提出日時 2022-06-24 00:04:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 338 ms / 3,000 ms
コード長 2,241 bytes
コンパイル時間 2,608 ms
コンパイル使用メモリ 234,564 KB
実行使用メモリ 55,932 KB
最終ジャッジ日時 2023-08-07 14:14:52
合計ジャッジ時間 5,973 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 18 ms
4,380 KB
testcase_11 AC 17 ms
4,380 KB
testcase_12 AC 18 ms
4,376 KB
testcase_13 AC 18 ms
4,376 KB
testcase_14 AC 18 ms
4,376 KB
testcase_15 AC 329 ms
55,932 KB
testcase_16 AC 331 ms
55,744 KB
testcase_17 AC 338 ms
55,660 KB
testcase_18 AC 338 ms
55,664 KB
testcase_19 AC 338 ms
55,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint1000000007;

struct S {
  int cnt;
  mint sm;
  mint f;
};
S e() { return { 0, 0, 0 }; }
S op(S x, S y) { return { x.cnt + y.cnt, x.sm + y.sm, x.f + y.f }; }

struct F {
  int assign;
  // ax + bF + c
  mint a, b, c;
};
F id() { return { -1, 1, 0, 0}; }
F composition(F f, F g) {
  if (f.assign != -1) return f;
  // fa (ga x + gb F + gc) + fb F + fc
  // fa ga x + (fa gb + fb) F + fa gc + fc
  return { g.assign, f.a * g.a, f.a * g.b + f.b, f.a * g.c + f.c };
}

S mapping(F f, S x) {
  if (f.assign != -1) x.sm = mint::raw(x.cnt) * f.assign;
  x.sm = f.a * x.sm + f.b * x.f + f.c * x.cnt;
  return x;
}

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<S> init_vec(n, {1, 0, 0});
  init_vec[0].f = 0;
  if (n > 1) {
    init_vec[1].f = 1;
    for(int i = 2; i < n; i++) init_vec[i].f = init_vec[i-2].f + init_vec[i-1].f;
  }
  lazy_segtree<S, op, e, F, mapping, composition, id> seg(init_vec);
  while(q--) {
    int q, l, r, k;
    cin >> q >> l >> r >> k;
    r++;
    switch(q) {
      case 0: {
        mint ans = k * seg.prod(l, r).sm;
        cout << ans.val() << '\n';
        break;
      }
      case 1: {
        seg.apply(l, r, { k, 1, 0, 0 });
        break;
      }
      case 2: {
        seg.apply(l, r, { -1, 1, 0, k });
        break;
      }
      case 3: {
        seg.apply(l, r, { -1, k, 0, 0 });
        break;
      }
      case 4: {
        seg.apply(l, r, { -1, 1, k, 0 });
        break;
      }
    }
  }
}
0