#include #include #include #include #include #include #include #include
    #include #include #include #include #include #include using namespace std; #define pii pair #define ll long long #define FAST ios_base::sync_with_stdio(false); cin.tie(NULL) const long long dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; const long long dl[2] = {1, -1}; const long long MOD = 1000000007; const long long MAXN = 1000005; int N, Q; long long arr[MAXN]; int sq; long long sq_arr[MAXN]; void build_sqrt(){ for(int i = 0; i < N; i++){ sq_arr[i / sq] += arr[i]; } } long long query(int x, int y){ int xdec = x / sq; int ydec = y / sq; long long ret = 0; if(xdec == ydec){ for(int i = x; i <= y; i++){ ret += arr[i]; } return ret; } for(int i = x; i < (xdec + 1) * sq; i++){ ret += arr[i]; } for(int i = xdec + 1; i < ydec; i++){ ret += sq_arr[i]; } for(int i = ydec * sq; i <= y; i++){ ret += arr[i]; } return ret; } void update(int a, long long b){ sq_arr[a / sq] -= arr[a]; sq_arr[a / sq] += b; arr[a] = b; } int main() { FAST; cin>> N>> Q; for(int i = 0; i < N; i++){ cin>> arr[i]; } sq = (int) sqrt(N); build_sqrt(); for(int i = 0; i < Q; i++){ int x, y, a; long long b; cin>> x>> y>> a>> b; x--; y--; a--; if(x> y){ swap(x, y); } cout << query(x, y) << "\n"; update(a, b); } } /* 5 2 1 2 3 4 5 2 3 3 1 3 5 4 1 */

    AltStyle によって変換されたページ (->オリジナル) /