답안 #968207

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968207 2024-04-23T08:30:14 Z PM1 Spiral (BOI16_spiral) C++17
0 / 100
1500 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxn=1e5+5,M=1e9+7;
int n,q;
int cal(int x,int y){
	ll w=max(abs(x),abs(y));
		ll z=w*2+1,zz=z*z;
		if(-w==x)
			return (zz-(w-y))%M;
		zz-=z;
		if(-w==y)
			return (zz-(x+w-1))%M;
		zz-=z-1;
		if(x==w)
			return (zz-(y+w-1))%M;
		zz-=z-1;
		return (zz-(w-1-x))%M;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>q;
	while(q--){
		int x,y,xx,yy;
		cin>>y>>x>>yy>>xx;
		ll ans=0;
		if(x<=0 && xx>=0 &&y<=0 && yy>=0)ans++;
		for(int i=1;i<=n;i++){
			if(x<=-i && xx>=-i){
				if(y<= i && yy>=-i){
					ll a=cal(-i,max(-i,y)),b=cal(-i,min(yy,i));
					ans+=(a+b)*(b-a+1)/2;
					ans%=M;
				}
			}
			if(y<=-i && yy>=-i){
				if(x<= i && xx>=-i+1){
					ll b=cal(max(-i+1,x),-i),a=cal(min(xx,i),-i);
					ans+=(a+b)*(b-a+1)/2;
					ans%=M;
				}
			}

			if(x<=i && xx>=i){
				if(y<= i && yy>=-i+1){
					ll b=cal(i,max(-i+1,y)),a=cal(i,min(yy,i));
					ans+=(a+b)*(b-a+1)/2;
					ans%=M;
				}
			}
			if(y<=i && yy>=i){
				if(x<= i-1 && xx>=-i+1){
					ll b=cal(max(-i+1,x),i),a=cal(min(xx,i-1),i);
					ans+=(a+b)*(b-a+1)/2;
					ans%=M;
				}
			}
		}
		cout<<ans<<'\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1560 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1511 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -