結果
問題 | No.877 Range ReLU Query |
ユーザー | ei1333333 |
提出日時 | 2019-09-07 01:41:29 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 989 ms / 2,000 ms |
コード長 | 4,530 bytes |
コンパイル時間 | 2,825 ms |
コンパイル使用メモリ | 219,364 KB |
実行使用メモリ | 129,408 KB |
最終ジャッジ日時 | 2024-11-08 10:13:37 |
合計ジャッジ時間 | 12,562 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 5 ms
5,248 KB |
testcase_02 | AC | 4 ms
5,248 KB |
testcase_03 | AC | 4 ms
5,248 KB |
testcase_04 | AC | 3 ms
5,248 KB |
testcase_05 | AC | 4 ms
5,248 KB |
testcase_06 | AC | 4 ms
5,248 KB |
testcase_07 | AC | 4 ms
5,248 KB |
testcase_08 | AC | 6 ms
5,248 KB |
testcase_09 | AC | 4 ms
5,248 KB |
testcase_10 | AC | 4 ms
5,248 KB |
testcase_11 | AC | 860 ms
99,028 KB |
testcase_12 | AC | 740 ms
96,028 KB |
testcase_13 | AC | 574 ms
79,612 KB |
testcase_14 | AC | 572 ms
70,980 KB |
testcase_15 | AC | 941 ms
125,852 KB |
testcase_16 | AC | 989 ms
122,152 KB |
testcase_17 | AC | 987 ms
125,296 KB |
testcase_18 | AC | 944 ms
126,540 KB |
testcase_19 | AC | 435 ms
129,408 KB |
testcase_20 | AC | 696 ms
129,404 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using int64 = long long; const int mod = (int) (1e9 + 7); const int64 infll = (1LL << 62) - 1; const int inf = (1 << 30) - 1; struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template< typename T1, typename T2 > ostream &operator<<(ostream &os, const pair< T1, T2 > &p) { os << p.first << " " << p.second; return os; } template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; } template< typename T > ostream &operator<<(ostream &os, const vector< T > &v) { for(int i = 0; i < (int) v.size(); i++) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; } template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template< typename T = int64 > vector< T > make_v(size_t a) { return vector< T >(a); } template< typename T, typename... Ts > auto make_v(size_t a, Ts... ts) { return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...)); } template< typename T, typename V > typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) { t = v; } template< typename T, typename V > typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); } template< typename F > struct FixPoint : F { FixPoint(F &&f) : F(forward< F >(f)) {} template< typename... Args > decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, forward< Args >(args)...); } }; template< typename F > inline decltype(auto) MFP(F &&f) { return FixPoint< F >{forward< F >(f)}; } template< typename Monoid, typename F > struct PersistentSegmentTree { struct Node { Monoid data; Node *l, *r; Node(const Monoid &data) : data(data), l(nullptr), r(nullptr) {} }; int sz; const F f; const Monoid M1; PersistentSegmentTree(const F f, const Monoid &M1) : f(f), M1(M1) {} Node *build(const vector< Monoid > &v) { sz = (int) v.size(); return build(0, (int) v.size(), v); } Node *merge(Node *l, Node *r) { auto t = new Node(f(l->data, r->data)); t->l = l; t->r = r; return t; } Node *build(int l, int r, const vector< Monoid > &v) { if(l + 1 >= r) return new Node(v[l]); return merge(build(l, (l + r) >> 1, v), build((l + r) >> 1, r, v)); } Node *update(int a, const Monoid &x, Node *k, int l, int r) { if(r <= a || a + 1 <= l) { return k; } else if(a <= l && r <= a + 1) { return new Node(x); } else { return merge(update(a, x, k->l, l, (l + r) >> 1), update(a, x, k->r, (l + r) >> 1, r)); } } Node *update(Node *t, int k, const Monoid &x) { return update(k, x, t, 0, sz); } Monoid query(int a, int b, Node *k, int l, int r) { if(r <= a || b <= l) { return M1; } else if(a <= l && r <= b) { return k->data; } else { return f(query(a, b, k->l, l, (l + r) >> 1), query(a, b, k->r, (l + r) >> 1, r)); } } Monoid query(Node *t, int a, int b) { return query(a, b, t, 0, sz); } }; int main() { int N, Q; cin >> N >> Q; vector< pair< int, int > > A(N); for(int i = 0; i < N; i++) { cin >> A[i].first; A[i].second = i; } sort(begin(A), end(A)); auto add = [](int64 a, int64 b) { return a + b; }; PersistentSegmentTree< int64, decltype(add) > beet(add, 0); vector< PersistentSegmentTree< int64, decltype(add) >::Node * > tapi(N + 1), tapu(N + 1); tapi[0] = beet.build(vector< int64 >(N, 1)); vector< int64 > dat(N); for(int i = 0; i < N; i++) dat[A[i].second] = A[i].first; tapu[0] = beet.build(dat); for(int i = 0; i < N; i++) { tapi[i + 1] = beet.update(tapi[i], A[i].second, 0); tapu[i + 1] = beet.update(tapu[i], A[i].second, 0); } auto type1 = [&]() { int l, r, x; cin >> l >> r >> x; --l; int pos = lower_bound(begin(A), end(A), make_pair(x, 0)) - begin(A); int64 add = 0; add -= beet.query(tapi[pos], l, r) * x; add += beet.query(tapu[pos], l, r); cout << add << "\n"; }; while(Q--) { int T; cin >> T; type1(); } }