제출 #1353083

#제출 시각아이디문제언어결과실행 시간메모리
1353083kl0989eSpiral (BOI16_spiral)C++20
15 / 100
0 ms344 KiB
#include <bits/stdc++.h>
using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#define ll long long
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll,ll>
#define all(x) (x).begin(),(x).end()

const int mod=1e9+7;

int get(int x, int y) {
	int mx=max(abs(x),abs(y));
	mx--;
	ll t=(2ll*mx+1)*(2ll*mx+1);
	if (x==mx+1 && y==-mx-1) {
		return (2ll*mx+3)*(2ll*mx+3)%mod;
	}
	if (x==mx+1) {
		return (t+mx+1+y)%mod;
	}
	t+=(mx+1)*2;
	if (y==mx+1) {
		return (t+mx+1-x)%mod;
	}
	t+=(mx+1)*2;
	if (x==-mx-1) {
		return (t+mx+1-y)%mod;
	}
	t+=(mx+1)*2;
	return (t+mx+1+x)%mod;
}

int32_t main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    int n,q;
	cin >> n >> q;
	int x1,y1,x2,y2;
	for (int i=0; i<q; i++) {
		cin >> x1 >> y1 >> x2 >> y2;
		cout << get(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...