百题计划(7)
总结:
- cout.precision(10); cout.setf(ios::fixed); //保留10位小数
- 给你一个数组求最大异或区间,考虑用二进制tire维护、查询。时间复杂度\(O(nx^2)\)(x为最大值的二进制位数)。
参考代码:
点击查看代码
- vector
a a.back() a.empty(); a.push_back() 对于有的题,可以直接开个vector ,每次对末尾进行操作
4.删除重复项
点击查看代码
void build(){
sort(nums.begin(), nums.end());
nums.erase(unique(nums.begin(), nums.end()), nums.end());
5.区间合并 :
点击查看代码
std::vector<std::array<int, 2>> seg(n);
for (int i = 0; i < n; i++) {
int l, r, a, b;
std::cin >> l >> r >> a >> b;
seg[i] = {l, b};
}
std::sort(seg.begin(), seg.end());
std::vector<std::array<int, 2>> a;
for (auto [l, r] : seg) {
std::cout<<l<<" s "<<r<<"\n";
if (!a.empty() && l <= a.back()[1]) {
a.back()[1] = std::max(a.back()[1], r);
} else {
a.push_back({l, r});
}
}
for(auto [l,r]:a)
std::cout<<l<<" "<<r<<"\n";
int x;
std::cin >> x;
int pos = std::lower_bound(a.begin(), a.end(), std::array{x + 1, 0}) - a.begin() - 1; //小于等于x的最大l所在区间
if (pos >= 0) {
x = std::max(x, a[pos][1]);
}
}
点击查看代码
vector<int> ve;
ve.push_back(1);
ve.push_back(3);
ve.push_back(2);
ve.push_back(1);
int c1=count(ve.begin(),ve.end(),0);
点击查看代码
deque<pii> que;
que.push_front(pii(0, s));
while(!que.empty())
que.front();que.pop_front();
que.push_back(pii(dis[s - n - 1][v],v));