#include <bits/stdc++.h> using namespace std; using ll = long long; struct Key { int a, b, s; bool operator==(const Key &other) const { return a == other.a && b == other.b && s == other.s; } }; struct KeyHash { size_t operator()(const Key &k) const { return ((size_t)k.a * 73856093U) ^ ((size_t)k.b * 19349663U) ^ ((size_t)k.s * 83492791U); } }; int l1, r1, l2, r2; unordered_map<Key,int,KeyHash> memo; int F(int a, int b, int s) { Key key{a,b,s}; if(memo.count(key)) return memo key ; // The square: a, a+s x b, b+s . // Check if completely inside Q. if(a >= l1 && a+s <= r1 && b >= l2 && b+s <= r2) return memo key = 1; // Check if completely outside Q. if(a >= r1 || a+s <= l1 || b >= r2 || b+s <= l2) return memo key = 0; // Partial overlap. if(s == 1) { // For a 1x1 cell (with integer boundaries) it is either completely inside or not. if(a >= l1 && a+s <= r1 && b >= l2 && b+s <= r2) return memo key = 1; else return memo key = 0; } int s2 = s/2; int ans = F(a, b, s2) + F(a+s2, b, s2) + F(a, b+s2, s2) + F(a+s2, b+s2, s2); return memo key = ans; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while(t--){ cin >> l1 >> r1 >> l2 >> r2; memo.clear(); // Determine S = 2^L large enough so that 0,S covers Q. int maxBound = max(r1, r2); int S = 1; while(S < maxBound) S *= 2; cout << F(0,0,S) << "\n"; } return 0; } 给我简化命名,删除注释,用万能头文件
时间: 2025-03-12 17:03:45 浏览: 35
好的,下面是简化后的版本。去掉了详细的注释,并且使用了 `#include <bits/stdc++.h>` 这个万能头文件来进行包含所有标准库的功能:
```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct K {
int a, b, s;
bool operator==(const K &o) const { return a == o.a && b == o.b && s == o.s; }
};
struct KH {
size_t operator()(const K &k) const {
return ((size_t)k.a * 73856093U) ^ ((size_t)k.b * 19349663U) ^ ((size_t)k.s * 83492791U);
}
};
int l1, r1, l2, r2;
unordered_map<K, int, KH> m;
int f(int a, int b, int s) {
K k{a, b, s};
if (m.count(k)) return m[k];
if (a >= l1 && a + s <= r1 && b >= l2 && b + s <= r2) return m[k] = 1;
if (a >= r1 || a + s <= l1 || b >= r2 || b + s <= l2) return m[k] = 0;
if (s == 1) {
if (a >= l1 && a + s <= r1 && b >= l2 && b + s <= r2) return m[k] = 1;
else return m[k] = 0;
}
int h = s / 2;
int res = f(a, b, h) + f(a + h, b, h) + f(a, b + h, h) + f(a + h, b + h, h);
return m[k] = res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
cin >> l1 >> r1 >> l2 >> r2;
m.clear();
int mx = max(r1, r2), S = 1;
while (S < mx) S *= 2;
cout << f(0, 0, S) << "\n";
}
return 0;
}
```
### 简化的主要内容包括:
- 删除详细注释,保留关键逻辑。
- 使用更短的变量名如`K`, `KH`, `f`等代替冗长名称。
阅读全文
相关推荐



















