結果
| 問題 | No.877 Range ReLU Query |
| コンテスト | |
| ユーザー |
minato
|
| 提出日時 | 2020-09-24 01:40:54 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 328 ms / 2,000 ms |
| コード長 | 6,132 bytes |
| 記録 | |
| コンパイル時間 | 4,072 ms |
| コンパイル使用メモリ | 231,756 KB |
| 最終ジャッジ日時 | 2025-01-14 19:55:43 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
//#pragma GCC target("avx2,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#include <atcoder/all>
//using namespace atcoder;
//using mint = modint998244353;
//using mint = modint1000000007;
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//using i128 = __int128_t;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
constexpr char ln = '\n';
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
inline int topbit(int x) {return x == 0 ? -1 : 31-__builtin_clz(x);}
inline int topbit(long long x) {return x == 0 ? -1 : 63-__builtin_clzll(x);}
inline int botbit(int x) {return x == 0 ? 32 : __builtin_ctz(x);}
inline int botbit(long long x) {return x == 0 ? 64 : __builtin_ctzll(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
inline int kthbit(long long x, int k) {return (x>>k)&1;}
inline void print() {cout << "\n";}
template<class T>
inline void print(const vector<T> &v) {
for (auto itr = v.begin(); itr != v.end(); ++itr) cout << *itr << " ";
print();
}
template<class T, class... Args>
inline void print(const T &x, const Args &... args) {
cout << x << " ";
print(args...);
}
#ifdef MINATO_LOCAL
#define dump(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
inline void debug() {cerr << endl;}
template<class T>
inline void debug(const vector<T> &v) {
for (auto itr = v.begin(); itr != v.end(); ++itr) cerr << *itr << " ";
debug();
}
template<class T, class... Args>
inline void debug(const T &x, const Args &... args) {
cerr << x << " ";
debug(args...);
}
#else
#define dump(x) void(0)
inline void debug() {}
template<class T> inline void debug(const vector<T> &v) {}
template<class T, class... Args> inline void debug(const T &x, const Args &... args) {}
#endif
//struct Fast_ios {Fast_ios() {cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);};} fast_ios;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<typename T, typename F>
struct SegmentTree {
private:
F op;
T e;
int _n, size ,log;
vector<T> node;
public:
SegmentTree() {}
SegmentTree(const F& op, T e, int n) : SegmentTree(op, e, vector<T>(n, e)) {}
SegmentTree(const F& op, T e, const vector<T>& v) : op(op), e(e), _n(int(v.size())), log(0) {
while ((1<<log) < _n) log++;
size = 1 << log;
node = vector<T> (2 * size, e);
for (int i = 0; i < _n; i++) node[size + i] = v[i];
for (int i = size - 1; i >= 1; i--) {
update(i);
}
}
// (0-indexed)
void set(int p, T x) {
assert(0 <= p && p < _n);
p += size;
node[p] = x;
for (int i = 1; i <= log; i++) update(p >> i);
}
// [l, r) (0-indexed)
T get(int l, int r) {
if (l >= r) return e;
T resl = e, resr = e;
l += size; r += size;
while (l < r) {
if (l & 1) resl = op(resl, node[l++]);
l >>= 1;
if (r & 1) resr = op(node[--r], resr);
r >>= 1;
}
return op(resl, resr);
}
T all_get() { return node[1]; }
template <typename C>
int max_right(int l, const C& check) {
assert(0 <= l && l <= _n);
assert(check(e));
if (l == _n) return _n;
l += size;
T sm = e;
do {
while (~l & 1) l >>= 1;
if (!check(op(sm, node[l]))) {
while (l < size) {
l = (2 * l);
if (check(op(sm, node[l]))) {
sm = op(sm, node[l]);
l++;
}
}
return l - size;
}
sm = op(sm, node[l]);
l++;
} while ((l & -l) != l);
return _n;
}
template <typename C>
int min_left(int r, const C& check) {
assert(0 <= r && r <= _n);
assert(check(e));
if (r == 0) return 0;
r += size;
T sm = e;
do {
r--;
while (r > 1 && (r & 1)) r >>= 1;
if (!check(op(node[r], sm))) {
while (r < size) {
r = (2 * r + 1);
if (f(op(node[r], sm))) {
sm = op(node[r], sm);
r--;
}
}
return r + 1 - size;
}
sm = op(node[r], sm);
} while ((r & -r) != r);
return 0;
}
T operator[](int p) {
assert(0 <= p && p < _n);
return node[p + size];
}
private:
void update(int k) { node[k] = op(node[2 * k], node[2 * k + 1]); }
};
int main() {
int N,Q; cin >> N >> Q;
vector<ll> A(N),L(Q),R(Q),x(Q);
rep(i,N) cin >> A[i];
rep(i,Q) {
int t;
cin >> t >> L[i] >> R[i] >> x[i];
L[i]--;
}
vector<int> idx(Q);
iota(all(idx),0);
sort(all(idx),[&](int i, int j){return x[i] < x[j];});
priority_queue<pll, vector<pll>, greater<pll>> pq;
rep(i,N) pq.emplace(A[i],i);
auto f=[](pll a, pll b) {return pll(a.first+b.first,a.second+b.second);};
const pll e = pll(0,0);
SegmentTree seg(f,e,N);
rep(i,N) seg.set(i,pll(A[i],1));
vector<ll> ans(Q);
rep(i,Q) {
int u = idx[i];
while (!pq.empty() and pq.top().first < x[u]) {
int v = pq.top().second; pq.pop();
seg.set(v,e);
}
auto[S,c] = seg.get(L[u],R[u]);
ans[u] = S - c*x[u];
}
rep(i,Q) cout << ans[i] << ln;
}
minato