N方过十万,暴力碾标算

· · 题解

本题考查简单的循环,但是可能过不去。

因为本题是 CF 的题,所以可以用火车头。

加上写的比较好看和内存访问连续,方便编译器自动向量化,于是就过了,最劣解。

#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#ifdef __unix__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#else
#define getchar _getchar_nolock
#define putchar _putchar_nolock
#endif
int read() {
    int x=0,f=1;char ch=getchar();
    while(ch<48||ch>57){if(ch=='-')f=-1;ch=getchar();}
    while(ch>=48&&ch<=57)x=x*10+ch-48,ch=getchar();
    return x*f;
}
inline void write(int x){
    static int s[35];int top=0;
    if(x<0)putchar('-'),x=-x;
    if(x==0){putchar('0');return;}
    while(x){s[top++]=x%10;x/=10;}
    while(top)putchar('0'+s[--top]);
}
using namespace std;
constexpr int N=1e5+20;
int n,m,inc[N],pr[N];
int ans[N];
struct node{int s,b,p;}a[N];
int s[N];
int ss[N],diff[N],sum[N];
signed main(){
    n=read();m=read();
    for(int i=1;i<=n;i++)a[i].p=read();
    for(int i=1;i<=n;i++)a[i].s=read();
    for(int i=1;i<=n;i++)a[i].b=read();
    for(int i=1;i<=m;i++)inc[i]=read();
    for(int i=1;i<=m;i++)pr[i]=read();
    sort(a+1,a+1+n,[](node s1,node s2){
        return s1.b<s2.b;
    });
    for(int i=1;i<=n;i++){
        s[i]=a[i].b;
        ss[i]=a[i].s;
        diff[i]=a[i].p-a[i].b;
        sum[i]=a[i].b+a[i].p;
    }
    for(int i=1;i<=m;i++){
        int incc=inc[i],prr=pr[i],val=0;
        int wh=upper_bound(s+1,s+1+n,prr)-s-1;
        int t1=incc-prr;
        int t2=incc+prr;
        for(int j=1;j<=wh;j++){
            val+=((ss[j]>=incc)&(diff[j]<=t1));
        }
        for(int j=wh+1;j<=n;j++){
            val+=((ss[j]>=incc)&(sum[j]<=t2));
        }
        ans[i]=val;
    }
    for(int i=1;i<=m;i++)write(ans[i]),putchar(' ');
    return 0;
}