题目分析在代码注释里。

int main() {
#if defined LOCAL && !defined DUIPAI
ifstream in("main.in");
cin.rdbuf(in.rdbuf());
// ofstream out("main.out");
// cout.rdbuf(out.rdbuf());
#endif
int n, q;
scan(n, q);
vi a(n);
scan(a);
vl sum(n);
sum[0] = a[0];
rng (i, 1, n) {
sum[i] = a[i] + sum[i - 1];
}
vl parity_sum(n);
parity_sum[0] = a[0];
parity_sum[1] = a[1];
rng (i, 2, n) {
parity_sum[i] = a[i] + parity_sum[i - 2];
} rep (q) {
int x;
scan(x);
// 二分查找Aoki拿走的最大的数。
// 设Aoki拿走的最大的数是a[i]。
// 拿了a[i]之后,Aoki手里共有 i + 1 - LB(a, x - abs(x - a[i])) 个数。
// 而此时Takahashi手里至多有n - i 个数,因此i必须满足i + 1 - LB(a, x - abs(x - a[i])) <= n - i
int l = 0, r = n - 1;
while (l + 1 < r) {
bool flag = false;
int mid = get_mid(l, r);
int at_most = n - 1 - mid;
auto t = LB(a, x - abs(x - a[mid]));
int taken = mid - t + 1;
if (taken <= at_most) {
l = mid;
} else {
r = mid;
}
}
ll ans = sum[n - 1] - sum[l];
int num = n - 1 - l;
if (n - 2 * num - 1 >= 0) {
ans += parity_sum[n - 2 * num - 1];
}
println(ans);
}
#if defined LOCAL && !defined DUIPAI
cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}

AtCoder AISing Programming Contest 2019 Task D. Nearest Card Game的更多相关文章

  1. [AtCoder] NIKKEI Programming Contest 2019 (暂缺F)

    [AtCoder] NIKKEI Programming Contest 2019   本来看见这一场的排名的画风比较正常就来补一下题,但是完全没有发现后两题的AC人数远少于我补的上一份AtCoder ...

  2. [AtCoder] Yahoo Programming Contest 2019

    [AtCoder] Yahoo Programming Contest 2019   很遗憾错过了一场 AtCoder .听说这场是涨分场呢,于是特意来补一下题. A - Anti-Adjacency ...

  3. 【AtCoder】AISing Programming Contest 2019

    本来以为是1199rated的..仔细一看发现是1999,所以就做了一下 这场涨分很轻松啊...为啥又没打 等pkuwc考完我一定打一场atcoder(咕咕咕,咕咕咕,咕咕咕咕咕咕咕~) 但是其实我思 ...

  4. AISing Programming Contest 2019 Solution

    A - Bulletin Board 签到. #include <bits/stdc++.h> using namespace std; int main() { int n, h, w; ...

  5. AtCoder NIKKEI Programming Contest 2019 C. Different Strokes (贪心)

    题目链接:https://nikkei2019-qual.contest.atcoder.jp/tasks/nikkei2019_qual_C 题意:给出 n 种食物,Takahashi 吃下获得 a ...

  6. AtCoder NIKKEI Programming Contest 2019 E. Weights on Vertices and Edges (并查集)

    题目链接:https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_e 题意:给出一个 n 个点 m 条边的无向图,每个点和每 ...

  7. atcoder NIKKEI Programming Contest 2019 E - Weights on Vertices and Edges

    题目链接:Weights on Vertices and Edges 题目大意:有一个\(n\)个点\(m\)条边的无向图,点有点权,边有边权,问至少删去多少条边使得对于剩下的每一条边,它所在的联通块 ...

  8. AISing Programming Contest 2019 翻车记

    A:签到. #include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> ...

  9. Atcoder Yahoo Programming Contest 2019 简要题解

    A-C 直接放代码吧. A int n,k; int main() { n=read();k=read(); puts(k<=(n+1)/2?"YES":"NO&q ...

随机推荐

  1. [Hdoj] Fast Matrix Calculation

    题面:http://acm.hdu.edu.cn/showproblem.php?pid=4965 题解:https://www.zybuluo.com/wsndy-xx/note/1153981

  2. Vue(一)

    什么是Vue? 用于构建用户界面的渐进式框架

  3. 【线性代数】6-3:微分方程的应用(Applications to Differential Equations)

    title: [线性代数]6-3:微分方程的应用(Applications to Differential Equations) categories: Mathematic Linear Algeb ...

  4. vue3.x 错误记录

    1:css报错 This dependency was not found: * !!vue-style-loader!css-loader?{"minimize":false,& ...

  5. 什么是CSR

    CSR的全称是Certificate Signing Request. 是我们在申请Https证书是向CA所提供的一杯申请书.其内部储存了我们申请证书所需要的基本信息.它是一个经过Base64编码的纯 ...

  6. vue pdf下载

    主要技术栈是Vue,两个库: html2canvas npm地址 jspdf 具体实现代码如下: <template> <div class="priview_resume ...

  7. 2-SAT两题

    看了大白书,学习了一下two-sat,很有意思的算法.题目就是大白书上的两题. 仅仅放一下代码作为以后的模板参考. #include <stdio.h> #include <algo ...

  8. 【Phoenix】1、搭建 Phoenix 环境

    Ps: 需要注意的是,我学习的时候,Elixir 是 1.8.1的版本,而 Phoenix 是 1.4.1的版本,对于其他版本,不一定正确. 1.安装 Phoenix 之前,先安装 Elixir. 2 ...

  9. 【SpringBoot】SpringBoot/MyBatis/MySql/thymeleaf/Log4j整合工程

    工程下载地址:https://files.cnblogs.com/files/xiandedanteng/MMSpringWeb20191027-1.rar 工程目录结构如图: 1.创建工程 有些网文 ...

  10. JDBC的异常处理方式

    A: try...catch(...) {...} finally {} B: 关闭ResultSet,Statement , Connection import java.sql.Connectio ...