結果
問題 | No.1441 MErGe |
ユーザー |
![]() |
提出日時 | 2021-03-26 23:31:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 889 ms / 1,000 ms |
コード長 | 1,839 bytes |
コンパイル時間 | 7,234 ms |
コンパイル使用メモリ | 278,020 KB |
最終ジャッジ日時 | 2025-01-19 23:37:45 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 28 |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; using namespace atcoder; #define rep(i,n)for (int i = 0; i < int(n); ++i) #define rrep(i,n)for (int i = int(n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template<class T> void chmax(T& a, const T& b) {a = max(a, b);} template<class T> void chmin(T& a, const T& b) {a = min(a, b);} using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; VL a(n), s(n + 1); rep(i, n) cin >> a[i]; rep(i, n) s[i+1] = s[i] + a[i]; VI tmp(n); iota(all(tmp), 0); tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> t_l(all(tmp)); tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> t_r(all(tmp)); while(q--) { int type, l, r; cin >> type >> l >> r; l--, r--; if (type == 1) { { auto it1 = t_r.find_by_order(l); auto it2 = t_r.find_by_order(r); while(it1 != it2) it1 = t_r.erase(it1); } { auto it1 = t_l.find_by_order(l); auto it2 = t_l.find_by_order(r); while(it1 != it2) { auto tmp = it2; tmp--; t_l.erase(it2); it2 = tmp; } } } else { int i = *t_l.find_by_order(l); int j = *t_r.find_by_order(r); cout << s[j + 1] - s[i] << '\n'; } } }