天天看點

Greater and Greater

​​G. Greater and Greater​​

參考:​​2020牛客多校第二場 G題Greater and Greater(bitset)​​

要仔細觀察規律,當看不出規律的時候,可以試着排序一下,看看能不能進行優化。
// Created by CAD on 2020/7/16.
#include <bits/stdc++.h>

#define fi first
#define se second
#define pii pair<int,int>
using namespace std;
const int maxn=1e5+5e4+5;
const int maxm=4e4+5;
pii a[maxn],b[maxm];
bitset<maxn> ans,t;

int main(){
    int n,m;cin>>n>>m;
    for(int i=1;i<=n;++i)   cin>>a[i].fi,a[i].se=i;
    for(int i=1;i<=m;++i)   cin>>b[i].fi,b[i].se=i;
    sort(a+1,a+n+1),sort(b+1,b+m+1);
    ans.set();
    for(int i=m,j=n;i>=1;--i){
        while(j>=1&&a[j].fi>=b[i].fi)
            t.set(a[j].se),j--;
        ans&=t>>(b[i].se-1);
    }
    cout<<ans.count()<<endl;
}