1.C. Kuroni and Impossible Calculation

**知识点:同余定理 **

#include <iostream>
#include <cstdio>
#include <stack>
#include <sstream>
#include <vector>
#include <map>
#include <cstring>
#include <deque>
#include <cmath>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#define mid ((l + r) >> 1)
#define Lson rt << 1, l , mid
#define Rson rt << 1|1, mid + 1, r
#define ms(a,al) memset(a,al,sizeof(a))
#define _for(i,a,b) for( int i = (a); i < (b); ++i)
#define _rep(i,a,b) for( int i = (a); i <= (b); ++i)
#define for_(i,a,b) for( int i = (a); i >= (b); -- i)
#define rep_(i,a,b) for( int i = (a); i > (b); -- i)
#define lowbit(x) ((-x) & x)
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define wei(a) fixed<<setprecision(a)
#define INF 0x3f3f3f3f
#define hash Hash
#define next Next
#define f first
#define s second
using namespace std;
const int N = 2e5 + 10;
const double pi = acos(-1);
const double eps = 1e-9;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
LL a[N];
int main()
{LL n, m;cin >> n >> m;_for(i,0,n) cin >> a[i];if(n - 1 > 1000) {cout << "0";return 0;}LL res = 1;_for(i,0,n)_for(j,i+1,n)res *= abs(a[i] - a[j]), res %= m;cout << res << endl;return 0;
}

2.D. MEX maximizing
题目大意:初始你有一个空的数组a[] = {};你每次都会向数组里面插入一个数字每次你都可以对数组里面的字进行任意次(±)x,问你在数组中没出现过的最小非负整数是多少?
思路:1.我们观察可以发现题目可以转化成是从0.1.2.3.4…n这样排列下去最长是少?
2.观察数据范围很明显一个数可以写成a = kx + b;n的大小是4e5,而插入的ai是1e9次方那么我们就可以把ai %= x, 把它变到这个范围里面。
3.我们刻意开一个数组记录一下0到n中有多少个数出现了,如插入的这个数以经有了那么我们就让它加上若干个x始得达到第一次没出现过的最小数为止,那么这个我们可以二分
4.插入之后我们就可以二分去查找最长的0,1,2,3,,,,n了,这里我们有树状数组维护一下就可以了(二分去查找前缀和==Mid的位置)[这里要特判一下0因为树状数组无法从0开始]

#include <iostream>
#include <cstdio>
#include <stack>
#include <sstream>
#include <vector>
#include <map>
#include <cstring>
#include <deque>
#include <cmath>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#define mid ((l + r) >> 1)
#define Lson rt << 1, l , mid
#define Rson rt << 1|1, mid + 1, r
#define ms(a,al) memset(a,al,sizeof(a))
#define _for(i,a,b) for( int i = (a); i < (b); ++i)
#define _rep(i,a,b) for( int i = (a); i <= (b); ++i)
#define for_(i,a,b) for( int i = (a); i >= (b); -- i)
#define rep_(i,a,b) for( int i = (a); i > (b); -- i)
#define lowbit(x) ((-x) & x)
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define wei(a) fixed<<setprecision(a)
#define INF 0x3f3f3f3f
#define hash Hash
#define next Next
#define f first
#define s second
using namespace std;
const int N = 4e5 + 10;
const double pi = acos(-1);
const double eps = 1e-9;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
int q, x;
bool vis[N << 1];
int tree[N << 1];
inline void add(int x)
{while(x <= N){tree[x] += 1;x += lowbit(x);}
}inline LL sum(LL x)
{LL res = 0;while(x){res += tree[x];x -= lowbit(x);}return res;
}bool judge(LL Mid, LL num)
{if(1ll * num + x * Mid * 1ll > 4e5) return true;if(!vis[num + x * Mid]) return true;return false;
}int check(LL num)
{int l = 0, r = 4e5;while(l < r){if(judge(mid,num)) r = mid;else l = mid + 1;}return l;
}int main()
{cin >> q >> x;while(q --){LL num;cin >> num;num %= x;LL next = check(num);vis[num + x * next] = true;// cout << num << " -----  " << next << endl;if(num + x * next)  add(num + x * next);if(!vis[0]) {cout << "0" << endl;continue;}int l = 0, r = N;while(l < r){int Mid = l + (r - l + 1 >> 1);if(sum(Mid) == Mid) l = Mid;else r = Mid - 1;}cout << l + 1 << endl;}return 0;
}

C. New Year and Permutation

这个题很有意思呀。就是给你一个n,求n的[所有全排列]里区间左右端点的差等于区间内极差的区间的和。
1.其实手枚一下就可以发现,其实满足这个条件的区间内的数一定是连续的。
2.所以我们从区间长度入手,对于每个长度的区间看对应了多少个排列满足要求。
3.这就很简单了呀。我们枚举区间的极差i,考虑选差值为i的i+1个数有n-i种选法,区间内的顺序随意,整体看这i+1个数为一组,另外的n-i-1个数为n-i-1个组,这n-i个组的顺序同样随意。
所以就有:
`

#define maxn 250010
LL fact[maxn],ans=0;
int main(){int i,n,m;scanf("%d%d",&n,&m);fact[0]=1;for(i=1;i<=n;i++)fact[i]=fact[i-1]*i%m;for(i=0;i<=n-1;i++)ans=(ans+(n-i)*fact[i+1]%m*fact[n-i]%m)%m;printf("%lld\n",ans);return 0;
}

Codeforces数学1600----day1[同余定理,树状数组+两次二分,,组合计数]相关推荐

  1. CodeForces 390E Inna and Large Sweet Matrix(树状数组改段求段)

    CodeForces 390E Inna and Large Sweet Matrix(树状数组改段求段) 树状数组仅仅能实现线段树区间改动和区间查询的功能,能够取代不须要lazy tag的线段树.且 ...

  2. CodeForces - 641ELittle Artem and Time Machine——map+树状数组

    [题目描述] CodeForces - 641ELittle Artem and Time Machine [题目分析] 题目的意思大概是有三种操作 1.在时间t加入一个数字x 2.在时间t删除一个数 ...

  3. CodeForces 869E The Untended Antiquity 二维树状数组,随机hash

    CodeForces 869E 题意: n*m 的格子,有三种操作, 1.在一个矩形周围加一层障碍.2.把一个矩形周围的障碍去掉. 3.询问两个格子是否可达.     题目保证不会有矩形障碍交叉,且去 ...

  4. codeforces 869 E. The Untended Antiquity(树状数组)

    题目链接:http://codeforces.com/contest/869/problem/E 题解:这题是挺好想到solution的但是不太好写,由于题目的特殊要求每个矩形不会重贴所以只要这两个点 ...

  5. Codeforces 629D Babaei and Birthday Cake(树状数组优化dp)

    题意: 线段树做法 分析: 因为每次都是在当前位置的前缀区间查询最大值,所以可以直接用树状数组优化.比线段树快了12ms~ 代码: #include<cstdio> #include< ...

  6. Codeforces #528 Div2 F (1087F) Rock-Paper-Scissors Champion 树状数组+set

    题意:n个人站成一排,初始时刻每个人手中都有一个图案,可能是石头,剪刀,布3个中的1种,之后会随机选取相邻的两个人玩石头剪刀布的游戏,输的人会离开(如果两个人图案相同,则随机选择一个人离开).执行(n ...

  7. Codeforces Round #401 (Div. 1) C(set+树状数组)

    题意: 给出一个序列,给出一个k,要求给出一个划分方案,使得连续区间内不同的数不超过k个,问划分的最少区间个数,输出时将k=1~n的答案都输出 比赛的时候想的有点偏,然后写了个nlog^2n的做法,T ...

  8. 树状数组两种基本的模式

    树状数数组基本的两种模式: 第一,对初始数组a[i]中的某一元素修改,查询某个区间内的所有的和,(时间复杂度都为logn).(插点问线) 第二,随时修改数组中a[i]中的某个区间的值(O(1)的时间复 ...

  9. Ybtoj 最优密码 单调队列(浅谈)树状数组 两种解法

    作者:hsez_yyh 链接:https://blog.csdn.net/yyh_getAC/article/details/123956399  来源:湖北省黄石二中竞赛组  著作权归作者所有.商业 ...

最新文章

  1. 损失函数与优化器理解+【PyTorch】在反向传播前为什么要手动将梯度清零?optimizer.zero_grad()
  2. 程序编号以后计算机能够查出,华威大学研究人员开发出计算机程序,可发现量子计算机中的“泄漏”...
  3. 领导逼走员工的新套路,一次就见效
  4. python连接hive kerberos_数据库开发实战教程:使用Python连接Kerberos的Presto
  5. 数据仓库技术解决方案
  6. 小米手机浏览器部分图片显示异常
  7. 印地语freeCodeCamp YouTube频道+不和谐聊天现已上线
  8. 全网最详细解释Keil-MDK中Code、RO-data、RW-data、ZI-data的含义
  9. SRM 459 500p hust1080 NumberPyramids
  10. 聊聊 Python 代码覆盖率工具 - 大咖爱爬虫
  11. java scanner输入数组_Java Scanner输入两个数组的方法
  12. SSM+天山产业园访客与疫情防控系统 毕业设计-附源码191123
  13. 对于算法工程师职业生涯规划的考虑
  14. Linux文件类型和根目录结构
  15. 牛客网暑期ACM多校训练营(第四场)C(Chiaki Sequence Reloaded)
  16. 在线版区间众数 hzw的代码。。
  17. 组合数学——牡牛和牝牛
  18. 臻米脱糖电饭煲,古法先煮后蒸,实现低糖生活
  19. R-quantile()
  20. iOS迅雷7月19日更新,终于可以稳定下载了!

热门文章

  1. C语言\b回退一格!_只愿与一人十指紧扣_新浪博客
  2. 从零开始一起学习SLAM | 不推公式,如何真正理解对极约束?
  3. 超硬核的 Python 数据可视化教程!
  4. 链表问题13——删除无序单链表中值重复出现的节点
  5. Win10环境Tensorflow-GPU13.1/JupyterNotebook的安装
  6. Mysql笔记2-----重要小点
  7. Zabbix 3.2.6 通过SNMP和iDRAC监控DELL服务器
  8. 【Java面试题】37 说出ArrayList,Vector, LinkedList的存储性能和特性
  9. 移动端页面——js控制制作
  10. 使用Maven管理Java项目