Submission #350935

#TimeUsernameProblemLanguageResultExecution timeMemory
350935MHNaderiSpiral (BOI16_spiral)C++14
0 / 100
111 ms79084 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define all(x) x.begin() , x.end() #define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout); #define random_init mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #define int long long #define pb push_back #define pii pair<int,int> #define F first #define S second const int maxn=3e3,INF=1e18,mod=1e9+7; int mark[maxn][maxn],dp[maxn][maxn]; pii pls(pii a , pii b){ return {a.F+b.F,a.S+b.S}; } int32_t main(){ ios_base::sync_with_stdio(0); int n; cin>>n; pii dir[4]={ {0,+1} , {+1,0} , {0,-1} , {-1,0} }; pii go={n+1,n+1}; int cnt=1; int x=1,w=0; while(cnt < (2*n+1)*(2*n+1)){ if(w>1){ w=0; x++; } int direction=((x-1)%2)*2+w; int xx=x; while(xx--){ mark[go.F][go.S]=cnt++; go=pls(go,dir[direction]); } w++; } // for(int i=1;i<=2*n+1;i++){ // for(int j=1;j<=2*n+1;j++) // cout<<mark[i][j]<<" "; // cout<<'\n'; // } for(int i=0;i<=2*n+1;i++){ dp[0][i]=dp[i][0]=0; } for(int i=1;i<=2*n+1;i++){ for(int j=1;j<=2*n+1;j++){ dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+mark[i][j]+mod)%mod; // cout<<dp[i][j]<<' '; } // cout<<'\n'; } int q; cin>>q; while(q--){ int x1,x2,y1,y2; cin>>y1>>x1>>y2>>x2; x1+=n+1; x2+=n+1; y1+=n+1; y2+=n+1; cout<<(dp[x2][y2]-dp[x1-1][y2]-dp[x2][y1-1]+dp[x1-1][y1-1]+mod)%mod; } 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...