华华送奕奕小礼物(二分)
发布日期:2021-06-30 10:27:27
浏览次数:2
分类:技术文章
本文共 1172 字,大约阅读时间需要 3 分钟。
任何一个子矩阵的和都可以写成如下形式
( p r e a [ r 1 ] − p r e a [ l 1 − 1 ] ) ∗ ( p r e b [ r 2 ] − p r e b [ l 2 − 1 ] ) (prea[r_1]-prea[l_1-1])*(preb[r_2]-preb[l_2-1]) (prea[r1]−prea[l1−1])∗(preb[r2]−preb[l2−1])
要让这个和在 [ L , R ] [L,R] [L,R]内
枚举 p r e a [ r 1 ] − p r e a [ l 1 − 1 ] prea[r_1]-prea[l_1-1] prea[r1]−prea[l1−1],这部分复杂度 O ( n 2 ) O(n^2) O(n2)
然后把所有 p r e b [ r 2 ] − p r e b [ l 2 − 1 ] preb[r_2]-preb[l_2-1] preb[r2]−preb[l2−1]预处理放在一个数组里
使用二分查找有多少满足条件的即可
#includeusing namespace std;#define int long longconst int maxn = 1e6+10;int n,m,L,R,ans,a[maxn],b[maxn],w[maxn];signed main(){ cin >> n >> m >> L >> R; for(int i=1;i<=n;i++) cin >> a[i]; for(int i=1;i<=m;i++) cin >> b[i]; for(int i=1;i<=m;i++) { int now = 0; for(int j=i;j<=m;j++) { now += b[j]; w[++w[0]] = now; } } sort( w+1,w+1+w[0] ); for(int i=1;i<=n;i++) { int now = 0; for(int j=i;j<=n;j++) { now += a[j]; //now*x>=L就是 now*x<=R int l = L/now-(L%now==0);//需要大于l int r = R/now;//需要小于等于r int index1 = upper_bound(w+1,w+1+w[0],l)-w; int index2 = upper_bound(w+1,w+1+w[0],r)-w; if( index1==w[0]+1 ) continue;//没有大于l,直接否 ans += index2-index1; } } cout << ans;}
转载地址:https://issue-is-vegetable.blog.csdn.net/article/details/112818564 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月14日 01时41分33秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
油猴脚本:微信推送浏览功能拓展
2019-04-30
JavaScript DOM对象操作详解
2019-04-30
JavaScript 表单操作与MD5加密
2019-04-30
CppWeekly 06 structured binding
2019-04-30
CppWeekly 08 constexpr
2019-04-30
使gazebo_ros能够找到其他package的资源文件
2019-04-30
右键打开 visual studio developer command prompt
2019-04-30
利用AirSim在Unreal Engine上获取全景图像
2019-04-30
神奇的c++等号重载
2019-04-30
利用uWSGI和Nginx部署Django
2019-04-30
Linux下修改^M换行符
2019-04-30
笔记-有关于Vim
2019-04-30
vnc, vncserver, ssh的locale问题
2019-04-30
[野路数] Django中使用logging
2019-04-30
[未修订]ROS学习笔记
2019-04-30
Eigen学习笔记
2019-04-30
PyTorch的学习笔记01-基础中的基础
2019-04-30
onshape 做参考面等虚拟几何的装配和原点定位
2019-04-30