Submission #1263301

#TimeUsernameProblemLanguageResultExecution timeMemory
1263301rtriSpiral (BOI16_spiral)C++20
0 / 100
1 ms324 KiB
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> grid;

typedef long long int ll;

ll MOD = 1e9 + 7;

ll modpow(ll base, ll exp) {
  base %= MOD;
  ll res = 1;
  while (exp > 0) {
    if (exp & 1)
      res = (res * base) % MOD;
    base = (base * base) % MOD;
    exp >>= 1;
  }
  return res;
}

ll at_poll(ll x, ll y) {
  if (x == 0 && y == 0)
    return 1;

  ll loc = max(abs(x), abs(y));
  ll slen = (2 * loc - 1) % MOD;
  ll val = (slen * slen) % MOD;

  if (y == loc)
    val += 6 * loc + loc + x;
  else if (x == -loc)
    val += 4 * loc + loc + y;
  else if (y == -loc)
    val += 2 * loc + loc - x;
  else if (x == loc)
    val += loc - y;

  return val % MOD;
}

int main() {
  int n, q;
  cin >> n >> q;

  for (int i = 0; i < q; i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << at_poll(x1, y1) << "\n";
  }

  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...