提交时间:2022-02-08 16:42:03
运行 ID: 44435
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll read() { ll x(0); int p(1); char c(getchar()); while (c < '0' || c > '9') (c ^ '-' ? 0 : p = -p), c = getchar(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); return x * p; } void write(long long x) { if (x < 0) putchar('-'), x = -x; if (x >= 10) write(x / 10); putchar((x % 10) | 48); } constexpr ll MXN = 100005; constexpr ll BW = 316; long long arr[MXN], tag[BW + 5]; ll N, M; int main() { N = read(); for (ll i(0); i != N; ++i) arr[i] = read(); M = read(); for (ll opt, l, r, x; M--;) { opt = read(); if (opt == 1) { l = read() - 1, r = read(), x = read(); if (r < l) swap(l, r); if (l / BW == r / BW) { for (ll i(l); i != r; ++i) { arr[i] += x; } } else { for (ll i(l); i / BW == l / BW; ++i) arr[i] += x; for (ll i(l / BW + 1); i != r / BW; ++i) tag[i] += x; for (ll i(r / BW * BW); i != r; ++i) arr[i] += x; } } else { x = read() - 1; write(arr[x] + tag[x / BW]), putchar('\n'); } } return 0; }