Submission

Status:

PPPPPPPPPPPPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: qweqwe

Problemset: ผลบวก (ยาก)

Language: cpp

Time: 0.083 second

Submitted On: 2025-12-10 18:05:41

#include <bits/stdc++.h>
#define speed cin.tie(0)->sync_with_stdio(0)
#define ll long long
#define pii pair<int,int>
using namespace std;

vector<int> fwck(1000001);
int n;

void update(int idx,int val){
	idx++;
	while (idx<=n){
		fwck[idx]+=val;
		idx+=idx&(-idx);
	}
}

ll query(int idx){
	idx++;ll sum=0;
	while (idx>0){
		sum+=fwck[idx];
		idx-=idx&(-idx);
	}return sum;
}

int main(){
	speed;
	cin >> n;
	vector<int> arr(n);
	for (int i=0;i<n;i++){
		cin >> arr[i];
		update(i,arr[i]);
	} 
	int q;cin >> q;
	while (q--){
		int t;cin >> t;
		while (t--){
			int idx,v;cin >> idx >> v;
			update(idx,v-arr[idx]);arr[idx]=v;
		}int l,r;cin >> l >> r;
		cout << query(r)-query(l-1) << "\n";
	}
	return 0;
}