Select solution language
Write solution here.
## Solution:
### - SỠdụng Vector Trong STL C++
### - Kết Hợp Vá»›i kỹ thuáºt Mảng cá»™ng dồn
## My Code:
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,q;
cin >> n >> q;
vector<int> v(n + 1);
vector<long long> pre(n + 1);
for(int i = 1;i <= n;i++){
cin >> v[i];
pre[i] = pre[i - 1] + v[i];
}
while(q--){
int c;
cin >> c;
if(c == 1){
int x;
cin >> x;
v.push_back(x);
pre.push_back(pre.back() + x);
}
if(c == 2){
if(v.size()){
v.pop_back();
pre.pop_back();
}
}
if(c == 3){
int l,r;
cin >> l >> r;
cout << pre[r] - pre[l - 1] << "\n";
}
}
return 0;
}
```