loj6270
#6270. 数据结构板子题




sol:对于一个询问L,R,Limit,答案就是所有长度小于R-l+1的线段-长度小于Limit的线段-左端点在L左边的线段-右端点在R右边的线段,求这个东西
后面两个东西可以十分容易的用两棵树状数组维护,但是直接搞得话长度小于Limit且不在区间[L,R]中的区间会被减两遍,把他们加上去即可
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline char gc(){
static char buf[],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,,,stdin),p1==p2)?EOF:*p1++;
}
#define getchar gc
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,Q,ans[N];
struct Question
{
int l,r,Down,Id;
}Ques[N];
vector<int>Limit1[N],Limit2[N];
struct Xianduan
{
int l,r,Len;
inline bool operator<(const Xianduan &tmp)const
{
return Len<tmp.Len;
}
}Line[N<<];
struct BIT
{
int S[N];
#define lowbit(x) ((x)&(-x))
inline void Ins(int x)
{
for(;x<=n;x+=lowbit(x))
{
++S[x];
}
}
inline int Que(int x)
{
int Sum=;
for(;x;x-=lowbit(x))
{
Sum+=S[x];
}
return Sum;
}
}T1,T2;
int main()
{
register int i,j;
R(n); R(Q);
for(i=;i<=n;i++)
{
R(Line[i].l); R(Line[i].r);
Line[i].Len=Line[i].r-Line[i].l;
}
sort(Line+,Line+n+);
for(i=;i<=Q;i++)
{
R(Ques[i].l); R(Ques[i].r); R(Ques[i].Down); Ques[i].Id=i;
if(Ques[i].r-Ques[i].l>=Ques[i].Down)
{
Limit1[Ques[i].Down-].push_back(i);
Limit2[Ques[i].r-Ques[i].l+].push_back(i);
}
}
register int Pos=,tot=;
for(i=;i<=n;i++) //枚举线段长度
{
while(Pos<=n&&Line[Pos].Len==i)
{
T1.Ins(Line[Pos].l);
T2.Ins(Line[Pos].r);
++tot; ++Pos;
}
for(j=;j<Limit1[i].size();j++)
{
register int o=Limit1[i][j];
ans[o]=ans[o]-tot+T1.Que(Ques[o].l-)+(tot-T2.Que(Ques[o].r));
}
for(j=;j<Limit2[i].size();j++)
{
register int o=Limit2[i][j];
ans[o]=ans[o]+tot-T1.Que(Ques[o].l-)-(tot-T2.Que(Ques[o].r));
}
}
for(i=;i<=Q;i++) Wl(ans[i]);
return ;
}
/*
input
5 5
1 2
1 3
2 3
2 4
2 5
1 5 1
1 4 1
1 5 2
2 5 2
1 5 3
output
5
4
3
2
1
*/
loj6270的更多相关文章
随机推荐
- C学习笔记-一些知识
memset可以方便的清空一个结构类型的变量或数组. 如: struct sample_struct { ]; int iSeq; int iType; }; 对于变量 struct sample_s ...
- 【vue】vue-router路径无法正确跳转
具体描述:vue项目,npm run build时点击路由切换,第一次点击没问题,再点不会切换报错如下图 原因分析:vue-router配置路由,当代码分割和懒加载时,由于webpack配置不当,导致 ...
- Apache Commons Codec的Base64加解密库
下载地址:http://commons.apache.org/proper/commons-codec/download_codec.cgi import org.apache.commons.cod ...
- MRO C3算法 super的运用
-------------态度决定成败,无论情况好坏,都要抱着积极的态度,莫让沮丧取代热心.生命可以价值极高,也可以一无是处,随你怎么去选择.# --------------------------- ...
- 自定义分页及Cookie、Session机制
分页 自定义分页 data = [] , ): tmp = {"id": i, "name": "alex-{}".format(i)} d ...
- Python-SMTP发送邮件(HTML、图片、附件)
前言: SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式. 一.Python发送HTML ...
- java 类与类,类与接口 ,接口与接口关系
类: 生活中类是人们对客观事物不断认识而产生的抽象概念,而对象则是现实生活中的一个个实体 面向对象程序设计中,对象是程序的基本单位,相似的对象像变量和类型的关系一样归并到一类,所以,并不先具体地定义对 ...
- 广州商学院16级软工一班&二班-第二次作业成绩
作业地址 https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2097 https://edu.cnblogs.com/campus/gzc ...
- Git远程分支的回退
下午发现上午提交的一个版本有问题,在回退本地分支后,发现还必须要回退远程分支的版本.网上查找到的资料如下: #新建old_master分支做备份 git branch old_master #push ...
- PAT L2-009 抢红包
https://pintia.cn/problem-sets/994805046380707840/problems/994805066890854400 没有人没抢过红包吧…… 这里给出N个人之间互 ...