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 ...
随机推荐
- 关于async await的测试
async await的教程:https://www.cnblogs.com/zhaoshujie/p/11192036.html 异步方法: private async Task<string ...
- 【POJ - 3268 】Silver Cow Party (最短路 Dijkstra算法)
Silver Cow Party Descriptions 给出n个点和m条边,接着是m条边,代表从牛a到牛b需要花费c时间,现在所有牛要到牛x那里去参加聚会,并且所有牛参加聚会后还要回来,给你牛x, ...
- 人工智能_2_特征处理.py
# 特征处理 # 特征预处理:通过统计方法将数据转换为算法需要的数据 # 数值型数据:标准缩放 # 规依法,标准化(常用,适用于当前大数据),缺失值处理(删除,填补中位数平均数,通常按照列填补) # ...
- nginx目录学习
目录 一. Nginx 基础知识 二. Nginx 安装及调试 三. Nginx Rewrite 四. Nginx Redirect 五. Nginx 目录自动加斜线: 六. Nginx Locati ...
- POJ 2299-Ultra-QuickSort-线段树的两种建树方式
此题有两种建树方式! Description In this problem, you have to analyze a particular sorting algorithm. The algo ...
- Solr综合案例深入练习
1. 综合案例 1.1. 需求 使用Solr实现电商网站中商品信息搜索功能,可以根据关键字.分类.价格搜索商品信息,也可以根据价格进行排序,并且实现分页功能. 界面如下: 1.2. 分析 开发人员需要 ...
- Docker容器日志查看与清理的方法
Docker容器日志查看与清理的方法 Docker 容器是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化.容器 ...
- CentOS7 服务器连接超时自动断开问题解决
背景 现在的客户们都开始使用云服务器了,还要通过堡垒机才给访问权限,这种方式访问方式以前都是银行的"专利",不过也间接说明其他行业的信息化也越来越普及了.今天主要是因为分配给我的这 ...
- Prometheus Grafana监控全方位实践
这次就不用 docker 部署服务了,这样大家会更容易接受.欢迎阅读. 引言 Prometheus 是一个监控系统,也是一个时间序列数据库,用Go语言开发的,官方文档.通过从某些特定的目标如主机,My ...
- 利用Filter和HttpServletRequestWrapper实现请求体中token校验
先说一下项目的背景,系统传参为json格式,token为其中一个必传参数,此时如果在过滤器中直接读取request,则后续controller中通过RequestBody注解封装请求参数是会报stre ...