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的更多相关文章

  1. 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 ...

  2. @codeforces - 1187F@ Expected Square Beauty

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个序列 x = {x1, x2, ..., xn},已知 ...

  3. Codeforces Round #448 C. Square Subsets

    题目链接 Codeforces Round #448 C. Square Subsets 题解 质因数 *质因数 = 平方数,问题转化成求异或方程组解的个数 求出答案就是\(2^{自由元-1}\) , ...

  4. Codeforces 959 F. Mahmoud and Ehab and yet another xor task

    \(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...

  5. Codeforces 835 F. Roads in the Kingdom

    \(>Codeforces\space835 F. Roads in the Kingdom<\) 题目大意 : 给你一棵 \(n\) 个点构成的树基环树,你需要删掉一条环边,使其变成一颗 ...

  6. Codeforces 731 F. Video Cards(前缀和)

    Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和 ...

  7. Codeforces 1221 F Choose a Square

    题面 不知道大佬们怎么想的,反正我看到这种区间包含性质的并且score只和包含的区间与询问区间挂钩的题,马上就想到了扫描线23333 虽然革命方向无比正确,但却因为SB错误交了5次才 A. WA第一发 ...

  8. Codeforces 710C. Magic Odd Square n阶幻方

    C. Magic Odd Square time limit per test:1 second memory limit per test:256 megabytes input:standard ...

  9. Codeforces 797 F Mice and Holes

    http://codeforces.com/problemset/problem/797/F F. Mice and Holes time limit per test             1.5 ...

随机推荐

  1. python 全栈开发之旅

    目录 python 基础语法 python 数据类型(未完成) python 内置函数(未完成) python 常用标准库(未完成) python 类(未完成) python 进程.线程.协程(未完成 ...

  2. csu 1770: 按钮控制彩灯实验

    1770: 按钮控制彩灯实验 Submit Page   Summary   Time Limit: 1 Sec     Memory Limit: 128 Mb     Submitted: 341 ...

  3. 安卓中listview中性能优化的处理

    1.在adapter中的getView方法中尽量少使用逻辑 不要在你的getView()中写过多的逻辑代码,我们能够将这些代码放在别的地方.比如: 优化前的getView(): @Override p ...

  4. jqGrid全部选中

    var jqGrid = $("#jqGrid"); // 拿到所有行id var jqGridIDs = jqGrid.getDataIDs(); // 拿到所有选中行id va ...

  5. 使用jquery操作iframe中的元素

    使用jquery操作iframe中的元素<iframe src="/test/demo.htm" width="99%" height="300 ...

  6. canvas与svg的区别

    1.历史: canvas是html5提供的新元素. 而svg存在的历史要比canvas久远,已经有十几年了.svg并不是html5专有的标签,最初svg是用xml技术(超文本扩展语言,可以自定义标签或 ...

  7. Python 实现把两个排好序的的列表合并成一个排序列表

    列表是升序的 # -*- coding: utf-8 -*- # 合并两个排序的数组 def merge_list(a, b): if not a: return b if not b: return ...

  8. java输入输出 -- I/O模型简述

    一.简介 本文向大家介绍五种I/O模型.分别是阻塞I/O.非阻塞I/O.I/O复用.信号驱动式I/O.异步I/O等.内容参考<UNIX网络编程>,大家想进深入学习网络编程,建议去读读这本书 ...

  9. Python列表推导

    一. 列表推导式   ord() 函数是 chr() 函数(对于8位的ASCII字符串)或 unichr() 函数(对于Unicode对象)的配对函数, 它以一个字符(长度为1的字符串)作为参数,返回 ...

  10. 数据结构——java实现队列

    顺序队列: 概念: 队列是一种先进先出的线性表,只允许在一端插入,另一端删除.允许插入的一端称为队尾,允许删除的一端称为队头 顺序队列的实现: import org.junit.jupiter.api ...