Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <bits/extc++.h>
- #define int int64_t
- #pragma GGG optimize("O3")
- using namespace std;
- using namespace __gnu_pbds;
- template<typename T>
- using orset = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
- template<typename T, typename K>
- using ormap = tree <T, K, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
- const int N = 500;
- int n, m, q;
- int a[N][N];
- int get(int fx, int fy, int sx, int sy){
- int sum = a[sx][sy];
- if (fx > 0)
- sum -= a[fx - 1][sy];
- if (fy > 0)
- sum -= a[sx][fy - 1];
- if (fy > 0 && fx > 0)
- sum += a[fx -1][fy - 1];
- return sum;
- }
- int32_t main() {
- ios::sync_with_stdio(false);
- cin >> n >> m>> q;
- for(int i = 0; i < n; i++){
- for(int j = 0; j < m; j++){
- cin >> a[i][j];
- }
- }
- for(int i = 1; i < n; i++)
- a[i][0] += a[i - 1][0];
- for(int i = 1; i < m; i++)
- a[0][i] += a[0][i - 1];
- for(int i = 1; i < n; i++){
- for(int j = 1; j < m; j++)
- a[i][j] = a[i][j] + a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
- }
- while(q--){
- int fi, fj, si, sj;
- cin >> fi >> fj >> si >> sj;
- fi--, si--, fj--, sj--;
- cout << get(fi, fj, si, sj) << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment