Codeforces_817
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的更多相关文章
随机推荐
- MySQL之插入数据(添加数据)-INSERT
基本语法: INSERT 语句有两种语法形式,分别是 INSERT…VALUES 语句和 INSERT…SET 语句. 1.INSERT...VLAUES语句 INSERT VLAUES的语法格式如下 ...
- 你对Java泛型的理解够深入吗?
泛型 泛型提供了一种将集合类型传达给编译器的方法,一旦编译器知道了集合元素的类型,编译器就可以对其类型进行检查,做类型约束. 在没有泛型之前: /** * 迭代 Collection ,注意 Coll ...
- Java集合概述(上)
Java集合概述(上) 前言 先说说,为什么要写这么一篇博客(我总是喜欢写原因).因为最近到年底了,正好又要准备面试,所以在做各方面的技术总结.而Java集合是Java非常重要的一部分,自己前前后后也 ...
- 洛谷 P2746 [USACO5.3]校园网Network of Schools schlnet Tarjan强连通分量
schlnet ★★★ 输入文件:schlnet.in 输出文件:schlnet.out 简单对比时间限制:1 s 内存限制:128 MB 描述 一些学校连入一个电脑网络.那些学校已订 ...
- Big Event
666DHG的大事记 2019.4.15 \(\text{ }\text{ }\text{ }\)注册洛谷 2019.8.10 \(\text{ }\text{ }\text{ }\)Luogu\(\ ...
- 简述http协议及抓包分析
1:HTTP请求头和响应头的格式 1:HTTP请求格式:<request-line><headers><blank line>[<request-body&g ...
- DataFrame数据合并
一.join 作用:默认情况下,他是把行索引相同的数据合并到一起注意:以左为准,没有的部分用NaN补全 例子 import pandas as pd import numpy as np df1 = ...
- JS 头像显示
HTML <div class="form-group"> <label class="col-sm-3 control-label"> ...
- 13.系统总结static
static修饰属性和方法: package com.oop.demo08; //static :被static修饰的变量或者方法随类加载,从属于类,当然对象也可以调用 public class St ...
- 2.Java程序运行机制
1.编译型:compile,把所有东西翻译好,若有更新需要重新全部翻译.执行速度够快,对操作系统要求比较低.开发操作系统时用到编译型语言,例如c/c++...运行时需编译整个程序 2.解释性:运行一个 ...