This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub beet-aizu/library
// verification-helper: PROBLEM https://judge.yosupo.jp/problem/static_range_sum #include <bits/stdc++.h> using namespace std; #define call_from_test #include "../../datastructure/cumulativesum.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; using ll = long long; int n,q; cin>>n>>q; vector<ll> as(n); for(int i=0;i<n;i++) cin>>as[i]; CumulativeSum cs(as); for(int i=0;i<q;i++){ int l,r; cin>>l>>r; cout<<cs.query(l,r)<<newl; } return 0; }
#line 1 "test/yosupo/static_range_sum.test.cpp" // verification-helper: PROBLEM https://judge.yosupo.jp/problem/static_range_sum #include <bits/stdc++.h> using namespace std; #define call_from_test #line 1 "datastructure/cumulativesum.cpp" #line 3 "datastructure/cumulativesum.cpp" using namespace std; #endif //BEGIN CUT HERE template<typename T> struct CumulativeSum{ vector<T> sm; CumulativeSum(const vector<T> &as){ int n=as.size(); sm.resize(n+1); sm[0]=T(); for(int i=0;i<n;i++) sm[i+1]=sm[i]+as[i]; } // [l, r) T query(int l,int r){return -sm[l]+sm[r];} }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif #line 8 "test/yosupo/static_range_sum.test.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); const char newl = '\n'; using ll = long long; int n,q; cin>>n>>q; vector<ll> as(n); for(int i=0;i<n;i++) cin>>as[i]; CumulativeSum cs(as); for(int i=0;i<q;i++){ int l,r; cin>>l>>r; cout<<cs.query(l,r)<<newl; } return 0; }