http://codeforces.com/contest/1030

B. Vasya and Cornfield

判断点是否在矩形内(包括边界)

把每条边转化为一个不等式

  public static void main(String[] args) {
IO io = new IO();
int n = io.nextInt(), d = io.nextInt();
int t = io.nextInt();
while (t-- > 0) {
int x = io.nextInt(), y = io.nextInt();
io.println(d <= x + y && x + y <= 2 * n - d &&
-d <= y - x && y - x <= d ? "YES" : "NO");
}
}

C. Vasya and Golden Ticket

给你一串数列,问该数列是否可以分为若干相邻且不相交的区间,每个区间和相等

枚举第一个区间的所有情况

     public static void main(String[] args) {
IO io = new IO();
int n = io.nextInt();
int[] sum = new int[n + 1];
int s = 0, k = 0, j;
for (int i = 1; i <= n; i++) sum[i] = io.nextChar() - '0' + sum[i - 1];
for (int i = 1; i < n; i++)
for (k = i, j = i + 1; j <= n; j++)
if (sum[j] - sum[k] == sum[i]) {
k = j;
if (sum[k] == sum[n]) {
io.println("YES");
return;
}
}
io.println("NO");
}

D. Vasya and Triangle

问是否存在三个点,每个点的横纵坐标范围是[0,n]、[0,m],且三个点围成的三角形面积为n*m/k

我们选择坐标轴上的点(0,0)、(x,0)、(0,y),得到x*y=2*m*n/k,关键是k的消去可能是2、n、m都贡献了因子,所以才要求最大公约数保证整除,2m算一个数还是2n算一个数要分情况讨论,不然乘以2了还只除以gcd=1会超过范围

     public static void main(String[] args) {
IO io = new IO();
long n = io.nextInt(), m = io.nextInt(), k = io.nextInt();
if (n * m * 2 % k != 0) io.println("NO");
else {
long g = gcd(2 * n, k);
if (g == 1) m = 2 * m / k;
else {
n = 2 * n / g;
m = m * g / k;
}
io.println("YES");
io.println("0 0");
io.println(n + " 0");
io.println("0 " + m);
}
}

E. Vasya and Good Sequences

给你一个数列,对于每个数,你可以任意交换它的二进制表示里的任意一对01,问这个数列最多有几个连续的区间,使其操作后的数字异或和为0

当区间内所有数的1的总和为偶数且不会出现一半以上的1都在1个数里时,该区间合法 。具体做法:求出所有可能,然后减去区间1的总和为偶数且一半以上的1都在1个数里的情况;

a[i]:将每个数替换为其二进制表示中1的个数

s[i]:a[i]前缀和,此时每个区间都可表示为si-sj的形式。当si为奇数时sj必须存在且也为奇数,这样组成的区间[j,i]里1的个数和才为偶数,此时si的贡献为[1,i)里奇数项的个数;当s[i]为偶数时,其贡献为[1,i]里偶数项的个数,多出来的情况是sj不存在的[1,i]。

(该题有个小却一缺即超的优化,已在代码里标出)

     public static void main(String[] args) {
IO io = new IO();
int n = io.nextInt();
int[] a = new int[n + 1];
int[] s = new int[n + 1];
int[] s1 = new int[n + 1];
int[] s0 = new int[n + 1];
long ans = 0, t, max;
for (int i = 1; i <= n; i++)
for (t = io.nextLong(); t != 0; t >>= 1)
a[i] += (t & 1);
for (int i = 1; i <= n; i++) {
s[i] = s[i - 1] + a[i];
s1[i] = s1[i - 1];
s0[i] = s0[i - 1];
if (s[i] % 2 == 1) ans += s1[i]++;
else ans += ++s0[i];
}
for (int i = 1; i <= n; i++) {
max = 0;
//j - i + 1 < 65
for (int j = i; j <= n && j - i + 1 < 65; j++) {
max = Math.max(max, a[j]);
if ((s[j] - s[i - 1]) % 2 == 0 && s[j] - s[i - 1] < max * 2) ans--;
}
}
io.println(ans);
}

F. Putting Boxes Together

一列上有n个盒子,每个盒子有自己的重量,移动一个重量为wi的盒子一个单位花费能量wi,现在有两种操作:1、改变某个盒子的重量,2、输出把第[l,r]的盒子放在一起(起点任意,只要每个都挨在一起)所需的最小能量

(树状数组:https://www.cnblogs.com/towerbird/p/9941030.html

不妨首先把盒子都移到[1,n],我们贪心地认为能量最少的方案应该是[l,r]里wi正好把总w分成最均等的两部分的盒子mid不移动,则答案是把所有盒子移动到[1,n]的能量减去右移a[mid]-mid的能量,注意mid左边的盒子贡献要取负数,右边的取正数。用二分查找找出mid。

(a、w下标以0开始怎么都错……为什么啊)

     private static final int c = (int) (2e5 + 10), mod = (int) (1e9 + 7);
static int n, q;
static long[] a = new long[c];
static long[] w = new long[c];
static long[][] tre = new long[c][2]; static void update(int i, long x, int j) {
while (i <= n) {
tre[i][j] += x;
if (j == 1) tre[i][j] %= mod;
i += i & -i;
}
} static long query(int i, int j) {
long s = 0;
while (i > 0) {
s += tre[i][j];
if (j == 1) s %= mod;
i -= i & -i;
}
return s;
} public static void main(String[] args) {
IO io = new IO();
n = io.nextInt();
q = io.nextInt();
for (int i = 0; i < n; i++) a[i] = io.nextLong();
for (int i = 0; i < n; i++) {
update(i + 1, w[i] = io.nextLong(), 0);
update(i + 1, w[i] * (a[i] - i), 1);
}
while (q-- > 0) {
int x = io.nextInt(), y = io.nextInt();
if (x < 0) {
x = -x - 1;
update(x + 1, y - w[x], 0);
update(x + 1, (y - w[x]) * (a[x] - x), 1);
w[x] = y;
} else {
long s = query(y, 0) + query(x - 1, 0), c = 0;
int mid = 0;
for (int i = 17; i >= 0; i--)
if (mid + (1 << i) < n && (c + tre[mid + (1 << i)][0]) * 2 < s) {
mid += 1 << i;
c += tre[mid][0];
}
long a1 = query(y, 1) - 2 * query(mid, 1) + query(x-1, 1);
long a2 = query(y, 0) - 2 * query(mid, 0) + query(x-1, 0);
//+ 2 * mod是出现了负无穷大的情况
long ans = a1 % mod - a2 % mod * (a[mid] - mid) % mod + 2 * mod;
io.println(ans % mod ); }
}
}

G. Linear Congruential Generator——我选择狗带o( ̄┰ ̄*)ゞ

Technocup 2019 - Elimination Round 1的更多相关文章

  1. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)

    Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...

  2. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)B. Personalized Cup

    题意:把一长串字符串 排成矩形形式  使得行最小  同时每行不能相差大于等于两个字符 每行也不能大于20个字符 思路: 因为使得行最小 直接行从小到大枚举即可   每行不能相差大于等于两个字符相当于  ...

  3. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) C. Playing Piano

    题意:给出一个数列 a1 a2......an  让你构造一个序列(该序列取值(1-5)) 如果a(i+1)>a(i) b(i+1)>b(i) 如果a(i+1)<a(i)  那么b( ...

  4. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) D. Barcelonian Distance 几何代数(简单)

    题意:给出一条直线 ax +by+c=0  给出两个整点 (x1,y1) (x2,y2) 只有在x,y坐标至少有一个整点的时 以及   给出的直线才有路径(也就是格子坐标图的线上) 问 两个整点所需要 ...

  5. Technocup 2019 - Elimination Round 2

    http://codeforces.com/contest/1031 (如果感觉一道题对于自己是有难度的,不要后退,懂0%的时候敲一遍,边敲边想,懂30%的时候敲一遍,边敲边想,懂60%的时候敲一遍, ...

  6. (AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round

    A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path

    http://codeforces.com/contest/1072/problem/D bfs 走1步的最佳状态 -> 走2步的最佳状态 -> …… #include <bits/ ...

  8. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path(字典序)

    https://codeforces.com/contest/1072/problem/D 题意 给你一个n*n充满小写字母的矩阵,你可以更改任意k个格子的字符,然后输出字典序最小的从[1,1]到[n ...

  9. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) Solution

    A. Kitchen Utensils Water. #include <bits/stdc++.h> using namespace std; #define N 110 int n, ...

随机推荐

  1. vue(7)—— 组件化开发 — webpack(1)

    引子 在研究完前面的vue开发后,其实已经可以自己开发点东西了,靠前面的指令集,组件,还有vue-router,还有异步请求这些知识点,是完全可以开发出来的,完全可以达到时下前后端分离的效果. 但是, ...

  2. Java 控制结构与方法

    控制结构: 控制结构是对我们程序执行顺序的一种控制,它规定了我们语句块的执行顺序和流程. 分支结构: 关系运算符和逻辑运算符: 关系运算符:== != > >= < <=逻辑运 ...

  3. js坚持不懈之16:使用js向HTML元素分配事件

    向 button 元素分配 onclick 事件: <!DOCTYPE html> <html> <body> <p>点击按钮就可以执行 <em& ...

  4. .Net Core 在Linux服务器下部署程序--(3). 部署.net Core程序

    确认第二步中的软件已安装完成 lrzsz文件上传下载软件 zip与unzip压缩包软件 net core 相关软件 确认上述软件安装完成之后,开始部署程序 创建部署文件夹 我的习惯是在usr文件夹下新 ...

  5. java jdk动态代理(proxy)

    1. 涉及主要jdk api java.lang.reflect.InvocationHandler: public interface InvocationHandler { /** * Proce ...

  6. 一个ELK日志检索实施案例

    figure:first-child { margin-top: -20px; } #write ol, #write ul { position: relative; } img { max-wid ...

  7. HTML基础-------HTML标签(3)

    HTML标签(3) 表格 作用:制作一个表格 属性: 标签;table>tr>td(或者th) 语义; table:一个表格 tr:一行 td:一个单元格 th:单元格的表头 captio ...

  8. P4013 数字梯形问题 网络流

    题目描述 给定一个由 nn 行数字组成的数字梯形如下图所示. 梯形的第一行有 mm 个数字.从梯形的顶部的 mm 个数字开始,在每个数字处可以沿左下或右下方向移动,形成一条从梯形的顶至底的路径. 分别 ...

  9. 使用RAP2和Mock.JS实现Web API接口的数据模拟和测试

    最近一直在思考如何对Web API的其接口数据进行独立开发的问题,随着Web API的越来越广泛应用,很多开发也要求前端后端分离,例如统一的Web API接口后,Winform团队.Web前端团队.微 ...

  10. nginx 的各种配置

    负载均衡 以上是ip的负载均衡,主要是保证 固定ip地址访问到固定服务,如果不做ip的匹配,那么每次请求的机器都不相同,就会出现问题,sessionid 之类的问题 //修改 路由负载均衡不能写has ...