当前位置:网站首页>AtCoder Beginner Contest 254
AtCoder Beginner Contest 254
2022-07-02 11:55:00 【不是张胖胖】
D - Together Square
题意:
计算有对少对小于等于 n ( 1 ≤ n ≤ 2 × 1 0 5 ) n(1 \leq n \leq 2×10^5) n(1≤n≤2×105)的 i , j i,j i,j,满足 i × j i×j i×j是平方数
思路:
如果 i i i是平方数,那么 j j j也是平方数才行。
否则, j j j应该是平方数乘以 i i i中出现次数为奇数的质因子
#include<bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
typedef pair<int,int> PII;
const int maxn=2e5+7;
int n,vis[maxn];
int main()
{
scanf("%d",&n);
vector<int>v;
for(int i=1;;i++)
{
if(i*i>n) break;
vis[i*i]=1;v.pb(i*i);
}
ll ans=0;
for(int i=1;i<=n;i++)
{
if(vis[i]) ans+=v.size();
else
{
int nn=i;
for(int j=1;j<v.size();j++)
{
while(nn%v[j]==0)
{
nn/=v[j];
}
}
for(int j=0;j<v.size();j++)
{
if(v[j]*nn>n) break;
ans++;
}
}
}
printf("%lld\n",ans);
}
F - Rectangle GCD
题意:
有长度为 n ( 1 ≤ n ≤ 2 × 1 0 5 ) n(1≤n≤2×10^5) n(1≤n≤2×105)的数组 A , B ( 1 ≤ A i , B i ≤ 1 0 9 ) A,B(1≤A _i,B_i≤10^9) A,B(1≤Ai,Bi≤109),以及一个 n × n n×n n×n的正方形,第 i i i行第 j j j列的数为 A i + B j A_i+B_j Ai+Bj
有 q ( 1 ≤ q ≤ 2 × 1 0 5 ) q(1≤q≤2×10^5) q(1≤q≤2×105)次询问,每次询问一个矩形区域内所有数字的 gcd \gcd gcd
思路:
矩形内数字为
a i + b j a i + b j + 1 a i + b j + 2 a i + b j + 3 . . . a i + 1 + b j a i + 1 + b j + 1 a i + 1 + b j + 3 a i + 1 + b j + 2 . . . . . . . . . a_i+b_j \quad a_{i}+b_{j+1} \quad a_{i}+b_{j+2} \quad a_{i}+b_{j+3} \quad ...\\ a_{i+1}+b_{j} \quad a_{i+1}+b_{j+1} \quad a_{i+1}+b_{j+3} \quad a_{i+1}+b_{j+2} \quad ...\\ ...... ai+bjai+bj+1ai+bj+2ai+bj+3...ai+1+bjai+1+bj+1ai+1+bj+3ai+1+bj+2.........
已知性质
gcd ( a , b , c , d ) = gcd ( a , b − a , c − b , d − c ) \gcd(a,b,c,d)=\gcd(a,b-a,c-b,d-c) gcd(a,b,c,d)=gcd(a,b−a,c−b,d−c)
所以问题转化为 gcd \gcd gcd数组 B , A B,A B,A的差分数组
用线段树维护即可
#include<bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
typedef pair<int,int> PII;
const int maxn=2e5+7;
struct gcd_tree
{
int nums[maxn];
struct tree
{
int l,r,sum;
int mid()
{
return (l+r)/2;
}
}tre[maxn<<2];
void pushup(int num)
{
tre[num].sum=__gcd(tre[2*num].sum,tre[2*num+1].sum);
}
void build(int num,int l,int r)
{
tre[num].l=l,tre[num].r=r;
if(l==r)
{
tre[num].sum=nums[l];return;
}
int mid=tre[num].mid();
build(2*num,l,mid);
build(2*num+1,mid+1,r);
pushup(num);
}
int query(int num,int l,int r)
{
if(tre[num].l==l && tre[num].r==r)
return tre[num].sum;
int mid=tre[num].mid();
if(l>mid)
return query(2*num+1,l,r);
else if(r<=mid)
return query(2*num,l,r);
else
return __gcd(query(2*num,l,mid),query(2*num+1,mid+1,r));
}
}da,db;
int n,m;
int a[maxn],b[maxn];
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=n;i++) scanf("%d",&b[i]);
for(int i=1;i<=n;i++) da.nums[i]=abs(a[i]-a[i-1]);
da.build(1,1,n);
for(int i=1;i<=n;i++) db.nums[i]=abs(b[i]-b[i-1]);
db.build(1,1,n);
while(m--)
{
int h1,h2,w1,w2;scanf("%d%d%d%d",&h1,&h2,&w1,&w2);
int ans=a[h1]+b[w1];
if(h2>h1) ans=__gcd(ans,da.query(1,h1+1,h2));
if(w2>w1) ans=__gcd(ans,db.query(1,w1+1,w2));
printf("%d\n",ans);
}
}
边栏推荐
- Add vector formula in rich text editor (MathType for TinyMCE, visual addition)
- 传感器数据怎么写入电脑数据库
- mathML转latex
- STM32 library function for GPIO initialization
- Actual combat sharing of shutter screen acquisition
- kityformula-editor 配置字号和间距
- Thoroughly master prototype__ proto__、 Relationship before constructor (JS prototype, prototype chain)
- qml 弹窗框架,可定制
- ##51单片机实验之简易验证码发生器
- 1. Editing weapon VIM
猜你喜欢

MathML to latex

C language exercises - (array)
[email protected] : The platform “win32“ is incompatible with this module."/>info [email protected] : The platform “win32“ is incompatible with this module.

LeetCode 209. 长度最小的子数组

C语言习题---(数组)

微信小程序使用towxml显示公式

Obsidian installs third-party plug-ins - unable to load plug-ins

Onnx+tensorrt: write preprocessing operations to onnx and complete TRT deployment

vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)

可视化搭建页面工具的前世今生
随机推荐
Fabric. JS upper dash, middle dash (strikethrough), underline
Socket and socket address
taobao. trade. Get (get some information of a single transaction), Taobao store order interface, Taobao oauth2.0 interface, Taobao R2 interface code docking and sharing
Threejs controller cube space basic controller + inertia control + flight control
Fabric. JS free draw circle
C语言习题---(数组)
Fabric.js 自由绘制椭圆
Introduction to C language -- array
Mfc a dialog calls B dialog function and passes parameters
Reuse and distribution
A white hole formed by antineutrons produced by particle accelerators
4. Array pointer and pointer array
【C语言】详解指针的初阶和进阶以及注意点(1)
taobao.logistics.dummy.send( 无需物流发货处理 )接口,淘宝店铺发货API接口,淘宝订单发货接口,淘宝r2接口,淘宝oAu2.0接口
It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen
taobao.trade.get( 获取单笔交易的部分信息),淘宝店铺订单接口,淘宝oAuth2.0接口,淘宝R2接口代码对接分享
电脑怎么设置扬声器播放麦克风的声音
Some Chinese character codes in the user privacy agreement are not standardized, which leads to the display of garbled codes on the web page. It needs to be found and handled uniformly
[untitled] leetcode 2321 Maximum score of concatenated array
SQL 后计算的利器 SPL