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 观察 + 树状数组的更多相关文章

  1. SCUT - G - 魔法项链 - 树状数组

    https://scut.online/contest/30/G 很久以前做的一个东西,当时是对R排序之后树状数组暴力统计当前区间的前缀和.每有一个元素出现在R的范围内,就解除他的同样元素的影响,在他 ...

  2. 第十二届湖南省赛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 ...

  3. ACM-ICPC 2018 徐州赛区网络预赛 G. Trace【树状数组维护区间最大值】

    任意门:https://nanti.jisuanke.com/t/31459 There's a beach in the first quadrant. And from time to time, ...

  4. BZOJ 4361 isn | DP 树状数组

    链接 BZOJ 4361 题面 给出一个长度为n的序列A(A1,A2...AN).如果序列A不是非降的,你必须从中删去一个数, 这一操作,直到A非降为止.求有多少种不同的操作方案,答案模10^9+7. ...

  5. Codeforces Gym 101142 G Gangsters in Central City (lca+dfs序+树状数组+set)

    题意: 树的根节点为水源,编号为 1 .给定编号为 2, 3, 4, …, n 的点的父节点.已知只有叶子节点都是房子. 有 q 个操作,每个操作可以是下列两者之一: + v ,表示编号为 v 的房子 ...

  6. codeforces 589G G. Hiring(树状数组+二分)

    题目链接: G. Hiring time limit per test 4 seconds memory limit per test 512 megabytes input standard inp ...

  7. 2020牛客寒假算法基础集训营3 G.牛牛的Link Power II (树状数组维护前缀和)

    https://ac.nowcoder.com/acm/contest/3004/G 发现每个“1”对于它本身位置产生的影响贡献为0,对前面的“1”有产生贡献,对后面的"1"也产生 ...

  8. 洛谷P2880 [USACO07JAN] Balanced Lineup G(树状数组/线段树)

    维护区间最值的模板题. 1.树状数组 1 #include<bits/stdc++.h> 2 //树状数组做法 3 using namespace std; 4 const int N=5 ...

  9. 洛谷 P4375 [USACO18OPEN]Out of Sorts G(树状数组求冒泡排序循环次数加强版)

    传送门:Problem 4375 参考资料: [1]:https://www.cnblogs.com/Miracevin/p/9662350.html [2]:https://blog.csdn.ne ...

随机推荐

  1. add time to file name

    add time to file name echo 123 > $(date +"%Y%m%d_%H%M%S").now; mv /mnt/mongodb_data/dat ...

  2. Sublime Text web开发神器

    开发工具介绍 开发工具一般分为两种类型:文本编辑器和集成开发环境(IDE) 常用的文本编辑器:Sublime Text.Notepad++.EditPlus等 常用的IDE:WebStorm.Inte ...

  3. 推断php操作mysql(添删改查)是否成功

    近期在使用CI框架 , 可是里面的数据库操作没有ThinkPhp方便 , 不知道数据库操作的反馈信息 , 仅仅好借助原生方法来推断是否操作数据库成功 推断php操作mysql(添删改查)是否成功,主要 ...

  4. HDU 5666 Segment

    Segment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  5. vue弹窗插件实战

    vue做移动端经常碰到弹窗的需求, 这里写一个功能简单的vue弹窗 popup.vue <template> <div class="popup-wrapper" ...

  6. YTU 1055: 输入字符串以及输出

    1055: 输入字符串以及输出 时间限制: 1 Sec  内存限制: 128 MB 提交: 694  解决: 476 题目描述 编写一函数,由实参传来一个字符串,统计此字符串中字母.数字.空格和其它字 ...

  7. js实现域名判断后跳转到指定网址

    js实现域名判断后跳转到指定网址,也适用于同一虚拟空间放多个网站: <script>       try           {               if(self.locatio ...

  8. easyUI-右键菜单,关闭选项卡

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  9. JAVASCRIPT技术 表达式验证

    失去焦点时,调用方法: <html> <head><script type="text/javascript">function upperCa ...

  10. 最浅谈的SG函数

    [更新] Nim游戏的经验: 每次最多取m个——%(m+1) 阶梯nim——奇数位无视,看偶数位互相独立,成一堆一堆的石子 . . . . 既然被征召去汇总算法..那么挑个简单点的SG函数好了.. 介 ...