双面间谍

链接

分析:

  戳这

代码:

#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. Oracle 单实例 Relink Binary Options 说明

    一.引入问题 帮朋友在CentOS上安装一个10g的Oracle,结果朋友的CentOS版本是6.2的版本,最新的一个版本,不过Linux上基本都差不多,所以按照以前的步骤,迅速的操作起来,结果遇到N ...

  2. Java 的布局管理器GridBagLayout的使用方法【图文说明】

    https://www.cnblogs.com/taoweiji/archive/2012/12/14/2818787.html GridBagLayout是java里面最重要的布局管理器之一,可以做 ...

  3. Windows7 添加快速启动栏

    解决方案: 1.右击任务栏空白处,选择“工具栏”,单击“新建工具栏”: 2.输入“%userprofile%\AppData\Roaming\Microsoft\Internet Explorer\Q ...

  4. OpenGL_Qt学习笔记之_03(平面图形的着色和旋转)(转)

    http://www.cnblogs.com/tornadomeet/archive/2012/08/23/2653305.html 在这一节中主要简单介绍下怎样给平面几何着色,以及怎样让绘制出来的几 ...

  5. MongoDB中_class字段的作用

    我们知道,如果你用Java的Sping Data 框架映射Pojo为MongoDB数据时,数据库中会自动给你添加一个_class字段,那这个字段是干嘛用的呢?我们可以不可以不要这个字段呢? 直接上结论 ...

  6. PyQt5--QCheckBox

    1 # -*- coding:utf-8 -*- ''' Created on Sep 20, 2018 @author: SaShuangYiBing Comment: ''' import sys ...

  7. sublime设置node.js编译

    1. 首先需安装node环境并配置好环境变量,安装教程. 2. 然后在sublime中打开工具(Tools)→编译系统(Build System)→新编译系统(New Build System) 3. ...

  8. node学习笔记_02 API详解

    一.知识点:url.parse方法 方法说明: 讲一个URL字符串转换成对象并返回. 语法:url.parse(urlStr, [parseQueryString], [slashesDenoteHo ...

  9. TML 打印预览问题,怎么设置有些内容不出现在打印预览页面上。怎么控制,有下代码 看得不是很懂 求解释

    HTML <style> 标签的 media 属性 HTML <style> 标签 实例 针对两种不同媒介类型的两种不同的样式(计算机屏幕和打印): <html> ...

  10. [转]C#操作INI文件

    在很多的程序中,我们都会看到有以.ini为后缀名的文件,这个文件可以很方便的对程序配置的一些信息进行设置和读取,比如说我们在做一个程序后台登陆的时候,需要自动登录或者是远程配置数据库连接,及保存密码设 ...