結果

問題 No.1099 Range Square Sum
ユーザー KumaTachiRenKumaTachiRen
提出日時 2023-06-02 00:04:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 665 ms / 2,000 ms
コード長 1,600 bytes
コンパイル時間 4,646 ms
コンパイル使用メモリ 270,500 KB
実行使用メモリ 40,216 KB
最終ジャッジ日時 2023-08-28 02:13:23
合計ジャッジ時間 14,314 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 657 ms
40,004 KB
testcase_22 AC 657 ms
40,148 KB
testcase_23 AC 660 ms
40,108 KB
testcase_24 AC 665 ms
40,056 KB
testcase_25 AC 657 ms
40,100 KB
testcase_26 AC 497 ms
40,216 KB
testcase_27 AC 496 ms
40,156 KB
testcase_28 AC 494 ms
40,076 KB
testcase_29 AC 495 ms
40,004 KB
testcase_30 AC 497 ms
40,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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";
    }
  }
}
0