結果
問題 | No.1441 MErGe |
ユーザー | snow39 |
提出日時 | 2021-03-26 21:51:38 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 288 ms / 1,000 ms |
コード長 | 3,258 bytes |
コンパイル時間 | 1,546 ms |
コンパイル使用メモリ | 129,772 KB |
実行使用メモリ | 17,672 KB |
最終ジャッジ日時 | 2023-08-19 08:04:20 |
合計ジャッジ時間 | 8,514 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 3 ms
4,376 KB |
testcase_04 | AC | 3 ms
4,376 KB |
testcase_05 | AC | 6 ms
4,380 KB |
testcase_06 | AC | 6 ms
4,376 KB |
testcase_07 | AC | 6 ms
4,376 KB |
testcase_08 | AC | 56 ms
6,368 KB |
testcase_09 | AC | 56 ms
6,488 KB |
testcase_10 | AC | 80 ms
6,060 KB |
testcase_11 | AC | 74 ms
5,340 KB |
testcase_12 | AC | 81 ms
6,312 KB |
testcase_13 | AC | 238 ms
16,892 KB |
testcase_14 | AC | 228 ms
17,068 KB |
testcase_15 | AC | 238 ms
16,352 KB |
testcase_16 | AC | 247 ms
17,096 KB |
testcase_17 | AC | 226 ms
16,720 KB |
testcase_18 | AC | 185 ms
13,936 KB |
testcase_19 | AC | 193 ms
15,688 KB |
testcase_20 | AC | 156 ms
13,344 KB |
testcase_21 | AC | 138 ms
11,092 KB |
testcase_22 | AC | 176 ms
10,832 KB |
testcase_23 | AC | 279 ms
17,672 KB |
testcase_24 | AC | 275 ms
17,632 KB |
testcase_25 | AC | 273 ms
17,636 KB |
testcase_26 | AC | 288 ms
17,624 KB |
testcase_27 | AC | 281 ms
17,632 KB |
testcase_28 | AC | 176 ms
17,496 KB |
testcase_29 | AC | 179 ms
17,496 KB |
ソースコード
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <map> #include <queue> #include <iomanip> #include <set> #include <tuple> #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; const ll MOD=1e9+7; template<class T> void chmin(T &a,const T &b){if(a>b) a=b;} template<class T> void chmax(T &a,const T &b){if(a<b) a=b;} #include <functional> #include <climits> //SegmentTree<int> seg(N,[](int a,int b){return min(a,b);},INT_MAX); template< typename T> class SegmentTree{ private: void resize(int size){ n=1; while(n<size) n*=2; tree.resize(2*n-1,def); } public: using F = function<T(T,T)>; int n; vector<T> tree; F operation; T def; SegmentTree(){} SegmentTree(int size,F _operation,T _def):operation(_operation),def(_def){ resize(size); } void embody(int size,F _operation,T _def){ operation=_operation; def=_def; resize(size); } void initialize(const vector<T> &v){ int size=v.size(); resize(size); for(int i=0;i<size;i++) tree[i+n-1]=v[i]; for(int i=n-2;i>=0;i--) tree[i]=operation(tree[2*i+1],tree[2*i+2]); } void update(int index,T value){ index+=n-1; tree[index]=value; while(index>0){ index=(index-1)/2; tree[index]=operation(tree[2*index+1],tree[2*index+2]); } } T query(int a,int b,int k=0,int l=0,int r=-1){//[a,b) if(r<0) r=n; if(r<=a||b<=l) return def; else if(a<=l&&r<=b) return tree[k]; else{ T lval=query(a,b,2*k+1,l,(l+r)/2); T rval=query(a,b,2*k+2,(l+r)/2,r); return operation(lval,rval); } } T get(int index){ return tree[index+n-1]; } int find(int x,int k=0,int l=0,int r=-1){// a[0]+...+a[i]>=x (i:minimal) if(r<0) r=n; if(tree[k]<x) return -1; if(r-l==1) return k-(n-1); if(tree[2*k+1]>=x) return find(x,2*k+1,l,(l+r)/2); else return find(x-tree[2*k+1],2*k+2,(l+r)/2,r); } //right -> change vl to vr (notice doesn't contain b. range [a,b)) int find_left(int a,int b,T x,int k=0,int l=0,int r=-1){// max(a[a],...,a[i])>=x (i:minimal) if(r<0) r=n; if(tree[k]<x||r<=a||b<=l) return -1; if(r-l==1) return k-(n-1); int vl=find_left(a,b,x,2*k+1,l,(l+r)/2); if(vl>=0) return vl; return find_left(a,b,x-tree[2*k+1],2*k+2,(l+r)/2,r); } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N,Q; cin>>N>>Q; vector<ll> A(N); rep(i,N) cin>>A[i]; SegmentTree<int> seg(N,[](int a,int b){ return a+b; },0); seg.initialize(vector<int> (N,1)); vector<ll> sum(N+1,0); rep(i,N) sum[i+1]=sum[i]+A[i]; set<int> se; rep(i,N) se.insert(i); rep(q,Q){ int t,l,r; cin>>t>>l>>r; l--;r--; if(t==1){ int st=seg.find_left(0,N,l+1); auto itr=se.lower_bound(st); int cnt=0; while(cnt<r-l){ int pos=*itr; seg.update(pos,0); itr=se.erase(itr); cnt++; } }else{ int pr=seg.find_left(0,N,r+1); int pl=-1; if(l>0) pl=seg.find_left(0,N,l); ll res=sum[pr+1]-sum[pl+1]; cout<<res<<"\n"; } } return 0; }