結果
| 問題 |
No.1099 Range Square Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-02 00:04:06 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 609 ms / 2,000 ms |
| コード長 | 1,600 bytes |
| コンパイル時間 | 4,513 ms |
| コンパイル使用メモリ | 262,788 KB |
| 最終ジャッジ日時 | 2025-02-13 17:24:18 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
struct Fast
{
Fast()
{
std::cin.tie(0);
ios::sync_with_stdio(false);
}
} fast;
#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--)
#define Yn(b) cout << ((b) ? "Yes" : "No") << "\n";
#define ll long long
template <typename T>
bool chmax(T &a, const T &b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
using S = array<ll, 3>;
using F = array<ll, 9>;
S e() { return {0, 0, 0}; }
F id() { return {1, 0, 0, 0, 1, 0, 0, 0, 1}; }
S op(S x, S y)
{
S z{};
rep(i, 0, 3) z[i] = x[i] + y[i];
return z;
}
S mapping(F f, S x)
{
S y{};
rep(i, 0, 3) rep(j, 0, 3) y[i] += f[3 * i + j] * x[j];
return y;
}
F composition(F f, F g)
{
F h{};
rep(i, 0, 3) rep(j, 0, 3) rep(k, 0, 3) h[3 * i + j] += f[3 * i + k] * g[3 * k + j];
return h;
}
int main()
{
int n, q;
cin >> n;
vector<ll> a(n);
rep(i, 0, n) cin >> a[i];
cin >> q;
vector<S> b(n);
rep(i, 0, n) b[i] = {1, a[i], a[i] * a[i]};
lazy_segtree<S, op, e, F, mapping, composition, id> seg(b);
while (q--)
{
int type;
cin >> type;
if (type == 1)
{
int l, r;
ll x;
cin >> l >> r >> x;
seg.apply(l - 1, r, {1, 0, 0, x, 1, 0, x * x, 2 * x, 1});
}
if (type == 2)
{
int l, r;
cin >> l >> r;
cout << seg.prod(l - 1, r)[2] << "\n";
}
}
}