当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
05 | 后台登录:基于账号密码的登录方式(下)
for循环的3个表达式执行顺序
[VMware virtual machine installation mysql5.7 tutorial]
人社部公布“数据库运行管理员”成新职业,OceanBase参与制定职业标准
OFDM 十六讲 3- OFDM Waveforms
R语言向前或者向后移动时间序列数据(自定义滞后或者超前的期数):使用dplyr包中的lag函数将时间序列数据向后移动一天(设置参数n为负值)
SQL 26 calculation under 25 years of age or older and the number of users
自从外包干了四年,基本废了...
cpu/CS and IP
永州动力电池实验室建设合理布局方案
【ROS进阶篇】第十一讲 基于Gazebo和Rviz的机器人联合仿真(运动控制与传感器)
电池包托盘有进水风险,存在安全隐患,紧急召回52928辆唐DM
pytorch学习记录(五):卷积神经网络的实现
戴墨镜的卡通太阳SVG动画js特效
R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化箱图、width参数自定义箱图中箱体的宽度
[论文翻译] Unpaired Image-To-Image Translation Using Cycle-Consistent Adversarial Networks
LeetCode二叉树系列——199二叉树的右视图
svg波浪动画js特效代码
树形dp小总结(换根,基环树,杂七杂八的dp)
AT4108 [ARC094D] Normalization







![[VMware virtual machine installation mysql5.7 tutorial]](/img/eb/4b47b859bb5695c38d48c8c01c9da0.png)