fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <map>
  5. #include <algorithm>
  6. #include <cmath>
  7. #include <ctime>
  8. #include <cstdlib>
  9. #include <cstdio>
  10. #include <utility>
  11. #include <iomanip>
  12. #include <assert.h>
  13. #define MP make_pair
  14. #define PB push_back
  15. #define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
  16. #define RE(i, n) FOR(i, 1, n)
  17. #define FORD(i, a, b) for(int i = (a); i >= (b); --i)
  18. #define REP(i, n) for(int i = 0;i <(n); ++i)
  19. #define VAR(v, i) __typeof(i) v=(i)
  20. #define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
  21. #define ALL(x) (x).begin(), (x).end()
  22. #define SZ(x) ((int)(x).size())
  23. #define PB push_back
  24. #define MP make_pair
  25. #ifdef LOCAL
  26. #define debug(x) {cerr <<#x <<" = " <<x <<"\n"; }
  27. #define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
  28. #else
  29. #define debug(x)
  30. #define debugv(x)
  31. #endif
  32. #define make(type, x) type x; cin>>x;
  33. #define make2(type, x, y) type x, y; cin>>x>>y;
  34. #define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
  35. using namespace std;
  36. typedef long long ll;
  37. typedef long double LD;
  38. typedef pair<int, int> PII;
  39. typedef pair<ll, ll> PLL;
  40. typedef vector<int> VI;
  41. typedef vector<ll> VLL;
  42. typedef vector<pair<int, int> > VPII;
  43. typedef vector<pair<ll, ll> > VPLL;
  44.  
  45. template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
  46. template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
  47. template<class T1, class T2>
  48. ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.X << ", " << pair.Y << ")";}
  49.  
  50. const ll INF = (ll)(2e9);
  51. ll A, B, K;
  52. long long rec(ll a, ll b, ll k, ll bit) {
  53. if (a < 0 || b < 0 || k < 0) {
  54. return 0;
  55. }
  56. long long to_ret = 0;
  57. ll bound = max(0ll, 2 * bit - 1);
  58. if (a >= bound) {
  59. a = INF;
  60. }
  61. if (b >= bound) {
  62. b = INF;
  63. }
  64. if (k >= bound) {
  65. return min(a + 1, bound + 1) * min(b + 1, bound + 1);
  66. }
  67. if (a == INF && b == INF) {
  68. return 3 * rec(a, b, k, bit / 2) + rec(a, b, k - bit, bit / 2);
  69. } else if (a == INF) {
  70. return 2 * rec(a, b, k, bit / 2) + rec(a, b - bit, k, bit / 2) + rec(a, b - bit, k - bit, bit / 2);
  71. } else if (b == INF) {
  72. return 2 * rec(a, b, k, bit / 2) + rec(a - bit, b, k, bit / 2) + rec(a - bit, b, k - bit, bit / 2);
  73. } else {
  74. return rec(a, b, k, bit / 2) + rec(a - bit, b, k, bit / 2) + rec(a, b - bit, k, bit / 2) +
  75. rec(a - bit, b - bit, k - bit, bit / 2);
  76. }
  77. }
  78. int main() {
  79. // nie zapomnij o ll
  80. ios_base::sync_with_stdio(0);
  81. cout << fixed << setprecision(10);
  82.  
  83. make(int, tt);
  84. RE (ttt, tt) {
  85. cout<<"Case #"<<ttt<<": ";
  86. cin>>A>>B>>K;
  87. A--;
  88. B--;
  89. K--;
  90. long long BIT = 1ll << 30;
  91. //cerr<<BIT<<endl;
  92. cout<<rec(A, B, K, BIT)<<endl;
  93. }
  94. // nie zapomnij o ll
  95. return 0;
  96. }
  97.  
Success #stdin #stdout 0s 3436KB
stdin
Standard input is empty
stdout
Standard output is empty