Submission #349427

#TimeUsernameProblemLanguageResultExecution timeMemory
349427sinamhdvSpiral (BOI16_spiral)C++11
27 / 100
1555 ms512 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int mod = 1000 * 1000 * 1000 + 7; const int INF = 1000 * 1000 * 1000; const ll LINF = (ll)INF * INF; #ifdef DEBUG #define dbg(x) cout << #x << " = " << (x) << endl << flush; #define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; } #else #define dbg(x) ; #define dbgr(s, f) ; #endif #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define msub(a, b) ((mod + ((ll)(a) - (b)) % mod) % mod) #define mdiv(a, b) ((ll)(a) * poww((b), mod - 2) % mod) #define all(x) (x).begin(), (x).end() #define pb push_back #define mp make_pair #define fr first #define sc second #define endl '\n' int n, q; ll get(int x, int y) { ll d = max(abs(x), abs(y)) + 1; ll ur = 4 * d * d - 10 * d + 7; ll off = 0; d--; if (y == d) off = d - x; else if (y == -d) { off = x + 5 * d; } else if (x == d) { off = y - d; } else if (x == -d) { off = 3 * d - y; } return ur + off; } int32_t main(void) { fast_io; cin >> n >> q; while (q--) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; ll ans = 0; FOR(i, x1, x2 + 1) { FOR(j, y1, y2 + 1) { ans = (ans + get(i, j)) % mod; } } cout << ans << endl; dbg(""); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...