样例过但全T
查看原帖
样例过但全T
354310
Tnuzy_plzro楼主2023/3/20 20:24

大佬求救。。。 qwq

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
const int N=1e5+10;
int n,m,a[N],pos[N];
struct query{
    int l1,r1,l2,r2,l3,r3,ans;
};
struct modui{
    int l,r,id;
};
int bl[N];
bool operator <(modui a,modui b){
    if(bl[a.l]==bl[b.l])
    return a.r<b.r;
    else return a.l<b.l;
}
bitset<N> bs[1001];
modui M[1001];
query Q[N];
bitset<N> Bit;
void add(int x){
    Bit[pos[x]++]=1;
}
void del(int x){
    Bit[--pos[x]]=0;
}
void proc(int L,int R){
    if(L>R)return;
    int tot=0;
    rep(i,L,R){
        auto& st=Q[i];
        ++tot;M[tot]={st.l1,st.r1,tot};
        ++tot;M[tot]={st.l2,st.r2,tot};
        ++tot;M[tot]={st.l3,st.r3,tot};
    }
    sort(M+1,M+tot+1);
    Bit.reset();
    rep(i,1,n)pos[i]=i;
    int l=1,r=0;
    rep(i,1,tot){
        while(l>M[i].l)add(a[--l]);
        while(r>M[i].r)del(a[r--]);
        while(r<M[i].r)add(a[++r]);
        while(l<M[i].l)del(a[l++]);
        bs[M[i].id]=Bit;
    }
    rep(i,L,R){
        int tot0=(i-L)*3+1;
        bitset<N> bsh=bs[tot0];
        bsh&=bs[tot0+1];
        bsh&=bs[tot0+2];
        Q[i].ans=(Q[i].r1-Q[i].l1
        +Q[i].r2-Q[i].l2
        +Q[i].r3-Q[i].l3
        +3)-bsh.count()*3;
    }
}
map<int,int> mapp;
map<int,int> mapper;
int toty;
signed main(){
    int B=300;
    rep(i,1,N-1){
        bl[i]=i/B+1;
    }
    cin>>n>>m;
    rep(i,1,n)cin>>a[i];
    rep(i,1,n)mapp[a[i]]++;
    for(auto [u,v]:mapp){
        ++toty;
        mapper[u]=toty;
        toty+=v-1;
    }
    rep(i,1,n)a[i]=mapper[a[i]];
    rep(i,1,m){
        int a,b,c,d,e,f;
        cin>>a>>b>>c>>d>>e>>f;
        Q[i]={a,b,c,d,e,f,0};
    }
    rep(i,1,n)pos[i]=i;
    int i;
    for(i=1;i+300-1<=m;i+=300){
        proc(i,i+300-1);
    }
    proc(i,m);
    rep(i,1,m)cout<<Q[i].ans<<'\n';
}
2023/3/20 20:24
加载中...