Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- #define sp(y) fixed<<setprecision(y)
- #define w(t) int t;cin>>t;while(t--)
- #define pi 2*acos(0.0)
- #define bg begin()
- #define en end()
- #define all(x) x.begin(),x.end()
- #define sortarr(x) sort(x,x+arrsize(x))
- #define arrsize(x) sizeof(x)/sizeof(x[0])
- #define sortall(x) sort(all(x))
- #define formn(m,n) for(m;m<=n;m++)
- #define mp make_pair
- #define pb push_back
- #define vi vector<ll>
- #define vs vector<string>
- #define REP(i,a,b) for (int i=a;i<=b;i++)
- #define sq(a) (a)*(a)
- #define inparr(arr) for(auto &x: arr){cin>>x;}
- #define printarr(arr) for(auto x: arr){cout<<x<<" ";}
- #define nline "\n"
- //iterative
- //recursive
- ll pow(ll c,ll d){return d==0?1:c*pow(c,d-1);}
- ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
- ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}
- ll modpow(ll a,ll b,ll m){if(b==0){return 1%m;}ll res = modpow(a,b/2,m);res = (res*res) %m;if(b%2==1){res = (res*a) %m;}return res;}
- ll modpoweritterative(ll a,ll n,ll m){ll ans=1;while(n>=1){if(n%2==0){a = (1ll * a * a ) %m;n/=2;}else{ans =(1ll * a * ans ) % m;n--;}}return ans;}
- ll modinverse(ll a,ll m){ return modpoweritterative(a,m-2,m); }
- //fast I/o;
- void fastIO(){
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- }
- void init_code(){
- fastIO();
- #ifdef EPSILON
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- #endif
- }
- //solution
- #define mx 100005
- #define mod 1000000007
- int sum[mx];
- void solve(){
- int n,m;
- cin>>n;
- int arr[n];
- inparr(arr);
- for(int i=0;i<n;++i)
- {
- if(i==0){
- sum[i]=arr[i];
- }else{
- sum[i]=sum[i-1]+arr[i];
- }
- }
- cin>>m;
- for(int i=0;i<m;i++){
- int a,b;
- cin>>a>>b;
- cout<<sum[b]-sum[a-1]<<endl;
- }
- }
- //end solution
- int main(){
- init_code();
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement