Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- int q, a, b, n = 317;
- std::string str;
- int T[100000];
- int B[320];
- void update(int pos, int val)
- {
- B[pos / n] += val - T[pos];
- T[pos - 1] = val;
- }
- long long query(int lhs, int rhs)
- {
- long long res = 0;
- int leftBucket = lhs / n, rightBucket = rhs / n;
- if(rhs <= n)
- {
- for(int i = lhs - 1; i < rhs; i++)
- res += T[i];
- }
- else
- {
- for(int i = (rightBucket + 1) * n; i <= rhs; i++)
- res += T[i];
- for(int i = leftBucket + 1; i < rightBucket; i++)
- res += B[i];
- }
- return res;
- }
- int main()
- {
- std::cin >> q;
- while(q--)
- {
- std::cin >> str >> a >> b;
- if(str == "Query") std::cout << query(a,b) << std::endl;
- else update(a,b);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement