Comet OJ - Contest #8
Comet OJ - Contest #8
A.杀手皇后
签到。
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1005;
vector <string> v;
int n;
string s;
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> s;
v.push_back(s);
}
sort(v.begin(), v.end());
cout << v[0];
return 0;
}
B.支援城市
把式子拆开就行。
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
int n;
int w[N];
ll sumv, sum;
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) cin >> w[i], sum += w[i];
for(int i = 1; i <= n; i++) sumv += 1ll * w[i] * w[i];
for(int i = 1; i <= n; i++) {
ll ans = sumv + 1ll * n * w[i] * w[i];
ans -= 2ll * w[i] * sum;
cout << ans << " \n"[i == n];
}
return 0;
}
C.符文能量
手玩一下样例,发现答案与合并顺序无关,然后就可以愉快的\(dp\)了。
因为最终序列的状态是有三个阶段的,所以就\(dp[i,0/1/2]\)来表示三种状态,然后分别转移就行。
Code
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
ll n, k;
ll a[N], b[N], c[N];
ll dp[N][3][2];
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];
for(int i = 1; i < n; i++) c[i] = a[i + 1] * b[i];
n--;
for(int i = 1; i <= n; i++) {
dp[i][0][0] = dp[i - 1][0][0] + c[i];
dp[i][0][1] = min(dp[i - 1][0][1], dp[i - 1][1][1]) + c[i];
dp[i][1][0] = dp[i - 1][0][0] + c[i] * k;
dp[i][1][1] = min(dp[i - 1][2][1], dp[i - 1][1][0]) + c[i] * k;
dp[i][2][1] = min(dp[i - 1][2][1], dp[i - 1][1][0]) + c[i] * k * k;
}
ll ans = INF;
ans = min(ans, min(dp[n][0][0], min(dp[n][0][1], min(dp[n][1][0], min(dp[n][1][1], dp[n][2][1])))));
cout << ans;
return 0;
}
还有一种前缀和的搞法,感觉说不太清楚,见代码吧:
Code
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
ll n, k;
ll a[N], b[N], c[N], d[N];
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];
for(int i = 1; i < n; i++) c[i] = a[i + 1] * b[i], d[i] = d[i - 1] + c[i];
n--;
ll ans = min(d[n], d[n] * k * k), Min = 0;
for(int i = 1; i <= n; i++) {
ans = min(ans, c[i] * k + d[i - 1] * k * k + d[n] - d[i] + Min);
Min = min(Min, -d[i] * k * k + c[i] * k + d[i - 1]);
}
cout << ans;
return 0;
}
D.菜菜种菜
题目给出的询问都为连续的区间,考虑离线处理.
将题目所求转化为数学语言就是,对于一段区间[l,r],找到所有的点\(u\),满足对于所有的\((u,v)\),不存在\(v\in [l,r]\)。
那么我们就可以直接对于所有的点找到一个最大区间[L,R],表示在这个区间中,点\(u\)是不能到达任意点的,那么我们对于每个区间\([l,r]\),其中所有的点\(u\)对答案有贡献的话就会满足:\(L\leq l,r\leq R\)。
之后用树状数组进行增删查询的操作就行。
代码如下:
Code
#include <bits/stdc++.h>
#define MP make_pair
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e6 + 5;
int n, m, q;
short a[N];
int l[N], r[N];
vector <pii> v[N];
vector <int> del[N];
int c[N];
int lowbit(int x) {return x & (-x);}
void update(int x, int v) {
for(; x < N; x += lowbit(x)) c[x] += v;
}
ll query(int x) {
ll ans = 0;
for(; x; x -= lowbit(x)) ans += c[x];
return ans;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> m >> q;
memset(r, INF, sizeof(r));
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= m; i++) {
int u, v; cin >> u >> v;
if(v < u) l[u] = max(l[u], v);
else r[u] = min(r[u], v);
}
for(int i = 1; i <= n; i++) {
l[i]++;
if(r[i] == INF) continue;
del[r[i]].push_back(i);
}
for(int i = 1; i <= q; i++) {
int L, R; cin >> L >> R;
v[R].push_back(MP(L, i));
}
ll ans = 0;
for(int i = 1; i <= n; i++) {
update(l[i], a[i]);
update(i + 1, -a[i]);
for(auto it : del[i]) {
update(l[it], -a[it]);
update(it + 1, a[it]);
}
for(auto it : v[i]) {
ans ^= 1ll * it.second * query(it.first);
}
}
cout << ans;
return 0;
}
Comet OJ - Contest #8的更多相关文章
- Comet OJ - Contest #2 简要题解
Comet OJ - Contest #2 简要题解 cometoj A 模拟,复杂度是对数级的. code B 易知\(p\in[l,r]\),且最终的利润关于\(p\)的表达式为\(\frac{( ...
- Comet OJ - Contest #2简要题解
Comet OJ - Contest #2简要题解 前言: 我没有小裙子,我太菜了. A 因自过去而至的残响起舞 https://www.cometoj.com/contest/37/problem/ ...
- Comet OJ - Contest #4--前缀和
原题:Comet OJ - Contest #4-B https://www.cometoj.com/contest/39/problem/B?problem_id=1577传送门 一开始就想着暴力打 ...
- Comet OJ - Contest #11 题解&赛后总结
Solution of Comet OJ - Contest #11 A.eon -Problem designed by Starria- 在模 10 意义下,答案变为最大数的最低位(即原数数位的最 ...
- Comet OJ - Contest #13-C2
Comet OJ - Contest #13-C2 C2-佛御石之钵 -不碎的意志-」(困难版) 又是一道并查集.最近做过的并查集的题貌似蛮多的. 思路 首先考虑,每次处理矩形只考虑从0变成1的点.这 ...
- Comet OJ - Contest #13 「火鼠的皮衣 -不焦躁的内心-」
来源:Comet OJ - Contest #13 芝士相关: 复平面在信息学奥赛中的应用[雾 其实是道 sb 题??? 发现原式貌似十分可二项式定理,然后发现确实如此 我们把 \(a^i\) 替换成 ...
- Comet OJ - Contest #13 「佛御石之钵 -不碎的意志-」(hard)
来源:Comet OJ - Contest #13 一眼并查集,然后发现这题 tmd 要卡常数的说卧槽... 发现这里又要用并查集跳过访问点,又要用并查集维护联通块,于是开俩并查集分别维护就好了 一开 ...
- Comet OJ - Contest #5
Comet OJ - Contest #5 总有一天,我会拿掉给\(dyj\)的小裙子的. A 显然 \(ans = min(cnt_1/3,cnt_4/2,cnt5)\) B 我们可以感性理解一下, ...
- Comet OJ Contest #13 D
Comet OJ Contest #13 D \(\displaystyle \sum_{i=0}^{\left\lfloor\frac{n}{2}\right\rfloor} a^{i} b^{n- ...
随机推荐
- redis的介绍与操作及Django中使用redis缓存
redis VS mysql的区别 """ redis: 内存数据库(读写快).非关系型(操作数据方便) mysql: 硬盘数据库(数据持久化).关系型(操作数据间关系) ...
- 简约清新立体商务年终工作总结汇报动态PPT模板
模版来源:http://ppt.dede58.com/gongzuohuibao/26682.html
- cocos2d游戏jsc文件格式解密,SpideMonkey大冒险
“ 介绍cocos2d游戏中常用的jsc格式文件的解密.” 01 — 在破解游戏应用中,经常会碰到后缀为jsc的文件,这是基于cocos2d开发的游戏的加密代码,本质上是js文件,只是被加密了. 例如 ...
- IDEA编译报错Error:java: Compilation failed: internal java compiler error
根据报错可以知道是编译某个模块报错, 接下来就是检查这个模块的编译版本 解决办法很简单:File-->Setting...-->Build,Execution,Deployment--&g ...
- dnf & yum
CentOS8 配置软件源 在 CentOS8 中.使用了基于DNF技术(YUM v4)的 YUM 工具. YUM v4 与之前在 CentOS7 上使用的 YUM v3 相比具有以下优点: 提高性能 ...
- java8的捕获多个异常的一个写法
这是按intellij idea的提示知道的, 可以写成 catch(xxxException | yyyException | zzzException e){ } 这样的形式,对几个不同的异常使用 ...
- day99_12_3numpy的索引以及pandas的两个数据结构。
一.索引与切片. nump的索引和python中的索引差不多,都是左开右闭区间. 如一个普通的array的索引,是由0开始的: res = np.array([1,2,3,4,5]) #### npa ...
- TopCoder12808 「SRM594Medium」FoxAndGo3 二分图最大独立集
问题描述 一个 \(N \times N\) 围棋棋盘,任意两个白子不相邻,你要加入若干个黑子并提出白子,最大化空格数目. submit 题解 显然最终棋盘的局面不能够一个白子和它周围的空格都是空的, ...
- 权限控制终于来了!Redis 6.0新特性——ACLs
在2019年纽约的Redis Day上,Salvatore Sanfilippo(AKA Antirez)介绍了即将发布的Redis 6.0的新特性.以下是关于ACLs的内容. ACLs简介 在过去的 ...
- Java中的String为什么要设计成不可变的?
一.不可变类和不可变对象 Normally,you create an object and allow its contents to be changed later.However ,occas ...