結果
問題 | No.877 Range ReLU Query |
ユーザー | tempura_pp |
提出日時 | 2019-09-06 21:49:52 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 346 ms / 2,000 ms |
コード長 | 2,247 bytes |
コンパイル時間 | 1,107 ms |
コンパイル使用メモリ | 109,116 KB |
実行使用メモリ | 11,280 KB |
最終ジャッジ日時 | 2023-08-08 04:14:50 |
合計ジャッジ時間 | 5,886 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 3 ms
4,376 KB |
testcase_02 | AC | 3 ms
4,376 KB |
testcase_03 | AC | 4 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 3 ms
4,380 KB |
testcase_07 | AC | 2 ms
4,376 KB |
testcase_08 | AC | 3 ms
4,376 KB |
testcase_09 | AC | 1 ms
4,380 KB |
testcase_10 | AC | 3 ms
4,376 KB |
testcase_11 | AC | 341 ms
11,100 KB |
testcase_12 | AC | 297 ms
10,308 KB |
testcase_13 | AC | 234 ms
7,792 KB |
testcase_14 | AC | 251 ms
7,732 KB |
testcase_15 | AC | 346 ms
10,936 KB |
testcase_16 | AC | 327 ms
10,676 KB |
testcase_17 | AC | 335 ms
11,088 KB |
testcase_18 | AC | 328 ms
11,088 KB |
testcase_19 | AC | 308 ms
11,280 KB |
testcase_20 | AC | 329 ms
11,104 KB |
ソースコード
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<complex> #include<queue> #include<deque> #include<stack> #include<map> #include<set> #include<bitset> #include<functional> #include<assert.h> #include<numeric> using namespace std; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) using ll = long long; const int inf=1e9+7; const ll longinf=1LL<<60 ; const ll mod=1e9+7 ; template<typename T> struct SegmentTree{ private: int n; T E; vector<T> node; inline void updatef(T& x,T& y){ x = y; } inline T queryf(T& x,T& y){ return {x.first + y.first, x.second+y.second}; } public: SegmentTree(int sz,T E_):E(E_){ n=1; while(n<sz)n<<=1; node.resize(2*n-1,E); } SegmentTree(vector<T>& A,T E_):E(E_){ int sz=A.size(); n=1; while(n<sz)n<<=1; node.resize(2*n-1,E); rep(i,sz)node[i+n-1]=A[i]; for(int i=n-2;i>=0;--i){ node[i]=queryf(node[2*i+1], node[2*i+2]); } } void update(int k,T x){ k+=n-1; updatef(node[k],x); while(k>0){ k=(k-1)/2; node[k]=queryf(node[2*k+1], node[2*k+2]); } } //[a,b)での和を返す T get(int a,int b,int k=0,int l=0,int r=-1){ if(r<0)r=n; if(r<=a||b<=l)return E; if(a<=l&&r<=b)return node[k]; T xl=get(a,b,2*k+1,l,(l+r)/2); T xr=get(a,b,2*k+2,(l+r)/2,r); return queryf(xl, xr); } }; int main(){ int n,q; cin>>n>>q; SegmentTree<pair<ll,ll>> sg(n,{0,0}); vector<ll> x(n+q); rep(i,n)cin>>x[i]; vector<int> l(q), r(q); rep(i,q){ cin>>l[i]>>l[i]>>r[i]>>x[n+i]; --l[i]; } vector<int> ord(n+q); vector<ll> ans(q); iota(ord.begin(),ord.end(),0); sort(ord.begin(),ord.end(),[&](int i, int j){ return x[i]>x[j]; }); for(auto i : ord){ if(i<n){ sg.update(i,{x[i],1}); } else { auto ret = sg.get(l[i-n],r[i-n]); ans[i-n]=ret.first-ret.second*x[i]; } } rep(i,q)cout<<ans[i]<<endl; return 0; }