# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
968229 |
2024-04-23T08:35:54 Z |
PM1 |
Spiral (BOI16_spiral) |
C++17 |
|
1500 ms |
436 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 a=cal(max(-i+1,x),i),b=cal(min(xx,i-1),i);
ans+=(a+b)*(b-a+1)/2;
ans%=M;
}
}
}
cout<<ans<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1591 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
152 ms |
436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1562 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1591 ms |
348 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |