Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- #define ll long long
- const int N = 2e5+5;
- const int LOG = 18;
- ll T[200005];
- int n;
- void update(ll x , ll val) {
- while (x <= n) {
- T[x] += val;
- x += x & (-x);
- }
- }
- ll sum(ll x) {
- ll sum = 0;
- while (x) {
- sum += T[x];
- x -= x & (-x);
- }
- return sum;
- }
- void solve() {
- int q;
- cin >> n >> q;
- vector <ll> v(n + 1);
- vector <ll> diff(n+1);
- memset(T , 0 , sizeof(T) );
- for(int i = 1; i<= n;i++) {
- cin >> v[i];
- diff[i] = v[i] - v[i-1];
- update(i , diff[i]);
- }
- while(q--)
- {
- int x; cin>>x;
- if(x == 1)
- {
- ll l , r , u; cin>>l>>r>>u;
- update(l , u);
- update(r+1 , -u);
- }
- else
- {
- int k; cin>>k;
- cout<<sum(k)<<"\n";
- }
- }
- }
- int main()
- {
- ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
- int tc = 1;
- //cin>>tc;
- while(tc--)
- {
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement