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 ...
随机推荐
- A1016 Phone Bills (25 分)
A long-distance telephone company charges its customers by the following rules: Making a long-distan ...
- shell 单引号&双引号的使用
使用双引号: shell> X='parameter' shell> echo "Hello $X" Hello parameter 单引号中嵌套单引号: shell& ...
- 极限学习机(Extreme Learning Machine)学习笔记
最近研究上了这个一个东西--极限学习机. 在很多问题中,我大多会碰到两个问题,一个是分类,另一个就是回归.简单来说,分类是给一串数打个标签,回归是把一串数变为一个数. 在这里我们需要处理的数据一般维度 ...
- EF 如何更新多对多关系的实体
ctx.Entry(user).Collection(t => t.UserPrivileges).Load(); Come form:https://www.thereformedprogra ...
- Mysql ---Sqlserver数据迁移到Mysql(Mysql建表迁移数据)
1 试用了MysqlWorkBench的数据迁移功能 以为能实现:建立跟Sqlserver一样的表结构和视图的功能,sqlserver的数据迁移到mysql 实际上发现:即使勾选了表和视图,实际上却只 ...
- 使用ajax怎么请求跨域资源
1.ajax中添加“xhrFields”和“crossDomain”,如: $.ajax({ url: url, data: data, type: "post", xhrFiel ...
- csp-s模拟9697题解
题面:https://www.cnblogs.com/Juve/articles/11790223.html 96: 刚一看以为是水题,直接等差数列求和就好了,然后发现模数不是质数,还要1e18*1e ...
- Docker系列(三):Docker自定义容器镜像
将容器编程镜像: docker commit [repo:tag] 网上有这句话:当我们在制作自己的镜像的时候,会在container中安装一些工具.修改配置,如果不做commit保存 起来,那么co ...
- 浅析ES的_source、_all、store、index
Elasticsearch中有大量关键概念容易混淆,对于初学者来说是噩梦: _source字段里存储了什么? index属性的作用是什么? 何时应该开启_all字段? store属性和_source字 ...
- 树链剖分(模板) 洛谷P3384
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #d ...