#include using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; #define rep(i,n) for(ll i=0;i T div_floor(T a, T b) { return a / b - ((a ^ b) < 0 && a % b); } template T div_ceil(T a, T b) { return a / b + ((a ^ b) > 0 && a % b); } template inline bool chmin(T &x, U y) { return (y < x) ? (x = y, true) : false; } template inline bool chmax(T &x, U y) { return (x < y) ? (x = y, true) : false; } #include using namespace atcoder; using mint = modint998244353; void solve() { ll N; cin>>N; vector A(N); rep(i,N)cin>>A[i]; auto op=[](ll x,ll y)->ll { return x+y; }; auto e=[]()->ll { return 0LL; }; segtree STA(A),STS(N+1); ll Q; cin>>Q; ll ans=0; rep(_,Q){ ll x,y,l,r; cin>>x>>y>>l>>r; l--; x--; ll s=STS.prod(0,x+1); ans+=(y-STA.get(x))*s; STA.set(x,y); ans+=STA.prod(l,r); STS.set(l,STS.get(l)+1); STS.set(r,STS.get(r)-1); cout<