csps模拟测试74梦境,玩具,飘雪圣域题解
题面:https://www.cnblogs.com/Juve/articles/11679226.html
梦境:
其实还是挺水的,排序错了过不了样例,打了个二分图匹配就跑了
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#define int long long
using namespace std;
const int MAXN=2e5+;
int n,m,b[MAXN],ans=;
struct node{
int l,r;
friend bool operator < (node p,node q){
return p.r==q.r?p.l<q.l:p.r<q.r;
}
}a[MAXN];
multiset<int>s;
signed main(){
scanf("%lld%lld",&n,&m);
for(int i=;i<=n;++i)
scanf("%lld%lld",&a[i].l,&a[i].r);
sort(a+,a+n+);
for(int i=;i<=m;++i){
scanf("%lld",&b[i]);
s.insert(b[i]);
}
for(int i=;i<=n;++i){
multiset<int>::iterator it=s.lower_bound(a[i].l);
if(it!=s.end()&&(*it)<=a[i].r){
++ans;
s.erase(it);
}
}
printf("%lld\n",ans);
return ;
}
玩具:神仙dp,
颓的题解和方程
令f[i][j]表示有i个点的树,深度不超过j的概率,g[i][j]表示有i个点的森林,深度不超过j的概率,
f[i][j]=g[i-1][j-1](j!=0) f[0][1]=1;
$g[i][j]=\sum\limits_{k=1}^{i}f[k][j]*g[i-k][j]*inv[i]$
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define int long long
using namespace std;
const int MAXN=;
int n,mod,inv[MAXN],ans=,g[MAXN][MAXN],f[MAXN][MAXN];
signed main(){
scanf("%lld%lld",&n,&mod);
inv[]=inv[]=;
for(int i=;i<=n;++i) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
for(int i=;i<=n;++i) g[][i]=;
for(int i=;i<=n;++i){
for(int j=;j<=n;++j){
if(j) f[i][j]=g[i-][j-];
else if(i==) f[i][j]=;
for(int k=;k<=i;++k)
g[i][j]=(g[i][j]+1ll*f[k][j]*g[i-k][j]%mod*inv[i]%mod)%mod;
}
}
for(int i=;i<=n;++i){
ans=(ans+1ll*(f[n][i]-f[n][i-]+mod)%mod*i%mod)%mod;
}
printf("%lld\n",ans);
return ;
}
飘雪圣域:
主席树,树状数组,莫队都可以过
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define re register
using namespace std;
const int MAXN=2e5+5;
int n,q;
vector<int>mp[MAXN];
int tot=0,root[MAXN];
struct node{
int ls,rs,val;
}tr[MAXN*30];
void build(int &k,int l,int r){
k=++tot;
if(l==r) return ;
int mid=(l+r)>>1;
build(tr[k].ls,l,mid);
build(tr[k].rs,mid+1,r);
}
void insert(int &now,int pre,int l,int r,int pos){
now=++tot;
tr[now]=tr[pre],++tr[now].val;
if(l==r) return ;
int mid=(l+r)>>1;
if(pos<=mid) insert(tr[now].ls,tr[pre].ls,l,mid,pos);
else insert(tr[now].rs,tr[pre].rs,mid+1,r,pos);
}
int query(int x,int y,int l,int r,int opl,int opr){
if(opl<=l&&r<=opr) return tr[y].val-tr[x].val;
int mid=(l+r)>>1,res=0;
if(opl<=mid) res+=query(tr[x].ls,tr[y].ls,l,mid,opl,opr);
if(opr>mid) res+=query(tr[x].rs,tr[y].rs,mid+1,r,opl,opr);
return res;
}
signed main(){
scanf("%d%d",&n,&q);
for(int i=1,u,v;i<n;++i){
scanf("%d%d",&u,&v);
mp[min(u,v)].push_back(max(u,v));
}
for(int i=1;i<=n;++i){
root[i]=root[i-1];
int N=mp[i].size();
for(int j=0;j<N;++j){
insert(root[i],root[i],1,n,mp[i][j]);
}
}
while(q--){
int l,r;
scanf("%d%d",&l,&r);
printf("%d\n",r-l+1-query(root[l-1],root[r],1,n,l,r));
}
return 0;
}
csps模拟测试74梦境,玩具,飘雪圣域题解的更多相关文章
- [CSP-S模拟测试74]题解
A.梦境 如果不用去重一定要用Multiset……挂30分算是出题人手下留情了. 贪心.把点排序,区间按右端点递增排序.依次考虑每个区间,取能选的最靠左的点即可.multiset维护. #includ ...
- csp-s模拟测试61砖块, 数字,甜圈题解
题面:https://www.cnblogs.com/Juve/articles/11626350.html 砖块: 直接模拟即可,map统计被覆盖的次数 #include<iostream&g ...
- csp-s模拟测试56Merchant, Equation,Rectangle题解
题面:https://www.cnblogs.com/Juve/articles/11619002.html merchant: 二分答案,贪心选前m大的 但是用sort复杂度不优,会T掉 我们只是找 ...
- csp-s模拟测试54x,y,z题解
题面:https://www.cnblogs.com/Juve/articles/11606834.html x: 并差集,把不能分到两个集合里的元素和并到一起,设连通块个数为cnt,则答案为:$2^ ...
- csp-s模拟测试53u,v,w题解
题面:https://www.cnblogs.com/Juve/articles/11602450.html u: 用差分优化修改 二维差分:给(x1,y1),(x2,y2)加上s: $d[x1][y ...
- csp-s模拟测试51(b)attack,tree题解
题面:https://www.cnblogs.com/Juve/articles/11598286.html attack: 支配树裸题? 看一下支配树是什么: 问题:我们有一个有向图(可以有环),定 ...
- csp-s模拟测试99
csp-s模拟测试99 九九归一直接爆炸. $T1$一眼板子. $T2$一眼语文题(语文的唯一一次$120+$是给模拟出来的可知我的语文能力). $T3$一眼普及题. ?? Hours Later 板 ...
- csp-s模拟测试98
csp-s模拟测试98 $T1$??不是我吹我轻松手玩20*20.$T2$装鸭好像挺可做?$T3$性质数据挺多提示很明显? $One$ $Hour$ $Later$ 这$T1$什么傻逼题真$jb$难调 ...
- csp-s模拟测试97
csp-s模拟测试97 猿型毕露.水题一眼秒,火题切不动,还是太菜了. $T1$看了一会儿感觉$woc$期望题$T1??$假的吧??. $T2$秒. $T3$什么玩意儿. 40 01:24:46 00 ...
随机推荐
- python array基本操作一
一.排序 a = [2,3,4,1] b = np.argsort(a) # out:[3 0 1 2] # 输出:是一个数组,是按元素递增顺序的索引 二.查找 1.最大值及其索引 b = max(a ...
- EXE 和 SYS 信息交互
操了,分发函数少发一个,让我白调了两个多小时.
- 数据库MySQL--基础查询
1.查询字段 查询表某字段:select 字段名 from 表名: 查询表内所有字段:select * from 表名: (当字段和关键字重名是用( ` )着重号区分 ) 2.查询常量值 select ...
- java继承,多态
子类继承父类,用父类去接收子类,其实我觉得用父类,子类来形容继承关系是不恰当的,比如再发生多态的时候,Car c = new W();w是大众,你能说Car 和W是父子关系吗,我觉得用所属关系类描述可 ...
- VBS脚本完美实现开机延时启动
目录 概述 vbs内容示例: vbs示例语句分析 自定义vbs脚本 一些问题和解决方法 概述 系统开机时,顺带自动启动了不少驱动程序,使得电脑开机后鼠标要呆滞许久.为了加快windows的开机速度 ...
- jquery高级编程学习
jquery高级编程 第1章.jQuery入门 类型检查 对象 类型检查表达式 String typeof object === "string" Number typeof ob ...
- kaptcha 实现验证码
依赖 <dependency> <groupId>com.github.penggle</groupId> <artifactId>kaptcha< ...
- 阿里云图数据库GraphDB上线,助力图数据处理
GraphDB简介 GraphDB图数据库适用于存储,管理,查询复杂并且高度连接的数据,图库的结构特别适合发现大数据集下数据之间的共性和特性,特别善于释放蕴含在数据关系之间的巨大价值.GraphDB引 ...
- dos中文乱码怎么办?
最简单的方法: 通过 chcp命令改变代码页,UTF-8的代码页为65001 即chcp 65001 chcp 65001 就是换成UTF-8代码页 chcp 936 可以换回默认的GBK chcp ...
- duilib教程之duilib入门简明教程12.简单控件介绍
前面的教程应该让大家对duilib的整体有所映像了,下面就来介绍下duilib具体控件的使用. 由于官方没有提供默认的控件样式,所以我就尽量使用win7或者XP自带的按钮样式了,虽然界面比较土鳖 ...