Submission #1052962

#TimeUsernameProblemLanguageResultExecution timeMemory
1052962caterpillowSpiral (BOI16_spiral)C++17
12 / 100
79 ms262144 KiB
#include <bits/stdc++.h> using namespace std; using db = long double; using ll = long long; using pl = pair<ll, ll>; using pi = pair<int, int>; #define vt vector #define f first #define s second #define pb push_back #define all(x) x.begin(), x.end() #define size(x) ((int) (x).size()) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--) #define F0R(i, b) FOR (i, 0, b) #define endl '\n' const ll INF = 1e18; const int inf = 1e9; template<typename... Args> // tuples ostream& operator<<(ostream& os, tuple<Args...> t) { apply([&](Args... args) { string dlm = "{"; ((os << dlm << args, dlm = ", "), ...); }, t); return os << "}"; } template<typename T, typename V> // pairs ostream& operator<<(ostream& os, pair<T, V> p) { return os << "{" << p.f << ", " << p.s << "}"; } template<class T, class = decltype(begin(declval<T>()))> // iterables typename enable_if<!is_same<T, string>::value, ostream&>::type operator<<(ostream& os, const T& v) { string dlm = "{"; for (auto& i : v) os << dlm << i, dlm = ", "; return os << "}"; } template <typename T, typename... V> void printer(string pfx, const char *names, T&& head, V&& ...tail) { int i = 0; while (names[i] && names[i] != ',') i++; constexpr bool is_str = is_same_v<decay_t<T>, const char*>; if (is_str) cerr << " " << head; else cerr << pfx, cerr.write(names, i) << " = " << head; if constexpr (sizeof...(tail)) printer(is_str ? "" : ",", names + i + 1, tail...); else cerr << endl; } #ifdef LOCAL #define dbg(...) printer(to_string(__LINE__) + ": ", #__VA_ARGS__, __VA_ARGS__) #else #define dbg(x...) #define cerr if (0) std::cerr #endif const ll mod = 1e9 + 7; void add(ll& a, ll b) { a = (a + b) % mod; } /* subtask 1: just do it subtask 2: find the size of the inner ring, and then math how many extra squares around the outside you are subtask 3: */ ll n, q; main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> q; vt grid(2 * n + 2, vt<ll>(2 * n + 2)); grid[n][n] = 1; FOR (_i, 1, n + 1) { ll i = 2 * _i + 1; ll x = (i - 2) * (i - 2) + 1; ll r = n + _i; ll c = n + _i; F0R (j, i - 1) r--, grid[r][c] = x++; F0R (j, i - 1) c--, grid[r][c] = x++; F0R (j, i - 1) r++, grid[r][c] = x++; F0R (j, i - 1) c++, grid[r][c] = x++; } // F0R (i, 2 * n + 1) { // F0R (j, 2 * n + 1) { // const int len = 3; // string st = to_string(grid[i][j]); // cerr << string(" ", len - size(st)) << st << " \n"[j == 2 * n]; // } // } ROF (i, 0, 2 * n + 1) ROF (j, 0, 2 * n + 1) add(grid[i][j], grid[i + 1][j]); ROF (i, 0, 2 * n + 1) ROF (j, 0, 2 * n + 1) add(grid[i][j], grid[i][j + 1]); F0R (i, q) { int r1, r2, c1, c2; cin >> c1 >> r2 >> c2 >> r1; r1 += n, c1 += n, r2 += n, c2 += n; r1 = 2 * n - r1; r2 = 2 * n - r2; ll ans = grid[r1][c1] - grid[r1][c2 + 1] - grid[r2 + 1][c1] + grid[r2 + 1][c2 + 1] + 2 * mod; cout << (ans % mod) << endl; } }

Compilation message (stderr)

spiral.cpp:71:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   71 | main() {
      | ^~~~
#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...