考虑到正向求解困难,于是正难则反。

那么实际上对于 \(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 题解的更多相关文章

  1. codeforcess水题100道

    之所以在codeforces上找这100道水题的原因是为了巩固我对最近学的编程语言的掌握程度. 找的方式在codeforces上的PROBLEMSET中过的题最多的那些题里面出现的最前面的10个题型, ...

  2. 题解 CF546B Soldier and Badges

    CF546B Soldier and Badges 简单的贪心qwq 排个序,如果当前数与之前的数相重,已经用过,则加到一个之前没有用过的数 #include<cstdio> #inclu ...

  3. 题解 CF546C 【Soldier and Cards】

    思路 是一道水题,可以用队列+模拟来写,注意不要拿完队列中的元素! 代码 #include<iostream> #include<cstdio> #include<que ...

  4. HDU 5603 the soldier of love 离线+树状数组

    这是bestcorder 67 div1 的1003 当时不会做 看了赛后官方题解,然后翻译了一下就过了,而且速度很快,膜拜官方题解.. 附上官方题解: the soldier of love 我们注 ...

  5. 2017 google Round C APAC Test 题解

    题解参考网上的答案,以及我自己的想法. 主要参考网站:http://codeforces.com/blog/entry/47181,http://codeforces.com/blog/entry/4 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

  10. ACM ICPC 2018 青岛赛区 部分金牌题题解(K,L,I,G)

     目录: K Airdrop I Soldier Game L Sub-cycle Graph G Repair the Artwork ———————————————————— ps:楼主脑残有点严 ...

随机推荐

  1. Postman 汉化教程

    Postman 汉化教程(Postman中文版) 迷恋自留地 postman官网下载地址 https://www.postman.com/downloads/ postman汉化包 https://g ...

  2. Oracle.DataAccess.Client.OracleException: 提供程序与此版本的 Oracle 客户机不兼容

    背景:进行程序部署,客户机上原有oracle客户端的版本为2.113.1.0(以下简称113),而数据库.开发机和其他客户机上均采用的2.112.1.0(以下简称112)客户端,所以进行了替换. 卸载 ...

  3. C/C++实例汇集(1)

    1.用代码判断一个系统是16位系统还是32位系统? 以下是几种常见编程语言中判断系统是 16 位还是 32 位的代码示例 C语言: #include <stdio.h> int main( ...

  4. Flutter Package: flutter_animate

    Flutter package: flutter_animate A performant library that makes it simple to add almost any kind of ...

  5. PDF 的一些资料

    PDF Succinctly https://www.syncfusion.com/ebooks/pdf Create PDFs in ASP.NET - getting started with i ...

  6. jdk安装-windows和linux

    下载:见此博客https://www.cnblogs.com/zn19961006/p/12857930.html 一.windows安装 1.很简单,运行exe,然后一直下一步 选安装路径. 注意: ...

  7. java-信息安全(二十)国密算法 SM1,SM2,SM3,SM4

    一.概述 国密即国家密码局认定的国产密码算法.主要有SM1,SM2,SM3,SM4.密钥长度和分组长度均为128位.目前主要使用公开的SM2.SM3.SM4三类算法,分别是非对称算法.哈希算法和对称算 ...

  8. CoverageBuilder

    public CoverageBuilder(String gitPath, String newBranchName, String oldBranchName, List<String> ...

  9. Qt编写安防视频监控系统68-兼容Qt4到Qt6

    一.前言 为了从Qt4.7兼容到Qt6.2及后续版本,着实花了不少精力,前提也是对自定义控件大全和各种跨平台的轮子组件全部做成了兼容Qt4到Qt6,这样只剩下UI这块需要兼容就好办多了,各个击破战略, ...

  10. [转]CFLAGS、CXXFLAGS、FFLAGS、FCFLAGS、LDFLAGS、LD_LIBRARY_PATH区别

    CFLAGS.CXXFLAGS.FFLAGS.FCFLAGS.LDFLAGS.LD_LIBRARY_PATH区别 Linux笔记之LD_LIBRARY_PATH详解 翻译 搜索 复制