双面间谍

链接

分析:

  戳这

代码:

#include<cstdio>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<bitset>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ;
int a[N], b[N], x[N], y[N], dx[N], dy[N]; struct SegmentTree{
int Root[N], ls[N * ], rs[N * ], cnt[N * ], Index, n, Now, disc[N];
LL sum[N * ], Ans;
SegmentTree() { n = ; }
void Insert(int l,int r,int &now,int pre,int p) {
if (!now) now = ++Index;
sum[now] = sum[pre] + disc[p]; cnt[now] = cnt[pre] + ;
if (l == r) return ;
int mid = (l + r) >> ;
if (p <= mid) rs[now] = rs[pre], Insert(l, mid, ls[now], ls[pre], p);
else ls[now] = ls[pre], Insert(mid + , r, rs[now], rs[pre], p);
}
void query(int l,int r,int now,int pre,int k) {
if (l == r) { Now = disc[l]; return ; }
int mid = (l + r) >> , x = cnt[ls[now]] - cnt[ls[pre]];
if (k <= x) {
query(l, mid, ls[now], ls[pre], k);
Ans += (sum[rs[now]] - sum[rs[pre]]) - 1ll * Now * (cnt[rs[now]] - cnt[rs[pre]]);
}
else {
query(mid + , r, rs[now], rs[pre], k - x);
Ans += 1ll * Now * x - (sum[ls[now]] - sum[ls[pre]]);
}
}
}T1, T2; void solve() {
int l = read(), r = read(); LL ans = ;
T1.Ans = , T1.Now = ;
T1.query(, T1.n, T1.Root[r], T1.Root[l - ], (r - l + + ) / );
ans += T1.Ans; T2.Ans = , T2.Now = ;
T2.query(, T2.n, T2.Root[r], T2.Root[l - ], (r - l + + ) / );
ans += T2.Ans; printf("%.2lf\n", ans / 2.0);
} signed main() {
int n = read(), m = read(), cx = , cy = ;
for (int i = ; i <= n; ++i) a[i] = read();
for (int i = ; i <= n; ++i) {
b[i] = read();
x[i] = a[i] + b[i], y[i] = a[i] - b[i];
T1.disc[i] = x[i], T2.disc[i] = y[i];
}
sort(T1.disc + , T1.disc + n + );
sort(T2.disc + , T2.disc + n + );
for (int i = ; i <= n; ++i) {
if (T1.disc[i] != T1.disc[cx]) T1.disc[++cx] = T1.disc[i];
if (T2.disc[i] != T2.disc[cy]) T2.disc[++cy] = T2.disc[i];
}
for (int i = ; i <= n; ++i) {
x[i] = lower_bound(T1.disc + , T1.disc + cx + , x[i]) - T1.disc;
y[i] = lower_bound(T2.disc + , T2.disc + cy + , y[i]) - T2.disc;
}
for (int i = ; i <= n; ++i) T1.n = max(T1.n, x[i]), T2.n = max(T2.n, y[i]);
for (int i = ; i <= n; ++i) {
T1.Insert(, T1.n, T1.Root[i], T1.Root[i - ], x[i]);
T2.Insert(, T2.n, T2.Root[i], T2.Root[i - ], y[i]);
}
while (m --) solve();
return ;
}

双面间谍(spy)的更多相关文章

  1. UVA - 1025 A Spy in the Metro[DP DAG]

    UVA - 1025 A Spy in the Metro Secret agent Maria was sent to Algorithms City to carry out an especia ...

  2. Manthan, Codefest 16 -C. Spy Syndrome 2

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  3. 用PowerMock spy mock private方法

    在实际的工作中,经常碰到只需要mock一个类的一部分方法,这时候可以用spy来实现. 被测类: public class EmployeeService { public boolean exist( ...

  4. Jasmine测试ng Promises - Provide and Spy

    jasmine提供了很多些很实用的处理Promises的方法,首先我们来考虑下面的这个例子: angular.module("myApp.store").controller(&q ...

  5. UVa 1025 A Spy in the Metro(动态规划)

    传送门 Description Secret agent Maria was sent to Algorithms City to carry out an especially dangerous ...

  6. UVA1025---A Spy in the Metro(DP)

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35913 Secret agent Maria was sent to Alg ...

  7. ZOJ 3860: - Find the Spy

    3860 - Find the Spy Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu S ...

  8. 如何使用SPY++查找

    自动化测试中,如果需要做UI automation的时候往往需要抓取object的工具.实际上这种工具有很多,认识的大牛使用SPY++,于是我也选择了这个.下面列出基本使用方法.有点像XACC spy ...

  9. SPY++的使用

    百度百科Spy++ 使用的是VS2010.net自带的功能,可以从开始菜单中打开.

随机推荐

  1. 白盒测试实践-day....

    时间:2017.12.22 地点:软件学院 参与人员:张双双.张玉.周静.赵天宇 会议内容:对代码测试的内容进行总结,总结任务由赵天宇完成,其余同学提出自己的看法和意见. 总结内容分为了五个阶段,不同 ...

  2. Linux Ubuntu16.04LTS安装TensorFlow(CPU-only,python3.7)——使用Anaconda安装

    1.安装Anaconda(在此不再赘述) 2.用Conda安装TensorFlow 1)建立TensorFlow运行环境并激活 conda create -n tensorflow pip pytho ...

  3. Dictionary CovertTo List

    示例代码 假设有如下一个Dictionary 要转换成List Dictionary<string, string> dicNumber = new Dictionary<strin ...

  4. Vue以CDN方式调用Swiper轮播异常

    问题概览: 有一个小型单页应用项目,嫌用组件式调用vue-swiper麻烦,因此以CDN的方式调用swiper,结果轮播的图不动了! 爬了半天百度和谷歌都无解决方案,最后曲线救国的方式解决了问题. 解 ...

  5. a.c:5:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wun

    PTA做题时出现的错误,用if括起来就没有了. if(scanf("%d",&a)){}; 其实并不是这里有问题,如果你的输出有问题,他就会鸡蛋里挑骨头的先显示这个错误.

  6. 阿里八八Alpha阶段Scrum(4/12)

    今日进度 叶文滔: 整合了一下已完成的界面设计,修复了一些BUG. 问题困难:制作多级悬浮按钮阻碍重重,首先是刚更新不久的Andriod Studio 3.0向前兼容性差,一些语句规则的修改无所适从, ...

  7. React-Native 真机调试踩坑指南

    继上一篇基础安装踩坑继续我们的踩坑之旅,备注一下以下仅针对Mac环境-- 安卓 1.adb 找不到命令? Adb的全称为Android Debug Bridge,就是起到调试桥的作用,真机调试安卓必备 ...

  8. 开发指南专题十四:JEECG微云高速开发平台MiniDao 介绍

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/zhangdaiscott/article/details/27068645   开发指南专题十四:J ...

  9. Nowcoder 提高组练习赛-R2

    https://www.nowcoder.com/acm/contest/173#question T1:https://www.nowcoder.com/acm/contest/173/A 题意概述 ...

  10. sql优化常见的集中方法

    在sql查询中为了提高查询效率,我们常常会采取一些措施对查询语句进行sql优化,下面总结的一些方法,有需要的可以参考参考. 1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 ord ...