結果
問題 | No.877 Range ReLU Query |
ユーザー | 👑 kmjp |
提出日時 | 2019-09-06 22:02:37 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 583 ms / 2,000 ms |
コード長 | 2,098 bytes |
コンパイル時間 | 1,858 ms |
コンパイル使用メモリ | 174,940 KB |
実行使用メモリ | 79,412 KB |
最終ジャッジ日時 | 2024-04-25 22:00:21 |
合計ジャッジ時間 | 8,541 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
36,024 KB |
testcase_01 | AC | 35 ms
36,276 KB |
testcase_02 | AC | 33 ms
36,368 KB |
testcase_03 | AC | 34 ms
36,188 KB |
testcase_04 | AC | 32 ms
36,136 KB |
testcase_05 | AC | 30 ms
35,964 KB |
testcase_06 | AC | 32 ms
36,260 KB |
testcase_07 | AC | 32 ms
36,100 KB |
testcase_08 | AC | 34 ms
36,340 KB |
testcase_09 | AC | 32 ms
36,224 KB |
testcase_10 | AC | 32 ms
36,064 KB |
testcase_11 | AC | 526 ms
69,628 KB |
testcase_12 | AC | 466 ms
68,808 KB |
testcase_13 | AC | 376 ms
63,076 KB |
testcase_14 | AC | 384 ms
60,088 KB |
testcase_15 | AC | 583 ms
78,108 KB |
testcase_16 | AC | 560 ms
76,860 KB |
testcase_17 | AC | 551 ms
78,060 KB |
testcase_18 | AC | 553 ms
78,308 KB |
testcase_19 | AC | 398 ms
79,412 KB |
testcase_20 | AC | 471 ms
79,284 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- template<class V,int NV> class SegTree_1 { public: vector<vector<V>> val,sum; static V const def=0; V comp(V l,V r){ return max(l,r);}; SegTree_1(){val.resize(NV*2);sum.resize(NV*2);}; V getval(int x,int y,int v,int l=0,int r=NV,int k=1) { // x<=i<y if(r<=x || y<=l) return 0; if(x<=l && r<=y) { int i=lower_bound(ALL(val[k]),v+1)-val[k].begin(); return sum[k].back()-sum[k][i]-v*(val[k].size()-i); } return getval(x,y,v,l,(l+r)/2,k*2)+getval(x,y,v,(l+r)/2,r,k*2+1); } void set(int entry,V v) { val[entry+NV].clear(); val[entry+NV].push_back(v); sum[entry+NV].clear(); sum[entry+NV].push_back(0); sum[entry+NV].push_back(v); } void build() { for(int i=NV-1;i>=1;i--) { val[i].clear(); int a=0,b=0; int x=i*2,y=i*2+1; while(a<val[x].size() || b<val[y].size()) { if(a==val[x].size()) { val[i].push_back(val[y][b++]); } else if(b==val[y].size()) { val[i].push_back(val[x][a++]); } else if(val[x][a]<val[y][b]) { val[i].push_back(val[x][a++]); } else { val[i].push_back(val[y][b++]); } } sum[i].clear(); sum[i].push_back(0); FORR(v,val[i]) sum[i].push_back(sum[i].back()+v); } } }; SegTree_1<ll,1<<18> st; int N,Q; void solve() { int i,j,k,l,r,x,y; string s; cin>>N>>Q; FOR(i,N) { cin>>x; st.set(i+1,x); } st.build(); FOR(i,Q) { int L,R,X; cin>>j>>L>>R>>X; cout<<st.getval(L,R+1,X)<<endl; } } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }