結果
| 問題 |
No.749 クエリ全部盛り
|
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2022-06-24 00:04:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 364 ms / 3,000 ms |
| コード長 | 2,241 bytes |
| コンパイル時間 | 2,622 ms |
| コンパイル使用メモリ | 226,880 KB |
| 最終ジャッジ日時 | 2025-01-29 23:47:47 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
#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;
}
}
}
}
Kude