【JZOJ4807】破解
来源:互联网 发布:淘宝网开店 编辑:程序博客网 时间:2024/05/16 06:15
Description
Solution
一看到这道题就想到了差分,那么就是把右端点+1。
然后就把一些无用的区间给除掉,比如说有一些区间首尾相接然后拼成的大区间已经出现过了,那么这个大区间就没有用了。
把这个转成图论的形式。
把l向r连边,然后有一个大小为size的联通块有用的边只有size-1,那么方案数就乘上
这个用并查集来搞联通块就好了。
然后还要注意一下要离散化,不然就会爆掉。
Code
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#define fo(i,a,b) for(i=a;i<=b;i++)using namespace std;typedef long long ll;const int maxn=200007,mo=1000000007;ll i,j,k,t,ans,cas,r,l,u,v,tot;ll n,m;ll f[maxn],size[maxn],num;ll er[maxn];struct node{ int l,r;}wen[maxn];struct nod{ int a,b,c;}a[maxn*2];ll gf(ll x){ if(!f[x])return x; f[x]=gf(f[x]); return f[x];}bool cmp(nod x,nod y){return x.a<y.a;}int main(){// freopen("fan.in","r",stdin); er[0]=1; fo(i,1,maxn-1)er[i]=er[i-1]*2%mo; for(scanf("%lld",&cas);cas;cas--){ scanf("%lld%lld",&n,&m); tot=0; fo(i,1,m){ scanf("%lld%lld",&wen[i].l,&wen[i].r);wen[i].r++; a[++tot].a=wen[i].l;a[tot].b=1,a[tot].c=i; a[++tot].a=wen[i].r;a[tot].b=2,a[tot].c=i; } sort(a+1,a+1+tot,cmp); fo(i,1,tot){ if(a[i].a!=a[i-1].a){ num++; } if(a[i].b==1)wen[a[i].c].l=num; else wen[a[i].c].r=num; } fo(i,1,num)f[i]=0,size[i]=1; fo(i,1,m){ u=gf(wen[i].l),v=gf(wen[i].r); if(u!=v){ f[v]=u; size[u]+=size[v]; } } ans=1; fo(i,1,num)if(!f[i])ans=ans*er[size[i]-1]%mo; printf("%lld\n",ans); }}
2 0
- 【JZOJ4807】破解
- 【JZOJ4807】破解
- 【JZOJ4807】破解
- 【改自CC_CHSEQ22】【JZOJ4807】破解 题解
- 破解
- 破解
- 破解
- 破解
- 破解
- 破解
- 破解
- 破解
- 破解
- 破解天下,天下破解
- 破解MD5
- cmos破解
- 软件破解
- 破解JIRA
- 最简单的java中TCP的网络编程
- 文章标题
- PAT_A 1118. Birds in Forest (25)
- 四旋翼飞行器——坐标变换
- 使用JDBC连接数据库
- 【JZOJ4807】破解
- 10.4
- MySql 学习笔记三:常用SQL优化
- 高精度阶乘
- Android gradle实用教程(一):Android studio中的gradle
- linux环境下的vi编辑器详解(一)
- jquery中事件
- android中xml文件的作用及解释
- LinearRegressionWithSGD 问题