Codeforces 1187 F - Expected Square Beauty
思路:
https://codeforces.com/blog/entry/68111
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head const int MOD = 1e9 + ;
const int N = 2e5 + ;
int l[N], r[N], n;
LL p[N], q[N], sum[N];
LL q_pow(LL n, LL k) {
LL res = ;
while(k) {
if(k&) res = (res * n) % MOD;
n = (n * n) % MOD;
k >>= ;
}
return res;
}
int main() {
scanf("%d", &n);
for (int i = ; i <= n; ++i) scanf("%d", &l[i]);
for (int i = ; i <= n; ++i) scanf("%d", &r[i]);
for (int i = ; i <= n; ++i) {
int L = max(l[i-], l[i]), R = min(r[i-], r[i]);
if(L > R) p[i] = , q[i] = ;
else q[i] = (R-L+)*q_pow((r[i]-l[i]+)*1LL*(r[i-]-l[i-]+)%MOD, MOD-)%MOD, p[i] = (-q[i]+MOD)%MOD;
sum[i] = (sum[i-] + p[i]) % MOD;
}
LL ans = sum[n];
for (int i = ; i <= n ;++i) {
LL tot = sum[n];
tot = (tot - p[i])%MOD;
if(i- >= ) tot = (tot - p[i-]) % MOD;
if(i+ <= n) tot = (tot - p[i+]) % MOD;
tot = (tot + MOD) % MOD;
ans = (ans + p[i]*tot%MOD) % MOD;
}
for (int i = ; i < n; ++i) {
LL tot = ((-q[i]-q[i+])%MOD+MOD)%MOD;
if(i- >= ) {
int L = max(l[i-], max(l[i], l[i+])), R= min(r[i-], min(r[i], r[i+]));
if(L <= R)tot = (tot + (R-L+)*q_pow((r[i]-l[i]+)*1LL*(r[i-]-l[i-]+)%MOD*(r[i+]-l[i+]+)%MOD, MOD-)%MOD)%MOD;
}
ans = (ans + *tot) % MOD;
}
printf("%lld\n", ans%MOD);
return ;
}
Codeforces 1187 F - Expected Square Beauty的更多相关文章
- CF1187F Expected Square Beauty(期望)
题目 CF1187F Expected Square Beauty 做法 \(B(x)=\sum\limits_{i=1}^n I_i(x),I_i(x)=\begin{cases}1&x_i ...
- @codeforces - 1187F@ Expected Square Beauty
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个序列 x = {x1, x2, ..., xn},已知 ...
- Codeforces Round #448 C. Square Subsets
题目链接 Codeforces Round #448 C. Square Subsets 题解 质因数 *质因数 = 平方数,问题转化成求异或方程组解的个数 求出答案就是\(2^{自由元-1}\) , ...
- Codeforces 959 F. Mahmoud and Ehab and yet another xor task
\(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...
- Codeforces 835 F. Roads in the Kingdom
\(>Codeforces\space835 F. Roads in the Kingdom<\) 题目大意 : 给你一棵 \(n\) 个点构成的树基环树,你需要删掉一条环边,使其变成一颗 ...
- Codeforces 731 F. Video Cards(前缀和)
Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和 ...
- Codeforces 1221 F Choose a Square
题面 不知道大佬们怎么想的,反正我看到这种区间包含性质的并且score只和包含的区间与询问区间挂钩的题,马上就想到了扫描线23333 虽然革命方向无比正确,但却因为SB错误交了5次才 A. WA第一发 ...
- Codeforces 710C. Magic Odd Square n阶幻方
C. Magic Odd Square time limit per test:1 second memory limit per test:256 megabytes input:standard ...
- Codeforces 797 F Mice and Holes
http://codeforces.com/problemset/problem/797/F F. Mice and Holes time limit per test 1.5 ...
随机推荐
- 安装新版redis4.0.6
看看新版本有那些特性提升,测试用!先安装 网址:https://redis.io/download 获取:wget http://download.redis.io/releases/redis-4. ...
- springboot集成webSocket能启动,但是打包不了war
1.pom.xml少packing元素 https://www.cnblogs.com/zeussbook/p/10790339.html 2.SpringBoot项目中增加了WebSocket功能无 ...
- [学习笔记] 在Eclipse中导入项目
参考前文:[学习笔记] 在Eclips 中导出项目 选择已经导出的文件: 导入之后,项目结构如下: 至此,完成.
- 三个思路解决413 Request Entity Too Large报错处理
最近一个项目当中,要求上传图片,并且限制图片大小,虽然在laravel当中已经添加了相关的表单验证来阻止文件过大的上传,然而当提交表单时,还没轮到laravel处理,nginx就先报错了.当你仔细看报 ...
- [转帖]如何保护你的 Python 代码 (一)—— 现有加密方案
如何保护你的 Python 代码 (一)—— 现有加密方案 Prodesire Python猫 1周前
- 2019CCPC网络赛——array(权值线段树)
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=6703 题目大意: 给出一个n(n<1e5)个元素的数组A,A中所有元素都是不重复的[1,n]. 有 ...
- 1190: 零起点学算法97——A == B ?(Java)
WUSTOJ 1190: 零起点学算法97--A == B ? Description Give you two integer numbers A and B, if A is equal to B ...
- Codeforces 666E Forensic Examination(广义后缀自动机+线段树合并)
将所有串(包括S)放一块建SAM.对于询问,倍增定位出该子串所在节点,然后要查询的就是该子串在区间内的哪个字符串出现最多.可以线段树合并求出该节点在每个字符串中的出现次数. #include<b ...
- 阿里云Centos7 搭建laravel
最近在考虑学习laravel框架,唔 现在服务器搭建一下. laravel是依赖composer的,首先在linux服务器下先安装composer.运行composer需要 php 5.3以上版本, ...
- jacascript 基础数据类型(一)
前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! 数据类型有 number.boolean.string.object.null.undefined; un ...