[HDU5603] the soldier of love 题解
考虑到正向求解困难,于是正难则反。
那么实际上对于 \(a_i\) 和 \(a_{i+1}\) 来说,它们给答案的贡献就是满足 \(l_j>a_i,r_j<a_{i+1}\) 的区间数量。
那么就是经典转化了。直接转换为二维数点问题即可。时间复杂度 \(O(tn\log V)\),离散化可以将 \(\log V\) 转化为 \(\log n\)。
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+5;
const int M=1e6+5;
const int K=2e6+5;
struct que{
int x,y,id,o;
}q[K];int n,m,k;
int c[M],as[N];
int cmp(que x,que y){
if(x.x!=y.x) return x.x<y.x;
return (x.y!=y.y)?x.y<y.y:x.id<y.id;
}void add(int x){
for(;x<=1e6;x+=x&-x) c[x]++;
}int sum(int x){
int re=0;
for(;x;x-=x&-x) re+=c[x];
return re;
}void solve(){
for(int i=1;i<=n;i++){
int l,r;cin>>l>>r;
q[++k]={l,r,0,0};
}for(int i=1,x;i<=m;i++){
int num,lst;
cin>>num,x=as[i]=0;
while(num--){
lst=x,cin>>x;
q[++k]={lst,x-1,i,-1};
if(lst) q[++k]={lst,lst-1,i,1};
}q[++k]={x,1e6,i,-1};
if(x) q[++k]={x,x-1,i,1};
q[++k]={1e6+1,1e6,i,1};
}sort(q+1,q+k+1,cmp);
for(int i=1;i<=k;i++){
if(!q[i].x) continue;
if(!q[i].id) add(q[i].y);
else as[q[i].id]+=q[i].o*sum(q[i].y);
}for(int i=1;i<=m;i++)
cout<<n-as[i]<<"\n";
for(int i=1;i<=1e6;i++) c[i]=0;
}int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
while(cin>>n>>m) k=0,solve();
return 0;
}
[HDU5603] the soldier of love 题解的更多相关文章
- codeforcess水题100道
之所以在codeforces上找这100道水题的原因是为了巩固我对最近学的编程语言的掌握程度. 找的方式在codeforces上的PROBLEMSET中过的题最多的那些题里面出现的最前面的10个题型, ...
- 题解 CF546B Soldier and Badges
CF546B Soldier and Badges 简单的贪心qwq 排个序,如果当前数与之前的数相重,已经用过,则加到一个之前没有用过的数 #include<cstdio> #inclu ...
- 题解 CF546C 【Soldier and Cards】
思路 是一道水题,可以用队列+模拟来写,注意不要拿完队列中的元素! 代码 #include<iostream> #include<cstdio> #include<que ...
- HDU 5603 the soldier of love 离线+树状数组
这是bestcorder 67 div1 的1003 当时不会做 看了赛后官方题解,然后翻译了一下就过了,而且速度很快,膜拜官方题解.. 附上官方题解: the soldier of love 我们注 ...
- 2017 google Round C APAC Test 题解
题解参考网上的答案,以及我自己的想法. 主要参考网站:http://codeforces.com/blog/entry/47181,http://codeforces.com/blog/entry/4 ...
- Codeforces Round #304 (Div. 2) E. Soldier and Traveling 最大流
题目链接: http://codeforces.com/problemset/problem/546/E E. Soldier and Traveling time limit per test1 s ...
- Codeforces Round #304 (Div. 2) D. Soldier and Number Game 数学 质因数个数
D. Soldier and Number Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...
- Codeforces Round #304 (Div. 2) C. Soldier and Cards 水题
C. Soldier and Cards Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/546 ...
- Codeforces Round #304 (Div. 2) B. Soldier and Badges 水题
B. Soldier and Badges Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/54 ...
- ACM ICPC 2018 青岛赛区 部分金牌题题解(K,L,I,G)
目录: K Airdrop I Soldier Game L Sub-cycle Graph G Repair the Artwork ———————————————————— ps:楼主脑残有点严 ...
随机推荐
- fastadmin-表单使用
1.日期时间 在FastAdmin中的日期时间组件采用的是Bootstrap-datetimepicker插件,官方文档:Bootstrap-datetimepicker官方教程 日期时间格式设置:设 ...
- Javascript 构造函数和类
1.构造函数 含义:所谓"构造函数",就是专门用来生成实例对象的函数.它就是对象的模板,描述实例对象的基本结构.一个构造函数,可以生成多个实例对象,这些实例对象都有相同的结构 写法 ...
- 在Python工具箱中,创建对应子工具集
目录 问题描述 实现方法 问题描述 在Pro中,新建自定义工具箱后,直接通过操作可以添加工具集. 但是新建python工具箱后,却没有新建的操作.因为python工具箱的对象定义,都是在脚本中定义的, ...
- [Mybatis Plus]lambdaQueryWrapper和QueryWrapper的选择
结论 更推荐使用:LambdaQueryWrapper QueryWrapper:灵活但是不够类型安全 LambdaQueryWrapper:安全 分析 在MyBatis-Plus中,QueryWra ...
- Could not retrieve transation read-only status server 的解决办法
问题描述: 在项目开发的过程中,使用Hibernate的ORM进行建表时,出现 " Could not retrieve transation read-only status server ...
- Spring boot 配置文件位置
Spring boot 的Application.properties 配置文件可以是以下几个地方:classpath:/,classpath:/config/,file:./,file:./conf ...
- Datawhale冬令营第二期!😀Task 1
Datawhale冬令营第二期-Task1:动手体验AI辅助编程:番茄钟 对应链接:https://www.datawhale.cn/activity/116/23/94?rankingPage=1 ...
- ESLint is disabled since its execution has not been approved or denied yet
VS Code 装好ESLint 插件报黄线的问题,具体解决方法如下所示: ESLint is disabled since its execution has not been approved o ...
- WebClient 用法小结
进来的项目中要实现能够在windows service中调用指定项目的链接页面.由于访问页面时候使用的是ie浏览器或其他浏览器,所以想起用webclient类. 如果只想从特定的URI请求文件,则使用 ...
- 基于开源IM即时通讯框架MobileIMSDK:RainbowChat v10.0版已发布
关于MobileIMSDK MobileIMSDK 是一套专门为移动端开发的开源IM即时通讯框架,超轻量级.高度提炼,一套API优雅支持UDP .TCP .WebSocket 三种协议,支持iOS.A ...