結果

問題 No.749 クエリ全部盛り
ユーザー kwm_tkwm_t
提出日時 2023-04-03 21:49:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 354 ms / 3,000 ms
コード長 2,242 bytes
コンパイル時間 5,299 ms
コンパイル使用メモリ 270,936 KB
実行使用メモリ 56,040 KB
最終ジャッジ日時 2023-10-25 07:38:32
合計ジャッジ時間 8,356 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 19 ms
4,348 KB
testcase_11 AC 19 ms
4,348 KB
testcase_12 AC 19 ms
4,348 KB
testcase_13 AC 19 ms
4,348 KB
testcase_14 AC 18 ms
4,348 KB
testcase_15 AC 354 ms
56,040 KB
testcase_16 AC 346 ms
56,040 KB
testcase_17 AC 351 ms
56,040 KB
testcase_18 AC 348 ms
56,040 KB
testcase_19 AC 353 ms
56,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
//★自分で編集
//data
struct S {
	mint size;		//区間の幅
	mint sum;		//実際の値
	mint fib;		//fib
};
//S*S->S
S op(S sl, S sr) { return S{ sl.size + sr.size,sl.sum + sr.sum, sl.fib + sr.fib }; }
//op(a,e) = a = op(e,a)なeを返す
S e() { return S{ 0,0, 0 }; }

//lazy
struct F {
	int assign;
	mint a, b, c;
};
//mapping(id,a) = aなidを返す
F id() { return F{ -1,1,0,0 }; }
//f(x)を返す関数
S mapping(F f, S s) {
	if (-1 != f.assign) s.sum = s.size * f.assign;
	s.sum = f.a * s.sum + f.b*s.fib + f.c * s.size;
	return s;
}
//f(g(x))の合成関数
//c(ax+b)+d = acx+(bc+d)
//gが先
F composition(F f, F g) {
	if (-1 != f.assign)return f;
	return F{ g.assign,f.a * g.a,f.a * g.b + f.b,f.a * g.c + f.c };
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, q; cin >> n >> q;
	vector<S> a(n, { 1, 0, 0 });
	a[0].fib = 0;
	if (n > 1) {
		a[1].fib = 1;
		rep2(i, 2, n) a[i].fib = a[i - 2].fib + a[i - 1].fib;
	}
	lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);
	while (q--) {
		int t, l, r, k;
		cin >> t >> l >> r >> k;
		r++;
		if (0 == t) {
			mint ans = seg.prod(l, r).sum * k;
			cout << ans.val() << endl;
		}
		else if (1 == t) {
			seg.apply(l, r, { k,1,0,0 });
		}
		else if (2 == t) {
			seg.apply(l, r, { -1, 1, 0, k });
		}
		else if (3 == t) {
			seg.apply(l, r, { -1, k, 0, 0 });
		}
		else {
			seg.apply(l, r, { -1, 1, k, 0 });
		}
	}
	return 0;
}
0