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 ...
随机推荐
- pycharm操作Django基础部分
原文地址:https://www.cnblogs.com/feixuelove1009/p/5823135.html
- .rpt 文件怎麽打開?Crystal Reports 打開.rpt失敗 ?
.rpt 是SAP Crystal Reports 製作出來的檔案的後綴名, 可以通過 SAP Crystal Reports Viewer 打開,也可以直接用記事本(notepad / Note ...
- Andrew Ng机器学习课程13
Andrew Ng机器学习课程13 声明:引用请注明出处http://blog.csdn.net/lg1259156776/ 引言:主要从一般的角度介绍EM算法及其思想,并推导了EM算法的收敛性.最后 ...
- WebStorm 2018.2安装激活教程
1.下载解压,得到jetbrains webstorm 2018.2主程序,破解文件和中文语言包: 2.运行“WebStorm-2018.2.exe”开始安装,默认安装目录[C:\Program Fi ...
- 生成 n 个不同的随机数且随机数区间为 [0,n)
生成 n 个不同的随机数且随机数区间为 [0,n) Java 实现 import java.util.ArrayList; import java.util.List; import java.uti ...
- 事务的ACID
事务提供一种机制将一个活动涉及的所有操作纳入到一个不可分割的执行单元,组成事务的所有操作只有在所有操作均能正常执行的情况下方能提交,只要其中任一操作执行失败,都将导致整个事务的回滚. 简单地说,事务提 ...
- [转帖]一个关于国密SM4的故事
一个关于国密SM4的故事 https://www.cnblogs.com/ouyida3/p/10053862.html SM1 硬件SM2 非对称加密SM3 hash算法SM4 对称加密 一个关于国 ...
- Visual Studio中Debug与Release以及x86、x64、Any CPU的区别
Visual Studio中Debug与Release的区别: 在Visual Studio中,编译模式有2种:Debug与Release.这也是默认的两种方式,在新建一个project的时候,就已经 ...
- python学习-48 模块2
sys修改环境变量 ---------- 只能临时修改 import syssys.path.append() 例如: import sys sys.path.append('C:\Users\hua ...
- Vue解决项目白屏
第一步: vue-cli项目根目录下面新建Vue.config.js文件 proxy反向代理 module.exports = { devServer: { proxy: { ...