题目简单描述就是求数组中[l,r]区间的和
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <numeric> using namespace std; int main(){ int n,m; cin >> n; vector<long long> v(n+1,0); for(int i= 1 ; i <= n ; ++ i) cin >> v[i]; vector<long long> u(v.begin(),v.end()); sort(u.begin(),u.end()); for(int i = 1; i <=n; ++ i){ v[i]+=v[i-1]; u[i]+=u[i-1]; } cin >> m; for(int i = 0; i < m; ++ i){ int number,l,r; cin >> number >> l >> r; if(number == 1) cout<<v[r]-v[l-1]<<endl; else cout<<u[r]-u[l-1]<<endl; } }