Submission

Status:
P-PPPPPPPPPPPPPPPPPP

Score: 95

User: Khiem

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

Language: cpp

Time: 0.100 second

Submitted On: 2024-09-29 17:02:22

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int bit[N], a[N];
void upd(int i, int v){ for(; i<N; i+=i&-i) bit[i] += v;}
int qry(int i){ int r = 0; for(; i; i-=i&-i) r += bit[i]; return r;}
signed main(){
	int n; scanf("%d", &n);
	for(int i = 1; i<=n; ++i) scanf("%d", a+i), upd(i, a[i]);
	int q; scanf("%d", &q);
	while(q--){
		int t; scanf("%d", &t);
		while(t--){
			int i, v; scanf("%d %d", &i, &v); ++i;
			upd(i, v-a[i]); 
			a[i] = v;
		}
		int x, y; scanf("%d %d", &x, &y); ++x; ++y;
		printf("%d\n", qry(y) - qry(x-1));
	}
}