Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <tuple>
- #include <random>
- using std::pair;
- using std::cin;
- using std::cout;
- using std::vector;
- using int64 = int64_t;
- using std::max;
- using std::min;
- int GetPrev(int x) {
- return x & (x + 1);
- }
- int GetNext(int x){
- return x | (x + 1);
- }
- int GetSum(int l, int b, int r, int t, vector<vector<int>> &values) {
- int result = 0;
- for (int i = r; i >= l; i = GetPrev(i) - 1) {
- for (int j = t; j >= b; j = GetPrev(j) - 1) {
- result += values[i][j];
- }
- }
- return result;
- }
- void Modify(int x, int y, int s, vector<vector<int>> &values) {
- for (int i = x; i < values.size(); i = (i | (i + 1))) {
- for (int j = y; j < values[0].size(); j = (j | (j + 1))) {
- values[i][j] += s;
- }
- }
- }
- int main() {
- int zero, s;
- cin >> zero >> s;
- vector<vector<int>> vec(s, vector<int>(s, 0));
- while (true){
- int num;
- cin >> num;
- if (num == 3){
- break;
- } else if (num == 2){
- int l, b, r, t;
- cin >> l >> b >> r >> t;
- cout << GetSum(l, b, r ,t, vec) << '\n';
- } else {
- int x, y, a;
- cin >> x >> y >> a;
- Modify(x, y, a, vec);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement