-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththe_last_problem.cpp
52 lines (40 loc) · 1.11 KB
/
the_last_problem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <bits/stdc++.h>
using namespace std;
#define long long long int
#define pii pair<int, int>
#define pll pair<long, long>
#define fst first
#define snd second
#define all(ds) (ds).begin(), (ds).end()
#define rall(ds) (ds).rbegin(), (ds).rend()
#define size(ds) (int) (ds).size()
#define pq priority_queue
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
const int MAX = 1e3 + 5;
long get_sum(long start, int length) {
long ans = (start + length - 1) * (start + length) / 2;
return ans - (start - 1) * start / 2;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T; cin >> T;
while (T--) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
long ans = 0LL;
for (int i = x1; i <= x2; i++) {
long aux = get_sum(1, y1 - 1) + 1LL;
ans += aux + get_sum(y1 + 1, i - 1);
}
for (int i = y1 + 1; i <= y2; i++) {
long aux = get_sum(1, i - 1) + 1LL;
ans += aux + get_sum(i + 1, x2 - 1);
}
cout << ans << "\n";
}
}