Submission #442361

# Submission time Handle Problem Language Result Execution time Memory
442361 2021-07-07T14:30:54 Z aryan12 Spiral (BOI16_spiral) C++17
12 / 100
132 ms 262148 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;

void Solve() {
	int n;
	cin >> n;
	int a[2 * n + 2][2 * n + 2];
	a[n][n] = 1;
	int k = 2;
	for(int i = 1; i <= n; i++) {
		for(int x = n + i, y = n - i + 1; y < n + i + 1; y++) {
			a[x][y] = k++;
		}
		for(int x = n + i - 1, y = n + i; x > n - i - 1; x--) {
			a[x][y] = k++;
		}
		for(int x = n - i, y = n + i - 1; y > n - i - 1; y--) {
			a[x][y] = k++;
		}
		for(int x = n - i + 1, y = n - i; x < n + i + 1; x++) {
			a[x][y] = k++;
		}
	}
	/*for(int i = 0; i < 2 * n + 1; i++) {
		for(int j = 0; j < 2 * n + 1; j++) {
			cout << a[i][j] << " ";
		}
		cout << "\n";
	}*/
	int pref[2 * n + 2][2 * n + 2];
	for(int i = 0; i < 2 * n + 2; i++) {
		for(int j = 0; j < 2 * n + 2; j++) {
			pref[i][j] = 0;
		}
	}
	for(int i = 1; i < 2 * n + 2; i++) {
		for(int j = 1; j < 2 * n + 2; j++) {
			pref[i][j] = pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + a[i - 1][j - 1];
			pref[i][j] += 10 * MOD;
			pref[i][j] %= MOD;
		}
	}
	int q;
	cin >> q;
	while(q--) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		x1 += n + 1, y1 += n + 1;
		x2 += n + 1, y2 += n + 1;
		cout << ((pref[x2][y2] - pref[x2][y1 - 1] - pref[x1 - 1][y2] + pref[x1 - 1][y1 - 1]) + 10 * MOD) % MOD << "\n";
	}
}

int32_t main() {
	auto begin = std::chrono::high_resolution_clock::now();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) {
		Solve();
	}
	auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 93 ms 63020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 132 ms 262148 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Correct 93 ms 63020 KB Output is correct
2 Runtime error 128 ms 262148 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 119 ms 262148 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Correct 93 ms 63020 KB Output is correct
2 Runtime error 132 ms 262148 KB Execution killed with signal 9