JOISC2019游记JOISC2019 游记
Day 1:
試験 (Examination)
题⽬⼤意:
有\(n(n\le10^5)\)个⼈,每个⼈有两种属性\(s_i,t_i\)。\(q(q\le10^5)\)次询问,每次给出\ ((a_i,b_i,c_i)\),询问同时满⾜\(s_i\ge a_i\),\(t_i\ge b_i\)和\(s_i t_i\ge c_i\)的⼈数。思路:
三维偏序裸题,CDQ分治即可。
源代码:
#include<cstdio>
#include<cctype>
#include<algorithm>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2) x)<<1) (ch^'0');
return x;
}
const int N=2e5 1,M=4e5 1;
int n,m,hash[M],ans[N],tot;
struct Node {
int x,y,z,id;
bool t;
};
Node a[N];
inline bool cmp1(const Node &p1,const Node &p2) {
if(p1.x==p2.x) {
if(p1.y==p2.y) {
if(p1.z==p2.z) return p1.t<p2.t;
return p1.z>p2.z;
}
return p1.y>p2.y;
}
return p1.x>p2.x;
}
inline bool cmp2(const Node &p1,const Node &p2) {
if(p1.y==p2.y) {
if(p1.z==p2.z) return p1.t<p2.t;
return p1.z>p2.z;
水果蛋糕图片大全}
return p1.y>p2.y;
}
class FenwickTree {
private:
int val[M];
任职以来工作总结
int lowbit(const int &x) const {
return x&-x;
}
public:麻仁润肠丸
void modify(int p,const int &x) {
for(;p;p-=lowbit(p)) val[p] =x;
}
int query(int p) const {
int ret=0;
for(;p<=tot;p =lowbit(p)) ret =val[p];
return ret;
}
};
FenwickTree t;
void cdq(const int &b,const int &e) {
if(b==e) return;
const int mid=(b e)>>1;
cdq(b,mid);
cdq(mid 1,e);
int p=b,q=mid 1;
for(;q<=e;q ) {
if(!a[q].t) continue;
for(;p<=mid&&a[p].y>=a[q].y;p ) {
大水坑镇if(!a[p].t) t.modify(a[p].z,1);
}
ans[a[q].id] =t.query(a[q].z);
}
while(--p>=b) {
if(!a[p].t) t.modify(a[p].z,-1);
}
std::inplace_merge(&a[b],&a[mid] 1,&a[e] 1,cmp2);离远
小学五年级数学课本}
int main() {
欢乐颂2电视剧
n=getint(),m=getint();
for(register int i=1;i<=n;i ) {
a[i].x=getint();
a[i].y=getint();
a[i].z=a[i].x a[i].y;
a[i].id=m i;
a[i].t=fal;
}
for(register int i=1;i<=m;i ) {
a[i n].x=getint();
a[i n].y=getint();
a[i n].z=getint();
a[i n].id=i;
a[i n].t=true;
}
for(register int i=1;i<=n m;i ) hash[ tot]=a[i].z;
std::sort(&hash[1],&hash[tot] 1);
for(register int i=1;i<=n m;i ) {
a[i].z=std::lower_bound(&hash[1],&hash[tot] 1,a[i].z)-hash; }
std::sort(&a[1],&a[n m] 1,cmp1);
cdq(1,n m);
for(register int i=1;i<=m;i ) {
printf("%d\n",ans[i]);
}
return 0;
}
属马一生的命运来源:/content-4-144501.html