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 ...
随机推荐
- npm的问题【解决】
1.解决npm下载慢的问题,使用该命令 npm install --registry=https://registry.npm.taobao.org 好处:比起cnpm官网解释的,这个更好,使用cnp ...
- 云计算服务模式(SaaS/PaaS/IaaS)
为什么是云计算,为什么是现在 商用云:商用云的设计初衷是将基础设施商品化,并以较低的成本对外提供,是用户能够获得高扩展性和自服务能力. 企业云:企业级云的目的,则是达到或超过它所要替代的本地基础设施的 ...
- 【C/C++开发】C++队列缓存的实现
C++队列缓存的实现 为什么使用队列缓存 c++的队列缓存主要用于解决大数据量并发时的数据存储问题,可以将并发时的数据缓存到队列中,当数据量变小时再匀速写入硬盘中. 引用queue队列 在头文件中引用 ...
- 日常工作问题解决:rhel7下配置多路径设备
目录 1.情景描述 2.安装多路径软件 2.1 安装多路径 2.2检查安装情况 2.3 重启系统 2.4 将多路径软件添加至内核模块 2.5 检查内核添加情况 2.6 启动multipath服务 2. ...
- python多任务基础
1.多任务:两个程序段同时运行2.为某个函数创建线程并启动: import threading 线程名 = threading.Thread(target = 函数名,args = 参数元组) #创建 ...
- 20191011-构建我们公司自己的自动化接口测试框架-Util的读取excel常用方法模块
包括获取excel的sheet名字,设定excel的sheet,读excel,写excel等常规操作. from openpyxl import Workbook from openpyxl impo ...
- SAS学习笔记16 SAS创建计数(枚举)变量
- 怎样绑定this
有三种方法: 1. Function.prototype.call(); 2. Function.prototype.apply(); 3. Function.prototype.bind(); ...
- PHP对程序员的要求更高
我这个文章标题可不是和大家开玩笑的哦 首先, 大家都知道, PHP也是一种编译型脚本语言, 和其他的预编译型语言不同, 它不是编译成中间代码, 然后发布.. 而是每次运行都需要编译.. 为此, 也 ...
- Android监听EditText输入字符串,删除指定的字符
alert_ed = (EditText) a.findViewById(R.id.alert_ed_queue_num); alert_ed.addTextChangedListener(mText ...