当前位置:网站首页>AtCoder Beginner Contest 254
AtCoder Beginner Contest 254
2022-07-02 15:03:00 【Not Zhang Pangpang】
List of articles
D - Together Square
The question :
Calculate the number of pairs less than or equal to n ( 1 ≤ n ≤ 2 × 1 0 5 ) n(1 \leq n \leq 2×10^5) n(1≤n≤2×105) Of i , j i,j i,j, Satisfy i × j i×j i×j It's a square number
Ideas :
If i i i It's a square number , that j j j It's also a square number .
otherwise , j j j It should be square times i i i A prime factor with an odd number of occurrences in
#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
The question :
There is a length of n ( 1 ≤ n ≤ 2 × 1 0 5 ) n(1≤n≤2×10^5) n(1≤n≤2×105) Array of 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), And one. n × n n×n n×n The square of , The first i i i Xing di j j j The number of columns is A i + B j A_i+B_j Ai+Bj
Yes q ( 1 ≤ q ≤ 2 × 1 0 5 ) q(1≤q≤2×10^5) q(1≤q≤2×105) Time to ask , Ask all the numbers in a rectangular area at a time gcd \gcd gcd
Ideas :
The number in the rectangle is
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.........
Known properties
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)
So the problem turns into gcd \gcd gcd Array B , A B,A B,A The differential array of
It can be maintained by line tree
#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);
}
}
边栏推荐
- jmeter脚本参数化
- Fatal: unsafe repository is owned by someone else
- info [email protected]: The platform “win32“ is incompatible with this module.
- Edit the formula with MathType, and set it to include only mathjax syntax when copying and pasting
- 天猫商品详情接口(APP,H5端)
- MFC console printing, pop-up dialog box
- JMeter script parameterization
- threejs的控制器 立方体空间 基本控制器+惯性控制+飞行控制
- Actual combat sharing of shutter screen acquisition
- Slashgear shares 2021 life changing technology products, which are somewhat unexpected
猜你喜欢
[email protected] : The platform “win32“ is incompatible with this module."/>info [email protected] : The platform “win32“ is incompatible with this module.

LeetCode 2310. The number of digits is the sum of integers of K

Introduction to C language -- array

MathML to latex

【NOI模拟赛】刮痧(动态规划)

Error: NPM warn config global ` --global`, `--local` are deprecated Use `--location=global` instead.

大顶堆、小顶堆与堆排序

YoloV6训练:训练自己数据集遇到的各种问题

蜻蜓低代码安全工具平台开发之路

About text selection in web pages and counting the length of selected text
随机推荐
taobao. logistics. dummy. Send (no logistics delivery processing) interface, Taobao store delivery API interface, Taobao order delivery interface, Taobao R2 interface, Taobao oau2.0 interface
求轮廓最大内接圆
Fundamentals of software testing
Socket and socket address
3、函数指针和指针函数
fatal: unsafe repository is owned by someone else 的解决方法
MFC timer usage
[development environment] install the visual studio community 2013 development environment (download the installation package of visual studio community 2013 with update 5 version)
buuctf-pwn write-ups (7)
Edit the formula with MathType, and set it to include only mathjax syntax when copying and pasting
Full of knowledge points, how to use JMeter to generate encrypted data and write it to the database? Don't collect it quickly
taobao.logistics.dummy.send( 无需物流发货处理 )接口,淘宝店铺发货API接口,淘宝订单发货接口,淘宝r2接口,淘宝oAu2.0接口
Large top heap, small top heap and heap sequencing
C#代码审计实战+前置知识
【NOI模拟赛】刮痧(动态规划)
一张图彻底掌握prototype、__proto__、constructor之前的关系(JS原型、原型链)
Threejs controller cube space basic controller + inertia control + flight control
[QNX Hypervisor 2.2用户手册]6.3 Guest与外部之间通信
Reuse and distribution
C code audit practice + pre knowledge