結果
問題 |
No.1441 MErGe
|
ユーザー |
![]() |
提出日時 | 2021-03-27 01:21:58 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 430 ms / 1,000 ms |
コード長 | 2,917 bytes |
コンパイル時間 | 8,874 ms |
コンパイル使用メモリ | 291,088 KB |
最終ジャッジ日時 | 2025-01-19 23:48:52 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 28 |
ソースコード
#pragma GCC diagnostic warning "-Wextra" #pragma GCC diagnostic warning "-Wshadow" #include <bits/stdc++.h> using namespace std; #include <bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <class A, class B> bool cmin(A& a, B b) { return a > b && (a = b, true); } template <class A, class B> bool cmax(A& a, B b) { return a < b && (a = b, true); } template <class A, class B> ostream& operator<<(ostream& os, pair<A, B>& p) { return os << '(' << p.first << ", " << p.second << ')'; } static bool debug = false; void dump() {} template <class A, class... B> void dump(A&& a, B&&... b) { if (debug) cout << a << (sizeof...(b) ? ' ' : '\n'), dump(b...); } template <class A> void dump1D(A& a) { if (debug) for (auto i = a.begin(); i != a.end(); i++) cout << *i << (next(i) != a.end() ? ' ' : '\n'); } template <class A> void dump2D(A& a) { if (debug) for (auto i = a.begin(); i != a.end(); i++) dump1D(*i), cout << (next(i) != a.end() ? "" : "\n"); } template <typename T> class FenwickTree { private: long N, M; vector<T> B; public: FenwickTree() : N(0) {} FenwickTree(long n) : N(n + 1), M(1), B(N, 0) { while (M * 2 <= N) M *= 2; } FenwickTree(const vector<T> &v) : N((long)v.size() + 1), M(1), B(N, 0) { for (long i = 0; i < N - 1; i++) add(i, v.at(i)); while (M * 2 <= N) M *= 2; } void add(long i, T x) { i++; while (i < N) B.at(i) += x, i += i & -i; } void add(long l, long r, T x) { add(l, x); add(r + 1, -x); } T sum(long i) { i++; T ret = 0; while (i > 0) ret += B.at(i), i -= i & -i; return ret; } T sum(long l, long r) { return sum(r) - sum(l - 1); } T at(long i) { return sum(i) - sum(i - 1); } long lower_bound(T w) { if (w <= 0) return 0; long x = 0; for (long k = M; k > 0; k /= 2) { if (x + k <= N - 1 && B.at(x + k) < w) { w -= B.at(x + k); x += k; } } return x; } long upper_bound(T w) { if (w < 0) return 0; long x = 0; for (long k = M; k > 0; k /= 2) { if (x + k <= N - 1 && B.at(x + k) <= w) { w -= B.at(x + k); x += k; } } return x; } }; signed main() { cin.tie(nullptr)->sync_with_stdio(false); debug = true; long N, Q; cin >> N >> Q; vector<long> A(N); for (long i = 0; i < N; i++) cin >> A.at(i); vector<tuple<long, long, long>> V(Q); for (long i = 0; i < Q; i++) { long a, b, c; cin >> a >> b >> c, b--, c--; V.at(i) = {a, b, c}; } FenwickTree<long> FT(A); tree<long, null_type, less<long>, rb_tree_tag, tree_order_statistics_node_update> T; for (long i = 0; i <= N; i++) T.insert(i); for (const auto& [a, l, r] : V) { if (a == 1) { for (long i = r; i > l; i--) T.erase(*T.find_by_order(i)); } else { cout << FT.sum(*T.find_by_order(l), *T.find_by_order(r + 1) - 1) << '\n'; } } }