結果
問題 | No.877 Range ReLU Query |
ユーザー |
![]() |
提出日時 | 2019-09-06 22:56:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 84 ms / 2,000 ms |
コード長 | 1,705 bytes |
コンパイル時間 | 1,294 ms |
コンパイル使用メモリ | 93,856 KB |
実行使用メモリ | 8,704 KB |
最終ジャッジ日時 | 2024-11-08 10:09:57 |
合計ジャッジ時間 | 3,643 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 20 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <functional> #include <array> #include <cstdio> #include <cstring> #include <cmath> using namespace std; using ll = long long; struct P { P &operator+=(const P &p) { s += p.s; c += p.c; return *this; } ll s; int c; }; struct BIT { BIT(int n) : b(n + 1), n(n) {} void add(int i, P v) { for (int k = i + 1; k <= n; k += k & -k) b[k] += v; } P sum(int k) { P s = { 0, 0 }; for (; k > 0; k -= k & -k) s += b[k]; return s; } vector<P> b; int n; }; struct Q { bool operator<(const Q &q) const { return x > q.x; } ll s; int l, r, x, h; }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<pair<int, int>> a(n); for (int i = 0; i < n; i++) { cin >> a[i].first; a[i].second = i; } sort(a.begin(), a.end(), greater<>()); vector<Q> q(m); for (int h = 0; h < m; h++) { int t, l, r, x; cin >> t >> l >> r >> x; l--; q[h] = { 0, l, r, x, h }; } sort(q.begin(), q.end()); BIT bt(n); int i = 0; for (int h = 0; h < m; h++) { int x = q[h].x; for (; i < n && a[i].first > x; i++) { bt.add(a[i].second, { a[i].first, 1 }); } P p0 = bt.sum(q[h].l); P p1 = bt.sum(q[h].r); q[h].s = (p1.s - p0.s) - (p1.c - p0.c) * (ll)x; } vector<ll> r(m); for (int h = 0; h < m; h++) { r[q[h].h] = q[h].s; } for (int h = 0; h < m; h++) { cout << r[h] << '\n'; } return 0; }