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分治即可。chong
源代码:
#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;
};
consist
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;
halliburtonreturn p1.z>p2.z;
}
return p1.y>p2.y;
}
class FenwickTree {
private:fen
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 {
rulerint 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() {
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;
special
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();
china sourcing
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;
ara是什么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 ) {
tudoprintf("%d\n",ans[i]);
}
return 0;
}
来源:/content-4-144501.html