제출 #46780

#제출 시각아이디문제언어결과실행 시간메모리
46780WaschbarSpiral (BOI16_spiral)C++17
0 / 100
218 ms126720 KiB
///©Waschbar #include <bits/stdc++.h> using namespace std; const int MAXN = 1000; const int INF = 1e9; const long long MOD = 1e9+7; long long g[2*MAXN+10][2*MAXN+10]; long long sum[2*MAXN+10][2*MAXN+10]; int n, m; void func(int k, int x, int y, int num, char c) { if(x >= MAXN+5 || y >= MAXN+5) return; if(x <= -MAXN+1 || y <= -MAXN+1) return; if(k == 1){ g[x+MAXN][y+MAXN] = k++; } if(c == 'R') { for(int i = 1; i <= num; i++) { y++; if(x >= MAXN+5 || y >= MAXN+5) break; if(x <= -MAXN+1 || y <= -MAXN+1) return; //cout << x << " "<<y <<" "<<k<<endl; g[x+MAXN][y+MAXN] = k++; } for(int i = 1; i <= num; i++) { x++; if(x <= -MAXN+1 || y <= -MAXN+1) return; if(x >= MAXN+5 || y >= MAXN+5) break; //cout << x << " "<<y <<" "<<k<<endl; g[x+MAXN][y+MAXN] = k++; } func(k,x,y,num+1,'L'); return; } if(c == 'L') { for(int i = 1; i <= num; i++) { y--; if(x <= -MAXN+1 || y <= -MAXN+1) return; if(x >= MAXN+5 || y >= MAXN+5) break; //cout << x << " "<<y <<" "<<k<<endl; g[x+MAXN][y+MAXN] = k++; } for(int i = 1; i <= num; i++) { x--; if(x <= -MAXN+1 || y <= -MAXN+1) return; if(x >= MAXN+5 || y >= MAXN+5) break; //cout << x << " "<<y <<" "<<k<<endl; g[x+MAXN][y+MAXN] = k++; } func(k,x,y,num+1,'R'); return; } } int main() { ios_base::sync_with_stdio(false); //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); cin >> n; func(1,0,0,1,'R'); for(int i = 1; i <= 2*MAXN+5; i++) for(int j = 1; j <= 2*MAXN+5; j++) sum[i][j] = ((sum[i-1][j]+(sum[i][j-1]-sum[i-1][j-1]+MOD)%MOD)%MOD+g[i][j])%MOD; cin >> m; while(m--) { int x1, y1, x2, y2; cin >> y1 >> x1 >> y2 >> x2; x1 += MAXN; x2 += MAXN; y1 += MAXN; y2 += MAXN; cout << (long long)(sum[x2][y2]-sum[x2][y1-1]-sum[x1-1][y2]+sum[x1-1][y1-1]+MOD)%MOD << endl; } /*for(int i = 0; i <= 6; i++) { for(int j = 0; j <= 6; j++) { if(g[i+MAXN-2][j+MAXN-2] < 10) cout << " "; cout << g[i+MAXN-2][j+MAXN-2] << " "; } cout << endl; }*/ 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...