fork download
  1. #include <functional>
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <cstring>
  5. #include <cassert>
  6. #include <cstdio>
  7. #include <string>
  8. #include <vector>
  9. #include <ctime>
  10. #include <queue>
  11. #include <set>
  12. #include <map>
  13. using namespace std;
  14. #define forn(i, n) for (int i = 0; i < (int)(n); i++)
  15. #define fore(i, b, e) for (int i = (int)(b); i <= (int)(e); i++)
  16. #define ford(i, n) for (int i = (int)(n)-1; i >= 0; i--)
  17. #define mp make_pair
  18. #define fi first
  19. #define se second
  20. #define pb push_back
  21. #define all(x) (x).begin(), (x).end()
  22. #define eq(x, y) (abs((x)-(y))<eps)
  23. #define lt(x, y) ((x)<(y)-eps)
  24. #define le(x, y) ((x)<=(y)+eps)
  25. #define gt(x, y) ((x)>(y)+eps)
  26. #define ge(x, y) ((x)>=(y)-eps)
  27. typedef long long i64;
  28. typedef unsigned long long u64;
  29. typedef unsigned int u32;
  30. typedef double ld;
  31. typedef pair<int, int> pii;
  32. typedef vector<int> vi;
  33. const int inf = 1e9+100500;
  34. const int maxn = 134;
  35.  
  36. #define ok(x, y) ((x)>=0 && (y)>=0 && (x)<maxn && (y)<maxn)
  37.  
  38. const int dx[] = {0, 0, 1, -1};
  39. const int dy[] = {1, -1, 0, 0};
  40.  
  41. int a[maxn][maxn], nxt[maxn][maxn];
  42. int n = maxn;
  43.  
  44.  
  45. bool iter2()
  46. {
  47. bool upd = false;
  48. forn(i, maxn) forn(j, maxn) {
  49. int t = a[i][j] / 4;
  50. if (t) {
  51. upd = true;
  52. a[i][j] -= 4*t;
  53. forn(k, 4) a[i+dx[k]][j+dy[k]] += t;
  54. }
  55. }
  56. return upd;
  57. }
  58.  
  59. int h = 0;
  60.  
  61. int solve(int n)
  62. {
  63. forn(i, maxn) forn(j, maxn) a[i][j] = 0;
  64. a[maxn/2][maxn/2] = n;
  65.  
  66. int cnt = 0;
  67. while (iter2()) ++cnt;
  68.  
  69. int mxx = -1, mxy = -1, mnx = 100000, mny = 100000;
  70. forn(i, maxn) forn(j, maxn) if (a[i][j]) {
  71. mxx = max(mxx, i); mnx = min(mnx, i);
  72. mxy = max(mxy, j); mny = min(mny, j);
  73. }
  74.  
  75. cerr << mnx << " " << mxx << " " << mny << " " << mxy << endl;
  76. cerr << mxx - mnx << endl;
  77.  
  78. //cout << " ---- " << n << " ----" << endl;
  79. //fore(i, mnx, mxx) {
  80. //fore(j, mny, mxy) cout << a[i][j] << " ";
  81. //cout << endl;
  82. //}
  83. //cout << endl;
  84.  
  85. forn(i, maxn) forn(j, maxn) h = h * 10099 + a[i][j] * 179;
  86.  
  87. return cnt;
  88. }
  89.  
  90. void gen()
  91. {
  92. freopen("input.txt", "w", stdout);
  93. cout << 30000 << " " << 50000 << endl;
  94. forn(i, 50000) cout << rand()%1000 << " " << rand()%1000 << endl;
  95. }
  96.  
  97. int main()
  98. {
  99. solve(30000);
  100. return 0;
  101. //gen();
  102. //freopen("input.txt", "r", stdin);
  103. //freopen("/dev/null", "w", stdout);
  104. int n;
  105. scanf("%d", &n);
  106. solve(n);
  107. int t;
  108. scanf("%d", &t);
  109. forn(i, t) {
  110. int x, y;
  111. scanf("%d%d", &x, &y);
  112. x += maxn/2; y += maxn/2;
  113. if (ok(x, y)) printf("%d\n", a[x][y]);
  114. else printf("0\n");
  115. }
  116. //for (int i = 1; i <= 100; i++)
  117. //cout << i << ": " << solve(i) << endl;
  118.  
  119. //cout << h << endl;
  120.  
  121. #ifdef HOME
  122. cerr << "time = " << clock()/1000 << " ms" << endl;
  123. #endif
  124. return 0;
  125. }
  126.  
Success #stdin #stdout #stderr 0.33s 2992KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
3 131    3 131
128