G. 24 观察 + 树状数组
http://codeforces.com/gym/101257/problem/G
首先要看到题目,题目是本来严格大于score[i] > score[j]。然后score[i] < score[j],的才算做是贡献。
然后这题需要一个小观察,就是只有低分的,不fail,然后高分的,fail了,才会交换位置。
也就是平时打比赛,别人fail了,我不fail,我才和它交换位置。(居然这种思维我都没。T_T)
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = 1e5 + ;
int a[maxn];
double p[maxn];
vector<int>vc;
vector<int>id;
double c[maxn];
int lowbit(int x) {
return x & (-x);
}
void upDate(int pos, double val) {
assert(pos != );
while (pos <= maxn - ) {
c[pos] += val;
pos += lowbit(pos);
}
}
double ask(int pos) {
assert(pos >= );
double ans = ;
while (pos) {
ans += c[pos];
pos -= lowbit(pos);
}
return ans;
}
void work() {
int n, be;
scanf("%d%d", &n, &be);
for (int i = ; i <= n; ++i) {
scanf("%d", &a[i]);
a[i]++;
}
for (int i = ; i <= n; ++i) {
scanf("%lf", &p[i]);
}
double ans = ;
for (int i = ; i <= n; ++i) {
ans += ( - p[i]) * ask(a[i] - );
if (i != n && a[i] == a[i + ]) {
vc.push_back(a[i] - be);
id.push_back(i);
} else {
for (int j = ; j < vc.size(); ++j) {
upDate(vc[j], p[id[j]]);
}
vc.clear();
id.clear();
upDate(a[i] - be, p[i]);
}
}
printf("%0.10f\n", ans);
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}
G. 24 观察 + 树状数组的更多相关文章
- SCUT - G - 魔法项链 - 树状数组
https://scut.online/contest/30/G 很久以前做的一个东西,当时是对R排序之后树状数组暴力统计当前区间的前缀和.每有一个元素出现在R的范围内,就解除他的同样元素的影响,在他 ...
- 第十二届湖南省赛G - Parenthesis (树状数组维护)
Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of length n and q questions. The i-th questio ...
- ACM-ICPC 2018 徐州赛区网络预赛 G. Trace【树状数组维护区间最大值】
任意门:https://nanti.jisuanke.com/t/31459 There's a beach in the first quadrant. And from time to time, ...
- BZOJ 4361 isn | DP 树状数组
链接 BZOJ 4361 题面 给出一个长度为n的序列A(A1,A2...AN).如果序列A不是非降的,你必须从中删去一个数, 这一操作,直到A非降为止.求有多少种不同的操作方案,答案模10^9+7. ...
- Codeforces Gym 101142 G Gangsters in Central City (lca+dfs序+树状数组+set)
题意: 树的根节点为水源,编号为 1 .给定编号为 2, 3, 4, …, n 的点的父节点.已知只有叶子节点都是房子. 有 q 个操作,每个操作可以是下列两者之一: + v ,表示编号为 v 的房子 ...
- codeforces 589G G. Hiring(树状数组+二分)
题目链接: G. Hiring time limit per test 4 seconds memory limit per test 512 megabytes input standard inp ...
- 2020牛客寒假算法基础集训营3 G.牛牛的Link Power II (树状数组维护前缀和)
https://ac.nowcoder.com/acm/contest/3004/G 发现每个“1”对于它本身位置产生的影响贡献为0,对前面的“1”有产生贡献,对后面的"1"也产生 ...
- 洛谷P2880 [USACO07JAN] Balanced Lineup G(树状数组/线段树)
维护区间最值的模板题. 1.树状数组 1 #include<bits/stdc++.h> 2 //树状数组做法 3 using namespace std; 4 const int N=5 ...
- 洛谷 P4375 [USACO18OPEN]Out of Sorts G(树状数组求冒泡排序循环次数加强版)
传送门:Problem 4375 参考资料: [1]:https://www.cnblogs.com/Miracevin/p/9662350.html [2]:https://blog.csdn.ne ...
随机推荐
- ECMAScript 实现继承的几种方式
1. 原形链 function Father() { this.fatherName = "licus"; } function Children() { this.chidr ...
- 「翻译」Unity中的AssetBundle详解(二)
为AssetBundles准备资源 使用AssetBundles时,您可以随意将任何Asset分配给所需的任何Bundle.但是,在设置Bundles时,需要考虑一些策略.这些分组策略可以使用到任何你 ...
- Java中需要了解的点
1.32位jvm.64位区别? 2.
- MYSQL初级学习笔记五:连接查询!(视频序号:初级_37-41)
知识点七:连接查询(37-41) 什么是连接查询: 连接查询是将两个或两个以上的表按某个条件连接起来,从中选取需要的数据.连接查询是同时查询两个或两个以上的表时使用的.当不同的表中存在相同意义的字段时 ...
- Swift语言学习(四)字符串与Array等集合的使用
Swift 提供了C和Objective-C基础类型的自己一套版本,包括用于整型的Int,用于浮点值的Double和Float,用于布尔值的Boolean,和用于文本数据的String.Swift还提 ...
- 倒排列表求交集算法 包括baeza yates的交集算法
#ifndef __INTERSECT_HPP__ #define __INTERSECT_HPP__ #include "probe.hpp" namespace themas ...
- 阮一峰 KMP BM算法
存一个链接,讲得好啊! 点击这里打开 字符串KMP 点击这里打开 字符串匹配的Boyer-Moore算法
- C#参数数组的用法1
C# 参数数组 有时,当声明一个方法时,您不能确定要传递给函数作为参数的参数数目.C# 参数数组解决了这个问题,参数数组通常用于传递未知数量的参数给函数. params 关键字 在使用数组作为形参时, ...
- laya在微信小游戏中加载BitmapFont失效的问题
发布为微信小游戏后,在微信工具中测试时总是提示加载retry to load TheRed.fnt,并以error告终.由于没有任何出错信息,无奈之下只好阅读源码.对BitmapFont的处理分为两个 ...
- NSString -- UILabel中字体有多种颜色,字符串自动计算高度/换行
一:UILabel中字体有多种颜色 UILabel *label = [[UILabel alloc] init]; label.frame = CGRectMake(, , , ); label.b ...