結果
問題 | No.877 Range ReLU Query |
ユーザー |
|
提出日時 | 2024-11-14 13:30:47 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,478 bytes |
コンパイル時間 | 4,100 ms |
コンパイル使用メモリ | 291,864 KB |
実行使用メモリ | 16,760 KB |
最終ジャッジ日時 | 2024-11-14 13:30:58 |
合計ジャッジ時間 | 10,641 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 11 RE * 9 |
ソースコード
#ifndef LOCAL#include <bits/stdc++.h>using namespace std;#define debug(...) (void(0))#else#include "algo/debug.h"#endif#include <atcoder/segtree>using S = long long;S op(S a, S b) {return a + b;}S e() {return 0;}void solve() {int N, Q;cin >> N >> Q;vector<S> A(N);for (int i = 0; i < N; i++) cin >> A[i];set<pair<int, int>> st;for (int i = 0; i < N; i++) st.insert({A[i], i});vector<array<long long, 4>> Qs(Q);for (int i = 0; i < Q; i++) {int t;cin >> t;int l, r, x;cin >> l >> r >> x;Qs[i] = {x, l, r, i};}debug(Qs);// cnt, sumatcoder::segtree<S, op, e> cnt(N);atcoder::segtree<S, op, e> sum(A);sort(Qs.begin(), Qs.end());auto Query = [&](int l, int r, long long x) -> S {l--;return x * cnt.prod(l, r) + sum.prod(l, r) - x * (r - l);};vector<S> ans(N);for (int ii = 0; ii < Q; ii++) {auto [x, l, r, i] = Qs[ii];while (!st.empty() && st.begin()->first <= x) {auto it = st.begin();auto [val, idx] = *it;st.erase(it);cnt.set(idx, 1);sum.set(idx, 0);}ans[i] = Query(l, r, x);}for (int i = 0; i < Q; i++) cout << ans[i] << endl;}int main() {std::ios::sync_with_stdio(false);std::cin.tie(nullptr);int tt = 1;// std::cin >> tt;while (tt--) {solve();}}