結果
問題 | No.1099 Range Square Sum |
ユーザー |
👑 ![]() |
提出日時 | 2020-10-04 15:04:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,271 ms / 2,000 ms |
コード長 | 1,701 bytes |
コンパイル時間 | 1,692 ms |
コンパイル使用メモリ | 178,520 KB |
実行使用メモリ | 70,400 KB |
最終ジャッジ日時 | 2024-07-19 16:02:23 |
合計ジャッジ時間 | 16,325 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 30 |
ソースコード
#include<bits/stdc++.h>using namespace std;using LL = long long;using ULL = unsigned long long;#define rep(i,n) for(int i=0; i<(n); i++)struct S { LL m[4][4] = {}; };S f(S a, S b) { S res; rep(i, 4)rep(j, 4)rep(k, 4)res.m[i][j] += a.m[i][k] * b.m[k][j]; return res; }S multi(LL x, LL a) { return S{ {{1,x,x * x,0},{0,1,2*x,0},{0,0,1,a},{0,0,0,1}} }; }struct segtree {int N;vector<S> V;S I;segtree(int n) {N = 1; while (N < n) N *= 2;V.resize(N * 2);rep(i, 4) I.m[i][i] = 1;}void upd(int p, S v) {p += N; V[p] = v;while (p != 1) {p /= 2;V[p] = f(V[p * 2], V[p * 2 + 1]);}}S get(int l, int r, int a = 0, int b = 0, int i = -1) {if (i == -1) { a = 0; b = N; i = 1; }if (r <= a || b <= l)return I;if (l <= a && b <= r)return V[i];return f(get(l, r, a, (a + b) / 2, i * 2), get(l, r, (a + b) / 2, b, i * 2 + 1));}};int main() {int N; cin >> N;LL A[200000]; rep(i, N) cin >> A[i];segtree G(N + 1);G.upd(0, multi(A[0], 0));rep(i, N - 1) { G.upd(i + 1, multi(A[i+1] - A[i], 1)); }G.upd(N, multi(0, 1));int Q; cin >> Q;rep(i, Q) {int c; cin >> c;if (c == 1) {int l, r; LL x; cin >> l >> r >> x;G.upd(l - 1, f(G.get(l - 1, l), multi(x, 0)));G.upd(r, f(G.get(r, r + 1), multi(-x, 0)));}else if (c == 2) {int l, r; cin >> l >> r;auto R = G.get(0, r + 1);auto L = G.get(0, l);cout << G.get(0, r + 1).m[0][3] - G.get(0, l).m[0][3] << endl;}}return 0;}