Submission #13
Details and source code
| ID | Time | User | Problem | Lang | Verdict |
|---|---|---|---|---|---|
| 13 | Mar 22, 2025, 08:32 AM | n29 | RSQ Queries | cpp | AC |
Source Code
cpp#include<bits/stdc++.h>
using namespace std;
#ifndef BADGNU
#pragma GCC target("sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#endif
#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
// #define int ll
#define ld long double
#define y1 cheza
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N=1e5+100;
const int M=5001;
const int B=447;
const int mod=998244353;
const ll INF=1e18;
const int dx[]={1,-1,0,0};
const int dy[]={0,0,1,-1};
const double eps=1e-6;
int n,q;
ll f[N];
int a[N];
void upd(int x,int y){
int d=y-a[x];
a[x]=y;
for(;x<=n;x+=(-x&x)){
f[x]+=d;
}
}
ll calc(int r){
ll res=0;
for(;r>0;r-=(-r&r)){
res+=f[r];
}
return res;
}
void test(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
f[i]+=a[i];
if(i+(-i&i)<=n)
f[i+(-i&i)]+=f[i];
}
cin>>q;
for(int t,l,r;q--;){
cin>>t>>l>>r;
if(t==1){
upd(l,r);
}
else{
cout<<calc(r)-calc(l-1)<<'\n';
}
}
}
/*
*/
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// cout.tie(nullptr);
int t2=1;
// cin>>t2;
for(int i=1;i<=t2;i++){
test();
}
}