B:注意到nc/2<=m,于是以c/2为界决定数放在左边还是右边,保证序列满足性质的前提下替换掉一个数使得其更靠近边界即可。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define P 1000000007
#define N 1010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m,c,a[N],head,tail;
signed main()
{
n=read(),m=read(),c=read();head=1,tail=n;
while (head<=tail)
{
int x=read();
if (x<=c/2)
{
bool flag=0;
for (int i=1;i<head;i++) if (a[i]>x) {cout<<i<<endl;a[i]=x;flag=1;break;}
if (!flag) cout<<head<<endl,a[head++]=x;
}
else
{
bool flag=0;
for (int i=n;i>tail;i--) if (a[i]<x) {cout<<i<<endl;a[i]=x;flag=1;break;}
if (!flag) cout<<tail<<endl,a[tail--]=x;
}
}
for (int i=1;i<=n;i++) cout<<a[i]<<' ';cout<<endl;
return 0;
//NOTICE LONG LONG!!!!!
}

  D:相当于求有多少个-1 0 1构成的序列满足前缀和始终不小于0且总和在[l,r]中。这个前缀和限制非常容易想到卡特兰数,考虑类似的推式子方法,写出dp式子然后造一个网格图,如果没有前缀和限制只要暴力枚举1的个数算一下组合数即可,而所有不满足前缀和限制的方案与从边界走过来的方案一一对应,于是减掉就可以了(具体见NOI2018冒泡排序?)。于是只剩下模数不是质数的问题,对其分解质因数,然后阶乘及其逆元拆成两部分,与模数互质部分直接处理,剩下的记录每个质因子幂次做前缀和即可求组合数。最坑的一点大概是因为模数可达2e9无法避免爆int。为什么这个小水题过的人这么少

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define int long long
#define N 100010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,P,l,r,fac[N],inv[N],sum[N][30],p[30],t;
void inc(int &x,int y){x+=y;if (x>=P) x-=P;}
void exgcd(int &x,int &y,int a,int b)
{
if (b==0)
{
x=1,y=0;
return;
}
exgcd(x,y,b,a%b);
int t=x;x=y;y=t-a/b*x;
}
int Inv(int a)
{
int x,y;
exgcd(x,y,a,P);
return (x%P+P)%P;
}
int ksm(int a,int k)
{
int s=1;
for (;k;k>>=1,a=1ll*a*a%P) if (k&1) s=1ll*s*a%P;
return s;
}
int C(int n,int m)
{
if (m>n) return 0;
int ans=1ll*fac[n]*inv[m]%P*inv[n-m]%P;
for (int i=1;i<=t;i++) ans=1ll*ans*ksm(p[i],sum[n][i]-sum[m][i]-sum[n-m][i])%P;
return ans;
}
int calc(int m)
{
int ans=0;
for (int i=0;i<=n;i++)
inc(ans,1ll*C(n,i)*C(n-i,m+i)%P);
return ans;
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("b.in","r",stdin);
freopen("b.out","w",stdout);
#endif
n=read(),P=read(),l=read(),r=read();
int u=P;
for (int i=2;i*i<=u;i++)
if (u%i==0) {p[++t]=i;while (u%i==0) u/=i;}
if (u>1) p[++t]=u;fac[0]=1;
for (int i=1;i<=n;i++)
{
int x=i;
for (int j=1;j<=t;j++)
{
sum[i][j]=sum[i-1][j];
while (x%p[j]==0) x/=p[j],sum[i][j]++;
}
fac[i]=1ll*fac[i-1]*x%P;
}
for (int i=0;i<=n;i++) inv[i]=Inv(fac[i]);
cout<<((calc(l)+calc(l+1)-calc(r+2)-calc(r+1))%P+P)%P;
return 0;
//NOTICE LONG LONG!!!!!
}

  布星lxl题一点都不会。

Codeforces Round #449 Div. 1的更多相关文章

  1. Codeforces Round #449 (Div. 2)

    Codeforces Round #449 (Div. 2) https://codeforces.com/contest/897 A #include<bits/stdc++.h> us ...

  2. Codeforces Round #449 (Div. 2)ABCD

    又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...

  3. Codeforces Round #449 (Div. 2) B. Chtholly's request【偶数位回文数】

    B. Chtholly's request time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  4. Codeforces Round #449 (Div. 2)-897A.Scarborough Fair(字符替换水题) 897B.Chtholly's request(处理前一半) 897C.Nephren gives a riddle(递归)

    A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #449 (Div. 2) D. Ithea Plays With Chtholly

    题目链接 交互题. 题意:给你三个数n,m,k.让你完成至多m次互动,每次给你一个q,让你从n个位置选一个位置放这个数,覆盖已经放过的数.让你再m次使得n个位置的数不递减,达到直接退出. 解法:暴力, ...

  6. Codeforces Round #449 (Div. 1) Willem, Chtholly and Seniorious (ODT维护)

    题意 给你一个长为 \(n\) 的序列 \(a_i\) 需要支持四个操作. \(1~l~r~x:\) 把 \(i \in [l, r]\) 的 \(a_i\) 加 \(x\) . \(2~l~r~x: ...

  7. Codeforces Round #449 (Div. 1)C - Willem, Chtholly and Seniorious

    ODT(主要特征就是推平一段区间) 其实就是用set来维护三元组,因为数据随机所以可以证明复杂度不超过O(NlogN),其他的都是暴力维护 主要操作是split,把区间分成两个,用lowerbound ...

  8. Codeforces Round #449 (Div. 2) C. DFS

    C. Nephren gives a riddle time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  9. Codeforces Round #449 (Div. 2) A. Scarborough Fair【多次区间修改字符串】

    A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. tensorflow-gpu安装的一些注意

    按正确的顺序安装,严格安装特定的版本 1,下载和安装严格版本的cuda和cuDnn,其他版本的不干活.比如要求9.0你就不能装9.1.https://www.tensorflow.org/instal ...

  2. JS判断当前设备类型

    CSS3出来后,我们一般都是通过@media媒体查询来实现网页自适应,但是有时候,还是需要我们根据不同的设备来对应的做不同的显示,这时候,我们需要知道当前用户访问我们的界面用的是什么设备,怎么获取呢? ...

  3. Python-类与对象

    类与对象的概念 类即类别.种类,是面向对象设计最重要的概念,从一小节我们得知对象是特征与技能的结合体,而类则是一系列对象相似的特征与技能的结合体. 那么问题来了,先有的一个个具体存在的对象(比如一个具 ...

  4. C++ string中的find()函数

    1.string中find()返回值是字母在母串中的位置(下标记录),如果没有找到,那么会返回一个特别的标记npos.(返回值可以看成是一个int型的数) #include<cstring> ...

  5. Elasticsearch的DSL之比较重要的几个查询语句

    1.  match_all { "match_all": {}} 匹配所有的, 当不给查询条件时,默认. 2. match 进行full text search或者exact va ...

  6. PEP 8 python编程规范

    一 代码编排 缩进.4个空格的缩进(编辑器都可以完成此功能),不使用Tap,更不能混合使用Tap和空格. 每行最大长度79,换行可以使用反斜杠,最好使用圆括号.换行点要在操作符的后边敲回车. 类和to ...

  7. vue-cli脚手架安装和webpack-simple模板项目生成

    vue-cli 是一个官方发布 vue.js 项目脚手架,使用 vue-cli 可以快速创建 vue 项目. GitHub地址是:https://github.com/vuejs/vue-cli 一. ...

  8. Servlet 转发请求与重定向,以及路径问题

    转发请求 当一个servlet接收到请求后,如果需要将请求转发给另外一个servlet或者jsp文件,可使用下面这种方法: package cn.ganlixin.servlet; import ja ...

  9. 实现数据结构与算法需要掌握的C语言

    我使用C语言并不频繁,一般都是用来实现数据结构与算法,因为面向过程的编程方式容易理解算法的原理,但是呢,如果很长时间没写算法,那么就意味着C语言的某些语法就生疏了,但是总有那么一些,在写算法的时候,特 ...

  10. jQuery学习(监听DOM加载)

    jQuery的extend方法 function njQuery() { } /* njQuery.extend = function (obj) { // 此时此刻的this就是njQuery这个类 ...