Submission #68933

# Submission time Handle Problem Language Result Execution time Memory
68933 2018-08-19T09:58:21 Z alenam0161 Spiral (BOI16_spiral) C++17
27 / 100
1500 ms 39800 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const long long mod = 1e9+7;
const int N = 5007;
long long get(long long x,long long y){	
	long long r=max(abs(x),abs(y));
		long long h=r+r+1;
		h%=mod;
		long long sz=h*h;
		sz%=mod;
		if(y==-r){
			return (sz-(r-x)+mod+mod)%mod;
		}
		else{
			sz-=r;
			sz-=r;
			sz+=mod;
			sz+=mod;
			sz%=mod;
			if(x==-r){
				return (sz-(y+r)+mod+mod)%mod;
			}
			else{
				sz-=r;
				sz-=r;
				sz+=mod;
				sz+=mod;
				sz%=mod;
				if(y==r){
					return (sz-(x+r)+mod+mod)%mod;
				}
				else{
					sz-=r;
					sz-=r;
					sz+=mod;
					sz+=mod;
					sz%=mod;
					return (sz-(r-y)+mod+mod)%mod;
				}
			}
		}
}
long long dp[3007][3007];
int sh=1001;
int main()
{
	int n,q;
	cin>>n>>q;
	if(n<=1000){
		for(int i=-1000;i<=1000;++i)
			for(int j=-1000;j<=1000;++j){
				dp[i+sh][j+sh]=dp[i+sh][j-1+sh]+dp[i-1+sh][j+sh]-dp[i-1+sh][j-1+sh]+get(i,j);
				dp[i+sh][j+sh]+=mod+mod+mod;
				dp[i+sh][j+sh]%=mod;
			}
		for(int i=1;i<=q;++i){
			long long x,y,x1,y1;
			cin>>x>>y>>x1>>y1;
			long long gum=dp[x1+sh][y1+sh]-dp[x1+sh][y-1+sh]-dp[x-1+sh][y1+sh]+dp[x-1+sh][y-1+sh];
			gum+=mod;
			gum+=mod;
			gum%=mod;
			cout<<gum<<endl;
		}
		return 0;
	}
	for(int i=1;i<=q;++i){
		long long x,y,x1,y1;
		cin>>x>>y>>x1>>y1;
		long long gum=0;
		for(int j=x;j<=x1;++j){
			for(int k=y;k<=y1;++k){
				gum+=get(j,k);
				gum%=mod;
			}
		}
		cout<<gum<<endl;
	}
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 147 ms 39800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 39800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 147 ms 39800 KB Output is correct
2 Execution timed out 1574 ms 39800 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1584 ms 39800 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 147 ms 39800 KB Output is correct
2 Correct 4 ms 39800 KB Output is correct
3 Execution timed out 1574 ms 39800 KB Time limit exceeded