結果
| 問題 | No.3078 Difference Sum Query |
| コンテスト | |
| ユーザー |
applejam
|
| 提出日時 | 2026-01-11 21:20:28 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 287 ms / 2,000 ms |
| コード長 | 1,590 bytes |
| 記録 | |
| コンパイル時間 | 6,397 ms |
| コンパイル使用メモリ | 392,068 KB |
| 実行使用メモリ | 15,116 KB |
| 最終ジャッジ日時 | 2026-01-11 21:20:46 |
| 合計ジャッジ時間 | 15,847 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vmi = vector<mint>;
using vvmi = vector<vmi>;
using vvvmi = vector<vvmi>;
#define all(a) (a).begin(), (a).end()
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
ll op(ll a, ll b){
return a+b;
}
ll e(){return 0;}
using t = tuple<ll, int, int, int>;
using p = pair<ll, int>;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q; cin >> n >> q;
vll a(n); rep(i, n)cin >> a[i];
vll s(n+1, 0); rep(i, n)s[i+1] = s[i] + a[i];
priority_queue<p, vector<p>, greater<p>> pq;
rep(i, n)pq.push({a[i], i});
vector<t> vt;
rep(i, q){
int l, r; ll x; cin >> l >> r >> x;
l--;
vt.push_back({x, l, r, i});
}sort(all(vt));
vll ans(q, 0);
segtree<ll, op, e> seg1(n), seg2(n);
rep(i, q){
auto [x, l, r, j] = vt[i];
while(!pq.empty() && pq.top().first < x){
auto [b, k] = pq.top(); pq.pop();
seg1.set(k, b);
seg2.set(k, 1);
}
ll c = seg2.prod(l, r), base = s[r] - s[l];
ans[j] = c*x - 2*seg1.prod(l, r) + base - x*(r-l-c);
}
rep(i, q){
cout << ans[i] << endl;
}
return 0;
}
applejam