結果
| 問題 | No.3411 Range Clamp Sum |
| コンテスト | |
| ユーザー |
detteiuu
|
| 提出日時 | 2025-12-18 03:49:48 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2,817 ms / 10,000 ms |
| コード長 | 3,207 bytes |
| 記録 | |
| コンパイル時間 | 5,782 ms |
| コンパイル使用メモリ | 335,676 KB |
| 実行使用メモリ | 501,068 KB |
| 最終ジャッジ日時 | 2025-12-18 03:50:34 |
| 合計ジャッジ時間 | 43,561 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 |
ソースコード
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#define pass (void)0
#define INF (1<<30)-1
#define INFLL (1LL<<60)-1
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define repr2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define YesNo(cond) cout << ((cond) ? "Yes\n" : "No\n")
#define YESNO(cond) cout << ((cond) ? "YES\n" : "NO\n")
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
template <typename T> void print(const T& value) { cout << value << "\n"; }
template <typename T> void print(const vector<T>& vec) { for (auto& v : vec) cout << v << " "; cout << "\n"; }
template <typename T> void input(vector<T>& vec) { for (auto& v : vec) cin >> v; };
template <typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using vm = vector<mint>;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(10);
int N, Q;
cin >> N >> Q;
vl A(N);
input(A);
int route = (int)sqrt(N);
int len = N/route+1;
vector<fenwick_tree<ll>> F(len, fenwick_tree<ll> (100001));
vector<fenwick_tree<ll>> C(len, fenwick_tree<ll> (100001));
rep (i, N) {
F[i/route].add(A[i], A[i]);
C[i/route].add(A[i], 1);
}
rep (i, Q) {
int t;
cin >> t;
if (t == 1) {
ll x, y;
cin >> x >> y;
x --;
F[x/route].add(A[x], -A[x]);
C[x/route].add(A[x], -1);
A[x] = y;
F[x/route].add(A[x], A[x]);
C[x/route].add(A[x], 1);
} else {
int l, r;
cin >> l >> r;
ll a, b;
cin >> a >> b;
l --;
if (l/route == r/route) {
ll ans = 0;
rep2 (j, l, r) {
ans += max(a, min(b, A[j]));
}
print(ans);
continue;
}
ll ans = 0;
while (l%route != 0) {
ans += max(a, min(b, A[l]));
l ++;
}
while (r%route != 0) {
ans += max(a, min(b, A[r-1]));
r --;
}
while (l/route < r/route) {
ans += F[l/route].sum(0, 100001);
if (1 <= a) {
ans += C[l/route].sum(0, a)*a-F[l/route].sum(0, a);
}
if (b < 100000) {
ans += C[l/route].sum(b+1, 100001)*b-F[l/route].sum(b+1, 100001);
}
l += route;
}
print(ans);
}
}
}
detteiuu