当前位置:网站首页>UPC2022 Summer Individual Training Game 19 (B, P)
UPC2022 Summer Individual Training Game 19 (B, P)
2022-07-30 13:55:00 【.Ashy。】
B: 数学 (math)
大意:
求 n(n<=1e12) The number of scenarios to decompose into consecutive integer sums
思路:
Very clever math problem
We assume that the leading term of the sum of consecutive integers is a a a ,一共有 n n n 项 ,和为 S S S
则一定满足
S = ( 首项 + 末项 ) ∗ n 2 S={(首项+末项)*n \over2} S=2(首项+末项)∗n
化简就是
2 ∗ S = ( 2 ∗ a + n − 1 ) ∗ n 2*S=(2*a+n-1)*n 2∗S=(2∗a+n−1)∗n
There are obviously two unknowns a a a 和 n n n
如果我们枚举 a a a 和 n n n it will explode
1.分析 n n n 的范围:
n 是项数,当 a = 1 a=1 a=1时 n n n 最大 这时 2 ∗ S = ( n + 1 ) ∗ n 2*S=(n+1)*n 2∗S=(n+1)∗n
所以我们可以得到 n ∗ n < ( n + 1 ) ∗ n = 2 ∗ S n*n<(n+1)*n=2*S n∗n<(n+1)∗n=2∗S
所以 n < s q r t ( 2 ∗ S ) n<sqrt(2*S) n<sqrt(2∗S) n最大在 1.5e6 左右
2.分析 a a a 的范围:
And the first item is clearly available to us a 2 a\over2 2a So it's obviously not appropriate to enumerate two values
最大为2e11
After analyzing the complexity, we can clearly see what to do n n n下手,枚举所有的 n n n ,It can be judged whether the first item at this time is legal
The first term must be a positive integer
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
const int N = 2e5+10;
const int NN = 1e6+10;
const int pp = 1e9+7;
typedef pair<int,int>PII;
ll n,ans;
int main()
{
cin>>n;
for(ll i=2;i<=sqrt(n*2);i++)
{
ll k=((n*2)-i*i+i)%(i*2);
if(k==0&&((n*2)-i*i+i)/(i*2)>0) ans++;
}
cout<<ans;
return 0;
}
问题 P: Count Interval
大意:
给出 N 个数,Find the one that satisfies the following formula l ,r 有多少组
∑ i = l r A i = k \displaystyle\sum_{i=l}^rA_i=k i=l∑rAi=k
思路
We can optimize it with prefix sum,After the optimization is completed, it is satisfied s u m [ r ] − s u m [ l − 1 ] = k sum[r]-sum[l-1]=k sum[r]−sum[l−1]=k的 l , r 有多少组
This question has become typical A − B = k A-B=k A−B=k 问题;We can store and compute as we go,Every number we deal with is one A A A,Contribution is the first few miles B B B 的数量 也就是 A − K A-K A−K 的数量
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
const int N = 2e5+10;
const int NN = 1e6+10;
const int pp = 1e9+7;
typedef pair<int,int>PII;
ll sum[N];
ll n,k,t,ans;
map<ll,ll>mp;
int main()
{
cin>>n>>k;
for(int i=1;i<=n;i++)
{
cin>>t;
sum[i]=sum[i-1]+t;
}
mp[0]=1;
for(int i=1;i<=n;i++)
{
ans+=mp[sum[i]-k];
mp[sum[i]]++;
// cout<<ans<<endl;
}
cout<<ans;
return 0;
}
边栏推荐
猜你喜欢

无代码开发平台全部应用设置入门教程

第十五天笔记

leetcode207.课程表(判断有向图是否有环)

无代码开发平台应用可见权限设置入门教程

学习笔记——七周成为数据分析师《第一周:数据分析思维》

Data Middle Office Construction (5): Breaking Enterprise Data Silos and Extracting Data Value

svg波浪动画js特效代码

jsArray array copy method performance test 2207292307

The way of programmers' cultivation: do one's own responsibilities, be clear in reality - lead to the highest realm of pragmatism

重保特辑|筑牢第一道防线,云防火墙攻防演练最佳实践
随机推荐
curl 执行脚本时传递环境变量与参数
电池包托盘有进水风险,存在安全隐患,紧急召回52928辆唐DM
权威推荐!腾讯安全DDoS边缘安全产品获国际研究机构Omdia认可
创意loadingjs特效小点跳跃动画
PyQt5快速开发与实战 8.6 设置样式
qq udp tcp机制
434. 字符串中的单词数
【软考软件评测师】自动化测试章节下篇
Data Middle Office Construction (5): Breaking Enterprise Data Silos and Extracting Data Value
CF1677E Tokitsukaze and Beautiful Subsegments
R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化分组箱图、使用ggpar函数改变图形化参数(xlab、ylab、改变可视化图像的坐标轴标签内容)
ARC117E零和范围2
20220729 证券、金融
二手手机销量突破3亿部,与降价的iPhone夹击国产手机
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
正确处理页面控制器woopagecontroller.php,当提交表单时是否跳转正确的页面
【微信小程序】一文带你搞懂小程序的页面配置和网络数据请求
R语言ggplot2可视化:使用ggpubr包的ggmaplot函数可视化MA图(MA-plot)、设置label.select参数自定义在图中显示标签的基因类型(自定义显示的标签列表)
腾讯称电竞人才缺口200万;华为鸿蒙3.0正式发布;乐视推行每周工作4天半?...丨黑马头条...
No-code development platform application visible permission setting introductory tutorial