博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces 1187 F - Expected Square Beauty
阅读量:5337 次
发布时间:2019-06-15

本文共 1925 字,大约阅读时间需要 6 分钟。

思路:
https://codeforces.com/blog/entry/68111

代码:

#pragma GCC optimize(2)#pragma GCC optimize(3)#pragma GCC optimize(4)#include
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
#define pli pair
#define pii pair
#define piii pair
#define pdd pair
#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);//headconst int MOD = 1e9 + 7;const int N = 2e5 + 5;int l[N], r[N], n;LL p[N], q[N], sum[N];LL q_pow(LL n, LL k) { LL res = 1; while(k) { if(k&1) res = (res * n) % MOD; n = (n * n) % MOD; k >>= 1; } return res;}int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &l[i]); for (int i = 1; i <= n; ++i) scanf("%d", &r[i]); for (int i = 1; i <= n; ++i) { int L = max(l[i-1], l[i]), R = min(r[i-1], r[i]); if(L > R) p[i] = 1, q[i] = 0; else q[i] = (R-L+1)*q_pow((r[i]-l[i]+1)*1LL*(r[i-1]-l[i-1]+1)%MOD, MOD-2)%MOD, p[i] = (1-q[i]+MOD)%MOD; sum[i] = (sum[i-1] + p[i]) % MOD; } LL ans = sum[n]; for (int i = 1; i <= n ;++i) { LL tot = sum[n]; tot = (tot - p[i])%MOD; if(i-1 >= 1) tot = (tot - p[i-1]) % MOD; if(i+1 <= n) tot = (tot - p[i+1]) % MOD; tot = (tot + MOD) % MOD; ans = (ans + p[i]*tot%MOD) % MOD; } for (int i = 1; i < n; ++i) { LL tot = ((1-q[i]-q[i+1])%MOD+MOD)%MOD; if(i-1 >= 1) { int L = max(l[i-1], max(l[i], l[i+1])), R= min(r[i-1], min(r[i], r[i+1])); if(L <= R)tot = (tot + (R-L+1)*q_pow((r[i]-l[i]+1)*1LL*(r[i-1]-l[i-1]+1)%MOD*(r[i+1]-l[i+1]+1)%MOD, MOD-2)%MOD)%MOD; } ans = (ans + 2*tot) % MOD; } printf("%lld\n", ans%MOD); return 0;}

 

转载于:https://www.cnblogs.com/widsom/p/11131833.html

你可能感兴趣的文章
EL表达式总结
查看>>
WCF的应用与说明
查看>>
JSON
查看>>
ibatis批量添加数据
查看>>
将 Shiro 作为应用的权限基础 二:基于SpringMVC实现的认证过程
查看>>
管理C++类中的指针成员
查看>>
生成函数与指数生成函数
查看>>
4.接口隔离原则(Interface Segregation Principle)
查看>>
wcf系列学习5天速成——第四天 wcf之分布式架构
查看>>
LeetCode "Maximum Product of Word Lengths"
查看>>
linux 用户与权限管理
查看>>
Api demo源码学习(9)--App/Activity/Receive Result --Activity间传递数据
查看>>
Vim总结(二)
查看>>
JAVA:URL之图像图标
查看>>
wcf host service
查看>>
JSP内置对象——out,get与post
查看>>
一维数组
查看>>
JAVA多线程通信
查看>>
二分图的最大匹配问题
查看>>
第三次月赛题解
查看>>