社区讨论
bitset 求卡常
P14957【模板】离线静态四维数点参与者 5已保存回复 8
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 8 条
- 当前快照
- 1 份
- 快照标识符
- @mk2b8phi
- 此快照首次捕获于
- 2026/01/06 16:11 上个月
- 此快照最后确认于
- 2026/01/09 20:50 上个月
总用时 16~17s,TLE 最后一个点。
CPP#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int n,m,ans[400005];
struct node {
int x[4];
} a[800005];
int b[4][800005];
ull mk[400005][150], tmp[150];
void ATRI() {
for(int l=1,r; l<=n; l=r+1) {
r=min(l+9599,n);
for(int i=0; i<4; i++) {
for(int j=0; j<150; j++) tmp[j]=0;
for(int j=1; j<=n+m; j++) {
if(b[i][j]<=n) {
if(l<=b[i][j] && b[i][j]<=r) tmp[(b[i][j]-l)>>6]|=(1ll<<((b[i][j]-l)&63));
} else {
if(i==0) for(int k=0; k<150; k++) mk[b[i][j]-n][k]=tmp[k];
else for(int k=0; k<150; k++) mk[b[i][j]-n][k]&=tmp[k];
}
}
// cout<<clock()<<'\n';
}
// cout<<"end\n";
for(int i=1; i<=m; i++) for(int j=0; j<150; j++) ans[i]+=__builtin_popcountll(mk[i][j]);
}
}
char buf[1<<20],*p1,*p2;
#define fast_getchar() (((p1==p2)&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin))),*p1++)
int rd() {
int s=0;
char c=fast_getchar();
while(c<48) c=fast_getchar();
while(c>47) s=s*10+(c^48), c=fast_getchar();
return s;
}
void write(int x) {
static int st[10], top;
if(!x) {
putchar('0');
return;
}
top=0;
while(x) st[++top]=x%10, x/=10;
while(top) putchar(48+st[top--]);
}
int main() {
// freopen("in.txt","r",stdin);
n=rd(), m=rd();
for(int i=1; i<=n+m; i++) {
for(int j=0; j<4; j++) a[i].x[j]=rd();
a[i].x[2]*=-1, a[i].x[3]*=-1;
}
// cerr<<clock()<<'\n';
for(int i=0; i<4; i++) {
for(int j=1; j<=n+m; j++) b[i][j]=j;
sort(b[i]+1, b[i]+1+n+m, [i](int xx, int yy) {
node &x=a[xx], &y=a[yy];
if(x.x[i]!=y.x[i]) return x.x[i]<y.x[i];
for(int j=0; j<4; j++)
if(i!=j && x.x[j]!=y.x[j])
return x.x[j]<y.x[j];
return xx<yy;
});
}
// cerr<<clock()<<'\n';
ATRI();
for(int i=1; i<=m; i++) write(ans[i]), putchar('\n');
return 0;
}
回复
共 8 条回复,欢迎继续交流。
正在加载回复...