# G题 Greater and Greater

## 题面

$\forall i \in {1,2,...m}, S_i \leq B_i$

## 思路

$对每个B_i遍历A数组，判定大小，然后就有了m个01序列$

$B_1=2 \quad 011111$

$B_2=3 \quad 010111$

$B_3=3 \quad 010111$

$B_1=011111\quad移动０位\\ B_2=10111\quad 移动１位\\ B_3=0111\quad 移动２位\\ temp=B_1 \&B_2\&B_3\\ ans=temp.cout()$

$对A,B序列排序，来使数字总是递增的保证复杂度$

## 代码

#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+5, M = 4e3 + 5;
int n, m;
struct node
{
int num,pos;
}a[N],b[N];
bool cmp(node x,node y)
{
return x.num < y.num;
}
bitset<N> bi,ans;
int main()
{
scanf("%d %d", &n,&m);
for (int i = 1; i <= n;i++)
{
scanf("%d", &a[i].num);
a[i].pos = i;
}
for (int i = 1; i <= m;i++)
{
scanf("%d", &b[i].num);
b[i].pos = i;
}
sort(a + 1, a + n + 1, cmp);
sort(b + 1, b + m + 1, cmp);
ans.set();//全为1
bi.set();//全为1
int posx = 1;

for (int i = 1; i <= m;i++)
{
while(posx<=n&&a[posx].num<b[i].num)
{
bi.reset(a[posx].pos);//不满足，变0
posx++;
}
//cout << (bi>>(b[i].pos-1)) << endl;
ans = ans & (bi >> (b[i].pos-1));
}
int tot = 0;
for (int i = 1; i <= n-m+1;i++)
{
if(ans[i]&1)
tot++;
}
printf("%d\n", tot);
return 0;
}
/*

*/


posted @ 2020-07-16 21:36  Sakura_Momoko  阅读(186)  评论(2编辑  收藏  举报