A.要求坐标差为移动距离的两倍。

#include<bits/stdc++.h>
using namespace std; int main()
{
ios::sync_with_stdio();
int x1,x2,y1,y2,x,y;
cin >> x1 >> y1 >> x2 >> y2 >> x >> y;
int xx = abs(x1-x2),yy = abs(y1-y2);
if(xx%x || yy%y)
{
cout << "NO" << endl;
return ;
}
if(xx/x% == yy/y%) cout << "YES" << endl;
else cout << "NO" << endl;
return ;
}

B.分4种情况分别计算。

#include<bits/stdc++.h>
using namespace std; int n,a[]; int main()
{
ios::sync_with_stdio();
cin >> n;
for(int i = ;i <= n;i++) cin >> a[i];
sort(a+,a++n);
int num = ,cnt = ;
if(a[] != a[]) num++;
if(a[] != a[]) num++;
if(num == )
{
for(int i = ;i <= n;i++)
{
if(a[i] == a[]) cnt++;
}
cout << (long long)cnt*(cnt-)*(cnt-)/ << endl;
}
else if(num == && a[] != a[])
{
for(int i = ;i <= n;i++)
{
if(a[i] == a[]) cnt++;
}
cout << (long long)cnt*(cnt-)/ << endl;
}
else
{
for(int i = ;i <= n;i++)
{
if(a[i] == a[]) cnt++;
}
cout << cnt << endl;
}
return ;
}

C.若x符合,则x+1肯定符合,可以二分最小的x。

#include<bits/stdc++.h>
using namespace std; long long n,s; bool ok(long long x)
{
long long t = x;
while(t)
{
x -= t%;
t /= ;
}
if(x >= s) return ;
return ;
} int main()
{
ios::sync_with_stdio();
cin >> n >> s;
long long l = ,r = n+;
while(l < r)
{
long long mid = (l+r)/;
if(ok(mid)) r = mid;
else l = mid+;
}
cout << n-l+ << endl;
return ;
}

D.l[i]表示i坐标第一个大于等于a[i]的位置,r[i]表示r右边第一个大于a[i]的位置,这样a[i]被当作max算的次数可以求出。减min只要把每个位置的数取负做相同操作。

#include<bits/stdc++.h>
using namespace std; int n,a[],l[],r[];
long long ans = ; void f()
{
for(int i = ;i <= n;i++)
{
l[i] = i-;
while(l[i] >= && a[i] > a[l[i]]) l[i] = l[l[i]];
}
for(int i = n;i >= ;i--)
{
r[i] = i+;
while(r[i] <= n && a[i] >= a[r[i]]) r[i] = r[r[i]];
}
for(int i = ;i <= n;i++)
ans += (long long)(r[i]-i)*(i-l[i])*a[i];
} int main()
{
ios::sync_with_stdio();
cin >> n;
for(int i = ;i <= n;i++) cin >> a[i];
f();
for(int i = ;i <= n;i++) a[i] = -a[i];
f();
cout << ans << endl;
return ;
}

E.01异或trie树,把每个数按位分。

#include<bits/stdc++.h>
using namespace std; int n,tr[][] = {},cnt[],sz = ; void add(int x,int v)
{
int now = ;
for(int i = ;i >= ;i--)
{
int t = bool((<<i)&x);
if(!tr[now][t]) tr[now][t] = ++sz;
now = tr[now][t];
cnt[now] += v;
}
} int getsum(int x,int y)
{
int now = ,ans = ;
for(int i = ;i >= ;i--)
{
int xt = bool((<<i)&x),yt = bool((<<i)&y);
if(!yt && !tr[now][xt]) break;
if(!yt) now = tr[now][xt];
else
{
if(tr[now][xt]) ans += cnt[tr[now][xt]];
if(!tr[now][!xt]) break;
now = tr[now][!xt];
}
}
return ans;
} int main()
{
ios::sync_with_stdio();
cin >> n;
while(n--)
{
int x,y,z;
cin >> x >> y;
if(x == ) add(y,);
else if(x == ) add(y,-);
else
{
cin >> z;
cout << getsum(y,z) << endl;
}
}
return ;
}

Codeforces_817的更多相关文章

随机推荐

  1. docker练习-群

    了解Swarm集群 群集是一组运行Docker并加入群集的计算机.在此之后,继续运行使用的Docker命令,但现在它们由群集管理器在群集上执行.群中的机器可以是物理的或虚拟的.加入群组后,它们被称为节 ...

  2. Win10系统下应用窗口任务栏居中效果

    实现步骤: 在资源管理器中新建文件夹,一定要保证文件夹内无任何文件 任务栏上鼠标右键,移动到工具栏上,选择新建工具栏 选择新建的空文件夹 空文件夹出现在任务栏后,鼠标可以拖动工具栏前的两条竖线(图片上 ...

  3. CF1200D White Lines | 前缀和

    传送门 Examples input 1 4 2 BWWW WBBW WBBW WWWB output 1 4 input 2 3 1 BWB WWB BWB output 2 2 input 3 5 ...

  4. hexo零基础搭建博客系列(一)

    关于其他搭建 [hexo4快速搭建博客(二)更换主题](https://blog.csdn.net/weixin_41800884/article/details/103750634)[hexo4快速 ...

  5. AES中ECB模式的加密与解密(Python3.7)

    本文主要解决的问题 本文主要是讲解AES加密算法中的ECB模式的加密解密的Python3.7实现.具体AES加密算法的原理这里不做过多介绍,想了解的可以参考文末的参考链接. 主要解决了两个问题: 在P ...

  6. OpenLayers 笔记

    1.加载ArcGIS MapServer var pipeLayer=new ol.layer.Tile({ extent: [11827395.404512288,3049293.321033439 ...

  7. MySQL 物理备份工具-xtrabackup

    安装 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo yum -y install perl ...

  8. Unity 基于Cinemachine计算透视摄像机在地图中的移动范围

    Unity中Cinemachine的基础功能介绍可详见之前写的博客: https://www.cnblogs.com/koshio0219/p/11820654.html 本篇的重点是讨论,在给定规则 ...

  9. 怎样使用七牛云CDN加速并绑定阿里云域名

    昨天晚上在某个群里看到群友问,七牛云能不能绑定自己的域名作为静态资源文件的前缀,忽然想起来我已经有快两年时间没有登录过我的七牛云账号了,不禁老脸一红,这是有多久没有自己前后端都弄了,幸好还没有老年痴呆 ...

  10. C#与JavaScript中URL编码解码问题(转)

    混乱的URI编码 JavaScript中编码有三种方法:escape.encodeURI.encodeURIComponent C#中编码主要方法:HttpUtility.UrlEncode.Serv ...