双面间谍(spy)
双面间谍
分析:
代码:
#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)的更多相关文章
- 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 ...
- Manthan, Codefest 16 -C. Spy Syndrome 2
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 用PowerMock spy mock private方法
在实际的工作中,经常碰到只需要mock一个类的一部分方法,这时候可以用spy来实现. 被测类: public class EmployeeService { public boolean exist( ...
- Jasmine测试ng Promises - Provide and Spy
jasmine提供了很多些很实用的处理Promises的方法,首先我们来考虑下面的这个例子: angular.module("myApp.store").controller(&q ...
- UVa 1025 A Spy in the Metro(动态规划)
传送门 Description Secret agent Maria was sent to Algorithms City to carry out an especially dangerous ...
- 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 ...
- ZOJ 3860: - Find the Spy
3860 - Find the Spy Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu S ...
- 如何使用SPY++查找
自动化测试中,如果需要做UI automation的时候往往需要抓取object的工具.实际上这种工具有很多,认识的大牛使用SPY++,于是我也选择了这个.下面列出基本使用方法.有点像XACC spy ...
- SPY++的使用
百度百科Spy++ 使用的是VS2010.net自带的功能,可以从开始菜单中打开.
随机推荐
- 最近见到一个用react native实现的标尺动画,不知道如何实现 帖两张图(新知食App)
很恶心,这款App的标尺没有做兼容,我在模拟上看不到效果,无法说明我想做出的东西的效果,无奈粘一张图吧! 就是这么一个屌样子,如何实现?
- (Stanford CS224d) Deep Learning and NLP课程笔记(二):word2vec
本节课将开始学习Deep NLP的基础--词向量模型. 背景 word vector是一种在计算机中表达word meaning的方式.在Webster词典中,关于meaning有三种定义: the ...
- 【Python】zlib压缩文件
import zlib import os ss = 's' * 1024 * 1024 #写入原始文件 file = open("src.dat", "wb" ...
- SQL2005的SSMS连接SQL2012会有问题
SQL2005的SSMS连接SQL2012会有问题 如果用SQL2005的SSMS连接SQL2012会产生“索引数组越界”的问题并且使用不了 反过来使用SQL2012的SSMS连接SQL2005就没有 ...
- 使用 Azure 门户创建 Windows 虚拟机
可以通过 Azure 门户创建 Azure 虚拟机. 此方法提供一个基于浏览器的用户界面,用于创建和配置虚拟机和所有相关的资源. 本快速入门介绍了如何创建虚拟机并在 VM 上安装 webserver. ...
- struts2框架
详细教程 参考struts教程https://www.w3cschool.cn/struts_2/struts_configuration.html Struts2 基于MVC设计模式的web应用程序 ...
- PHP支付宝支付开发流程
支付宝开发流程 1.首先我们先谈谈第三方支付 所谓第三方支付就是和一些各大银行签约,并具备一定实力和信誉保障的第三方独立机构提供的交易平台 目前市面上常见的有支付宝,财付通,网银,易宝支付等,网站 ...
- BZOJ 1087 互不侵犯King 状态压缩DP
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1087 题目大意; 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国 ...
- Android Studio运行找不到Genymotion虚拟机
如图: 在Genymotion->Settings下ADB选项卡下选择使用SDK工具: 完成后试试吧
- 【转】Android 获取本机号码(收集)
SIM卡存储的数据可分为四类: 第一类是固定存放的数据.这类数据在移动电话机被出售之前由SIM卡中心写入,包括国际移动用户识别号(IMSI).鉴权密钥(KI).鉴权和加密算法等等. 第二类是暂时存放的 ...