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 ...
随机推荐
- KNN与决策树
KNN: 就是计算特征之间的距离,某一个待预测的数据分别与已知的所有数据计算他们之间的特征距离,选出前N个距离最近的数据,这N个数据中哪一类的数据最多,就判定待测数据归属哪一类. 假如N=3,图中待测 ...
- iBATIS存储过程
使用iBATIS配置来调用存储过程.为了理解这一章,首先需要了解我们是如何在MySQL中创建一个存储过程. 在继续对本章学习之前,可以通过MySQL存储过程. 我们已经在MySQL下有EMPLOYEE ...
- k8s 映射 外部服务
把外部的服务,通过创建service和endpoint,把它映射到k8s内部来使用. 操作步骤: 在10.0.0.13上安装数据库 yum install mariadb-server -y syst ...
- Bootstrap3的响应式缩略图幻灯轮播效果设计
在线演示1 本地下载 HTML <div class="container"> <div class="col-md-12"> &l ...
- PyTorch中,关于model.eval()和torch.no_grad()
一直对于model.eval()和torch.no_grad()有些疑惑 之前看博客说,只用torch.no_grad()即可 但是今天查资料,发现不是这样,而是两者都用,因为两者有着不同的作用 引用 ...
- Python3中string内置参数
说明: 使用ipython查看python3的内置函数 ,只需要输入字符串按两下tab键 capitalize():将字符串中第一个字符大写 casefold:将字符串中的所有大写字母转为小写 cen ...
- Lucene 搜索方式
Lucene 的搜索方式包括:词项查询(TermQuery) / 布尔查询(BooleanQuery) / 短语查询(PhraseQuery) / 范围查询(RangeQuery) / 百搭查询(Wi ...
- Deep Dive into Neo4j 3.5 Full Text Search
In this blog we will go over the Full Text Search capabilities available in the latest major release ...
- 6.RDD算子实战
from pyspark import SparkContext,SparkConf import sys if __name__ == '__main__': if len(sys.argv) != ...
- Windows tasklist
TASKLIST [/S system [/U username [/P [password]]]] [/M [module] | /SVC | /V] [/FI filter] [/ ...