HDU 5603 the soldier of love (线段树)
来源:互联网 发布:网络学习论坛发帖 编辑:程序博客网 时间:2024/04/29 17:18
分析:很经典的区间覆盖问题,给
如果要完全覆盖,那么
此题离线做就可以了。
代码:
#include <bits/stdc++.h>using namespace std;#define FOR(i,x,y) for(int i = x;i < y;++ i)#define IFOR(i,x,y) for(int i = x;i > y;-- i)#define fi first#define se second#define pb push_back #define mp make_pair #define SZ(x) ((int)(x.size()))#define sc(x) scanf("%d",&x)#define sc2(x,y) scanf("%d%d",&x,&y)#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)#define lrt rt<<1#define rrt rt<<1|1#define lson rt<<1,l,mid#define rson rt<<1|1,mid,rtypedef long long LL;typedef vector <int> VI;typedef pair <int,int> PII;const int inf = 1000010;const int maxn = 300030;int n,m;struct Node{ int l,r; int id; Node() {} Node(int x,int y,int z) : l(x),r(y),id(z) {} bool operator < (const Node& rhs) const{ if(r == rhs.r) return id > rhs.id; return r < rhs.r; }}node[maxn<<1];int c[inf];int lowbit(int x) {return x&-x;}void modify(int x,int val){ for(;x < inf;x += lowbit(x)) c[x] += val;} int query(int x){ int ans = 0; for(;x;x -= lowbit(x)) ans += c[x]; return ans;}int ans[maxn];int main(){ //freopen("in.txt","r",stdin); while(~sc2(n,m)){ FOR(i,0,inf) c[i] = 0; int cnt = 0; FOR(i,0,n){ int l,r; sc2(l,r); node[cnt++] = Node(l,r,0); } FOR(i,1,m+1){ int k,r; sc(k); int last = 0; FOR(j,0,k){ sc(r); node[cnt++] = Node(last,r,i); last = r; } node[cnt++] = Node(last,inf-1,i); } sort(node,node+cnt); memset(ans,0,sizeof(ans)); FOR(i,0,cnt){ //printf("%d %d %d\n",node[i].l,node[i].r,node[i].id); if(!node[i].id){ modify(node[i].l,1); } else{ ans[node[i].id] += query(inf-1)-query(node[i].l); //printf("ans : %d %d ",query(inf-1),query(node[i].l)); //printf("%d\n",ans[node[i].id]); } } FOR(i,1,m+1){ printf("%d\n",n-ans[i]); } } return 0;}
0 0
- HDU 5603 the soldier of love (线段树)
- hdu 5603 the soldier of love
- HDU 5603 the soldier of love(BIT)
- HDU 5603/BC 67D the soldier of love
- hdu5603the soldier of love
- hdu 5176 The Experience of Love(并查集)
- hdu 5176 The Experience of Love
- hdu 5381 The sum of gcd(线段树+gcd)
- hdu 1823 Luck and Love(线段树)
- hdu 1823 Luck and Love(二维线段树)
- hdu - 1823 - Luck and Love(线段树)
- HDU 1823 Luck and Love 二维线段树(树套树)
- HDU 1832 Luck and Love (二维线段树)
- hdu 1823 Luck and Love (二维树套树线段树)
- HDU 1823 Luck and Love (二维线段树模板)
- hdu-1823-Luck and Love-(二维线段树)
- HDU 1832:Luck and Love(二维线段树)
- the code of love
- 全局获取Context的方法
- python build-in functions
- 【C++ STL应用与实现】17: 如何使用迭代器辅助函数
- IOS-Label
- 重置 Mac 上的系统管理控制器 (SMC)
- HDU 5603 the soldier of love (线段树)
- GreenDao 教程
- 本地通知
- MyBatis Generator 详解
- Fragment不同操作的生命周期
- Linux netstat命令详解
- 【跟我学spring 4.0 】之第三节-bean的配置
- linux service命令
- MySQL常用字符集