mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-15 03:10:07 +08:00
formatting source-code for 153fb7b8a5
This commit is contained in:
@@ -12,19 +12,15 @@ const int maxn = 1e5 + 7;
|
||||
int tree[maxn] = {0},
|
||||
range; // segement of [1...range], notice it must be less than `maxn`
|
||||
|
||||
void update(int x, int c)
|
||||
{
|
||||
while (x <= range)
|
||||
{
|
||||
void update(int x, int c) {
|
||||
while (x <= range) {
|
||||
tree[x] += c;
|
||||
x += lowbit(x);
|
||||
}
|
||||
}
|
||||
int query(int x)
|
||||
{
|
||||
int query(int x) {
|
||||
int ans = 0;
|
||||
while (x)
|
||||
{
|
||||
while (x) {
|
||||
ans += tree[x];
|
||||
x -= lowbit(x);
|
||||
}
|
||||
@@ -32,29 +28,23 @@ int query(int x)
|
||||
}
|
||||
int query_segement(int l, int r) { return query(r) - query(l - 1); }
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
cin >> range;
|
||||
for (int i = 1; i <= range; i++)
|
||||
{
|
||||
for (int i = 1; i <= range; i++) {
|
||||
int num;
|
||||
cin >> num;
|
||||
update(i, num);
|
||||
}
|
||||
int q;
|
||||
cin >> q;
|
||||
while (q--)
|
||||
{
|
||||
while (q--) {
|
||||
int op;
|
||||
cin >> op;
|
||||
if (op == 0)
|
||||
{
|
||||
if (op == 0) {
|
||||
int l, r;
|
||||
cin >> l >> r;
|
||||
cout << query_segement(l, r) << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
int x, c;
|
||||
cin >> x >> c;
|
||||
update(x, c);
|
||||
|
||||
Reference in New Issue
Block a user