Joao_Joao

Range Sum Queries I - C++

Aug 3rd, 2020 (edited)
99
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;typedef long double lf;typedef double fl;typedef string str;
  5. typedef vector<int> vi;typedef vector<vector<int>> vvi;typedef vector<fl> vf;typedef vector<ll> vl;
  6. typedef vector<lf> vlf;typedef vector<char> vc;typedef vector<str> vs;typedef pair<int,int> ii;
  7.  
  8. # define f(i,a,b,c) for(ll i=a;i<b;i+=c)
  9. # define fd(i,a,b,c) for(ll i=a;i>=b;i-=c)
  10.  
  11. ll soma[200000], au, n, q, x, y;
  12. int main(){
  13.    ios::sync_with_stdio(0);cin.tie(0);cout.precision(2);cout.setf(ios::fixed); 
  14.    
  15.     cin>>n>>q;
  16.     soma[0] = 0;
  17.     f(i,1,n+1,1){
  18.         cin>>au;
  19.         soma[i] = soma[i-1]+au;
  20.     }
  21.     f(i,0,q,1){
  22.         cin>>x>>y;
  23.         cout<<soma[y]-soma[x-1]<<'\n';
  24.     }
  25.    
  26. }
  27.  
RAW Paste Data Copied