結果
問題 | No.2942 Sigma Music Game Level Problem |
ユーザー |
![]() |
提出日時 | 2024-10-18 21:57:30 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 423 ms / 6,000 ms |
コード長 | 2,599 bytes |
コンパイル時間 | 3,282 ms |
コンパイル使用メモリ | 248,536 KB |
実行使用メモリ | 14,252 KB |
最終ジャッジ日時 | 2024-11-14 23:00:30 |
合計ジャッジ時間 | 10,963 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; using tll=tuple<ll,ll,ll>; using ld=long double; constexpr ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define replr(i,l,r) for (ll i=(ll)(l);i<(ll)(r);i++) #define all(v) v.begin(),v.end() #define len(v) ((ll)v.size()) template<class T> inline bool chmin(T &a,T b){ if(a>b){ a=b; return true; } return false; } template<class T> inline bool chmax(T &a,T b){ if(a<b){ a=b; return true; } return false; } template<class T> struct fenwick_tree{ vector<T> v; int n; fenwick_tree(int x){ n=x; v.assign(n+1,0); } fenwick_tree(vector<T> &a){ n=(int)a.size(); v.assign(n+1,0); for(int i=0;i<n;i++) v[i+1]=a[i]; for(int idx=1;idx<=n;idx++){ if(n<idx+(idx&(-idx))) continue; v[idx+(idx&(-idx))]+=v[idx]; } } void add(int i,T x){ assert(0<=i&&i<n); i++; for(int idx=i;idx<=n;idx+=(idx&(-idx))){ v[idx]+=x; } } T sum(int r){ //[0,r] r++; T ret=0; for(int idx=r;0<idx;idx-=(idx&(-idx))){ ret+=v[idx]; } return ret; } T sum(int l,int r){ //[l,r] assert(0<=l&&l<n); assert(0<=r&&r<n); assert(l<=r); if(l==0) return sum(r); return sum(r)-sum(l-1); } int lower_bound(T w){ if(w<=0) return 0; int x=0; static int r=1; if(r==1){ while((r<<1)<=n) r<<=1; } while((r<<1)<=n) r<<=1; for(int k=r;0<k;k>>=1){ if(x+k<=n&&v[x+k]<w){ w-=v[x+k]; x+=k; } } return x; } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll n,q,l0; cin >> n >> q >> l0; ll sz=(ll)2e5+1; fenwick_tree<ll> cnt(sz),sum(sz); vector<ll> a(n); rep(i,n){ cin >> a[i]; cnt.add(a[i],1); sum.add(a[i],a[i]); } bool found=false; while(q--){ ll t; cin >> t; if(t==1){ ll l; cin >> l; cnt.add(l,1); sum.add(l,l); } if(t==2){ ll l,r; cin >> l >> r; cout << cnt.sum(l,r) << ' ' << sum.sum(l,r) << '\n'; found=true; } if(t==3){ ll m; cin >> m; } } if(!found) cout << "Not Found!\n"; }