牛客练习赛 66

A.平方数

讨论一下最接近它的两个平方数即可。

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{IO;int T=1;//cin>>T;while(T--){ll x;cin>>x;ll y=sqrt(x);ll z=y+1;z*=z;y*=y;if(abs(y-x)<abs(z-x)) cout<<y<<'\n';else cout<<z<<'\n';}return 0;
}

B.异或图

首先我们要知道一个性质x⊕x=0x\oplus x=0xx=0
设起点为sss,终点为ttt,如果存在一条路径s−>p1−>p2−>pi−>es->p_1->p_2->p_i->es>p1>p2>pi>e那么说明有以下等式a[s]⊕a[p1]=ka[p1]⊕a[p2]=ka[p2]⊕a[pi]=ka[pi]⊕a[t]=ka[s]\oplus a[p_1]=k \\ a[p_1]\oplus a[p_2]=k \\a[p_2]\oplus a[p_i]=k\\ a[p_i]\oplus a[t]=ka[s]a[p1]=ka[p1]a[p2]=ka[p2]a[pi]=ka[pi]a[t]=k我们不难发现如果有一条路径能够使得s−>⋯−>ts->\dots->ts>>t说明a[s]⊕a[e]=0/ka[s] \oplus a[e]=0/ka[s]a[e]=0/k,并且明显如果a[s]⊕a[e]=ka[s] \oplus a[e]=ka[s]a[e]=k答案是111,如果a[s]⊕a[e]=0a[s] \oplus a[e]=0a[s]a[e]=0需要判断是否有中间点即a[e]⊕ka[e]\oplus ka[e]k是否存在即可,如存在答案是222,否则不存在路径答案是−1-11
刚开始以为2202^{20}220很大数组开不下,用unordered_map存的个数,结果一直T,最后发现数组能开下直接就A了。~。·

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1100010;
int a[N],cnt[N];
int n,q;
int main()
{scanf("%d%d",&n,&q);for(int i=1;i<=n;i++){scanf("%d",&a[i]);cnt[a[i]]++;}while(q--){int k,st,ed;scanf("%d%d%d",&k,&st,&ed);if((a[st]^a[ed])==k) printf("1\n");else{int x=a[st]^k,y=a[ed]^k;if(x!=y||!cnt[x]) printf("-1\n");else printf("2\n");}}return 0;
}

C.公因子

辗转相除法扩展可得以下式子,然后不难乱搞求解
gcd(a1,a2,a3,…,an)=gcd(a1,a2−a1,a3−a2,…,an−an−1)gcd(a_1,a_2,a_3,\dots,a_n)=gcd(a_1,a_2-a_1,a_3-a_2,\dots,a_n-a_{n-1})gcd(a1,a2,a3,,an)=gcd(a1,a2a1,a3a2,,anan1)

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1100010;
ll a[N];
int n;
ll gcd(ll a,ll b)
{return b?gcd(b,a%b):a;
}
int main()
{IO;int T=1;//cin>>T;while(T--){cin>>n;for(int i=1;i<=n;i++) cin>>a[i];sort(a+1,a+1+n);ll d=a[2]-a[1];for(int i=3;i<=n;i++) d=gcd(d,a[i]-a[i-1]);if(d<0) d=-d;ll res=abs(a[1]/d*d-a[1]);cout<<d<<' '<<res<<'\n';}return 0;
}

E.骚区间

参考大佬题解
一般这种区间左右端点都不确定的情况,我们尝试固定一段点,求另一个端点的可行范围。
对于i位置作为左端点,考虑如何求右端点的合法区间,由于a[i]是第二小值,在[i+1,n]范围内第一个小于a[i]的位置是l1,在[i+1,n]范围内第二个小于a[i]的位置是r1,不难看出对于[l1,r1)范围满足左区间限制条件。
对于i位置作为右端点,我们同样可以如法炮制的求出满足右端点限制条件的区间(l2,r2]
我们可以维护一个树状数组差分求得答案。

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1000010;
int a[N],n;
struct node
{int l,r;int mx,mn;
}tree[N*4];
void pushup(int u)
{tree[u].mx=max(tree[u<<1].mx,tree[u<<1|1].mx);tree[u].mn=min(tree[u<<1].mn,tree[u<<1|1].mn);
}
void build(int u,int l,int r)
{tree[u]={l,r,0,n+1};if(l==r){tree[u].mx=tree[u].mn=a[l];return;}int mid=l+r>>1;build(u<<1,l,mid),build(u<<1|1,mid+1,r);pushup(u);
}
int query_min(int u,int l,int r,int x)
{if(l>r) return n+1;if(tree[u].mn>=x) return n+1;if(tree[u].l==tree[u].r) return tree[u].l;int mid=tree[u].l+tree[u].r>>1;if(l>mid) return query_min(u<<1|1,l,r,x);else if(r<=mid) return query_min(u<<1,l,r,x);else{if(tree[u<<1].mn<x){int v=query_min(u<<1,l,r,x);return v!=n+1?v:query_min(u<<1|1,l,r,x);}elsereturn query_min(u<<1|1,l,r,x);}
}
int query_max(int u,int l,int r,int x)
{if(l>r) return 0;if(tree[u].mx<=x) return 0;if(tree[u].l==tree[u].r) return tree[u].l;int mid=tree[u].l+tree[u].r>>1;if(l>mid) return query_max(u<<1|1,l,r,x);else if(r<=mid) return query_max(u<<1,l,r,x);else{if(tree[u<<1|1].mx>x) {int v=query_max(u<<1|1,l,r,x);return v?v:query_max(u<<1,l,r,x);}else return query_max(u<<1,l,r,x);}
}
vector<int> p[N];
int cnt[N];
int lowbit(int x)
{return x&-x;
}
void update(int k,int x)
{for(;k<=n;k+=lowbit(k)) cnt[k]+=x;
}
ll query(int k)
{ll now=0;for(;k;k-=lowbit(k)) now+=cnt[k];return now;
}
int main()
{int T=1;//cin>>T;while(T--){scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%d",&a[i]);build(1,1,n);ll res=0;for(int i=1;i<=n;i++){int l=query_min(1,i+1,n,a[i]);int r=query_min(1,l+1,n,a[i]);if(l!=n+1) p[l].push_back(i);if(r!=n+1) p[r].push_back(-i);for(auto t:p[i]){if(t>0) update(t,1);else update(-t,-1);}r=query_max(1,1,i-1,a[i]);l=query_max(1,1,r-1,a[i]);res+=query(r)-query(l);}printf("%lld\n",res);}return 0;
}

要加油哦~

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/319578.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

在你的andorid设备上运行netcore (Linux Deploy)

最近注意到.net core 的新版本已经开始支持ARM 平台的CPU, 特意去Linux Deploy 中尝试了一下&#xff0c;真的可以运行 Welcome to Ubuntu 16.04 LTS (GNU/Linux 4.9.65-perf armv8l)* Documentation: https://help.ubuntu.com/Ubuntu 16.04 LTS [running via Linux Deploy]La…

【每日一题】8月6日题目精讲—追债之旅

来源&#xff1a;牛客网&#xff1a; 时间限制&#xff1a;C/C 1秒&#xff0c;其他语言2秒 空间限制&#xff1a;C/C 65536K&#xff0c;其他语言131072K 64bit IO Format: %lld文章目录题目描述题解&#xff1a;代码&#xff1a;题目描述 小明现在要追讨一笔债务&#xff0c…

【结论】只不过是长的领带(luogu 6877)

正题 luogu 6877 题目大意 给你n1个数aia_iai​和n个数bib_ibi​&#xff0c;cic_ici​为不选aia_iai​时&#xff0c;重新调整剩下n个数的位置后&#xff0c;∑i1nmax(ai−aj)\sum \limits_{i1}^{n}max(a_i-a_j)i1∑n​max(ai​−aj​)的最小值,求c数组 解题思路 不难发现让…

P3273-[SCOI2011]棘手的操作【线段树,并查集】

正题 题目链接:https://www.luogu.com.cn/problem/P3273 题目大意 nnn个点有权值&#xff0c;要求支持操作 连接两个点单点加权联通块加权全图加权单点询问联通块询问最大值全图询问最大值 解题思路 把所有可能产生的联通块都变到一个区间里就好了 考虑怎么排这个东西&…

牛客练习赛 65 (待补E-网络流)

A.最值序列 排序后&#xff0c;前一半加后一半乘即可。 #define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #pragma GCC optimize(2) #include<iostream> #include<algorithm> using namespace std; typedef long long ll; const int N500010; cons…

持续集成配置之Nuget

Intro本文是基于微软的 VSTS(Visual Studio Team Service) 做实现公众类库的自动打包及发布。之前自己的项目有通过 Github 上的 Travis 和 Appveyor&#xff0c;这次主要是用 VSTS 来做的&#xff0c;对比 appveyor 和 vsts 上的持续集成&#xff0c;vsts 上微软把常用的工具和…

【每日一题】8月7日题目精讲—双栈排序

来源&#xff1a;牛客网 文章目录题目描述题意&#xff1a;题解&#xff1a;代码&#xff1a;时间限制&#xff1a;C/C 1秒&#xff0c;其他语言2秒 空间限制&#xff1a;C/C 131072K&#xff0c;其他语言262144K 64bit IO Format: %lld题目描述 Tom最近在研究一个有趣的排序问…

【期望DP】概率充电器(luogu 4284)

正题 luogu 4284 题目大意 给你棵树&#xff0c;第i个点自己通电的概率是wiw_iwi​&#xff0c;第j条边连接的两个点之间通电的概率是pjp_jpj​&#xff0c;问你通电的点个数的期望值 题目大意 设fif_ifi​为第i个点通电的概率&#xff0c;那么&#xff1a; fisolvej∈link{…

P3760-[TJOI2017]异或和【树状数组】

正题 题目链接:https://www.luogu.com.cn/problem/P3760 题目大意 给出nnn个数字的一个序列aaa&#xff0c;求它所有区间和的异或和 n≤105,∑ai≤106n\leq 10^5,\sum a_i\leq 10^6n≤105,∑ai​≤106 解题思路 开始写了个前缀和FFTFFTFFT发现要卡常然后就换了个方法。 每一…

手把手教你搭APM之Skywalking搭建指南(支持Java/C#/Node.js)

前言什么是APM?全称:Application Performance Management可以参考这里:现代APM体系&#xff0c;基本都是参考Google的Dapper&#xff08;大规模分布式系统的跟踪系统&#xff09;的体系来做的。通过跟踪请求的处理过程&#xff0c;来对应用系统在前后端处理、服务端调用的性能…

牛客练习赛 64——错排

A.怪盗-1412 111…1⏟⌊n2⌋444…4⏟m111…1⏟⌈n2⌉222…2⏟k\begin{matrix} \underbrace{ 111\dots\ 1} \\ \lfloor \frac{n}{2} \rfloor \end {matrix}\begin{matrix} \underbrace{ 444\dots\ 4} \\ m \end{matrix}\begin{matrix} \underbrace{ 111\dots\ 1} \\ \lceil \fra…

牛客网状压dp

状压dp 视频链接 &#xff08;如果想购买网课&#xff0c;可以用我的邀请码&#xff09; 用我的链接购买&#xff0c;我再反你10&#xff0c;一共花54多值 购买链接 不放心可以先加我好友2830872914 总试题链接 文章目录状压dp预备知识——位运算例题&#xff1a;引入&#x…

【线段树】海报(loj 3264)

正题 loj 3264 题目大意 有一个环&#xff0c;环上n个点&#xff0c;权值为a&#xff0c;有m次修改&#xff0c;每次修改一个aia_iai​&#xff0c;然后让你选取一些数&#xff0c;使环上不存在连续四个以上的数被选取&#xff0c;让你求所选数的最大权值和 解题思路 不难想…

P4338-[ZJOI2018]历史【LCT】

正题 题目链接:https://www.luogu.com.cn/problem/P4338 题目大意 给出nnn个点的一棵树&#xff0c;和每个点进行accessaccessaccess的次数aia_iai​&#xff0c;要求安排一个顺序使得虚实边转换最多。 mmm次修改一个点让aia_iai​加上www后求答案 n,m∈[1,4∗105],ai,w∈[1,…

小G有一个大树

来源&#xff1a;牛客网 &#xff1a; 时间限制&#xff1a;C/C 1秒&#xff0c;其他语言2秒 空间限制&#xff1a;C/C 32768K&#xff0c;其他语言65536K 64bit IO Format: %lld题目描述 小G想要把自己家院子里的橘子树搬到家门口&#xff08;QAQ。。就当小G是大力水手吧&…

.Net Core功能开关实战

为了快速发布开发完成的功能&#xff0c;企业通常会以比较快的迭代周期持续发布。但是由于某些 原因或场景&#xff0c;需要在发布的时候将某些功能隐藏起来或者小规模的开放&#xff08;例如只有某些特定用户可以使用、或者特定日期开放&#xff09;&#xff0c;通过使用功能开…

AtCoder Beginner Contest 179 总结

A - Plural Form 模拟签到题1 #define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #pragma GCC optimize(2) #include<string> #include<iostream> #include<algorithm> using namespace std; const int N100010; int main() {IO;int T1;//cin…

纪中A组模拟赛总结(2021.7.19)

成绩 rankrankranknamenamenamescorescorescoreT1T1T1T2T2T2T3T3T3101010lyflyflyf175175175000757575100100100 前言&#xff1a;进前10啦&#xff01;&#xff01; 总结 T1看着推了一下&#xff0c;发现可以改变答案的解决顺序&#xff0c;然后在O(n)内求解&#xff0c;打完…

AT4505-[AGC029F]Construction of a tree【构造题,hall定理,网络流】

正题 题目链接:https://www.luogu.com.cn/problem/AT4505 题目大意 给出nnn个点和n−1n-1n−1个点集UiU_iUi​&#xff0c;每个点集中选择两个点连边使得该图是一棵树。求方案。 n∈[1,105],∑i1n−1∣Ui∣∈[1,2∗105]n\in[1,10^5],\sum_{i1}^{n-1} |U_i|\in[1,2*10^5]n∈[1…

学习究竟是为了什么?

今天无意中看到一句话&#xff0c;人如果停止了学习&#xff0c;就开始走向失败。这句话其实应该送给每一个面临30岁焦虑期的开发者&#xff0c;同时也应该成为每一个开发者内心的真实写照。 想问一下大家一个问题&#xff0c;多久没有学习新的知识呢&#xff1f;尤其…