2020牛客多校二 G. Greater and Greater (双指针+bitset优化)
程序员文章站
2022-04-02 19:03:02
...
题意:给定长度为n的序列a,和长度为m的序列b,问有序列a中有多少个长度为m的连续子区间s,满足s(i)>=b(i)。
题解:双指针+bitset优化
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<fstream>
#include<set>
#include<map>
#include<sstream>
#include<iomanip>
#include<bitset>
#define ll long long
using namespace std;
int n, m, x;
vector<pair<int, int> > a, b;
bitset<150005> res, ans;
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", &x), a.push_back(make_pair(x, i));
for (int i = 0; i < m; i++) scanf("%d", &x), b.push_back(make_pair(x, i));
sort(a.begin(), a.end());
sort(b.begin(), b.end());
ans.set();
for (int i = m - 1, j = n - 1; i >= 0; i--) {
while (j >= 0 && a[j].first >= b[i].first) {
res.set(a[j--].second);
}
ans &= (res >> b[i].second);
}
printf("%d\n", ans.count());
return 0;
}
推荐阅读
-
2020暑期牛客多校第二场G.Greater and Greater(bitset+思维构造)
-
2020牛客暑期多校训练营(第二场)G Greater and Greater bitset+思维
-
2020牛客多校第二场 G - Greater and Greater(思维+bitset)
-
2020牛客多校 2G.Greater and Greater(双指针+bitset优化)
-
【Newcoder】2020牛客暑期多校训练营(第二场)G - Greater and Greater | bitset、思维
-
2020牛客多校二 G. Greater and Greater (双指针+bitset优化)
-
2020牛客多校 G - Greater and Greater 动态规划+bitset优化
-
2020牛客多校第二场(G题)Greater and Greater
-
G-Greater and Greater 2020牛客多校第二场
-
2020牛客暑假多校B Boundary(计算几何) G Greater and Greater(bitset)