Submission
Status:
-PTTTTTTTTTTTTTTTTTT
Score: 5
User: Asphyrv
Problemset: ผลบวก (ยาก)
Language: cpp
Time: 0.201 second
Submitted On: 2024-11-11 23:42:16
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int p[1000006], c[1000006];
int main(){
cin.tie(NULL)->ios_base::sync_with_stdio(false);
int n, a, x, y, q, t;
vector<int> v;
cin >> n;
//also works with range update sum queries
for(int i=0; i<n; i++){
cin >> a;
v.push_back(a);
}
cin >> q;
while(q--){
cin >> t;
while(t--){
cin >> x >> y;
c[x] += abs(v[x] - y);
}
cin >> x >> y;
//p[0] = v[0];
for(int i=1; i<=y+1; i++){
p[i] = p[i-1] + v[i-1] + c[i];
}
cout << p[y+1] - p[x] << '\n';
}
return 0;
}