双面间谍(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自带的功能,可以从开始菜单中打开.
随机推荐
- 数据分析——Matplotlib图形绘制
创建画布或子图 函数名称 函数作用 plt.figure 创建一个空白画布,可以指定画布大小,像素. figure.add_subplot 创建并选中子图,可以指定子图的行数,列数,与选中图片编号. ...
- 类Unix上5个最佳开源备份工具 Bacula/Amanda/Backupninja/Backuppc/UrBackup
当为一个企业选择备份工具的时候,你都考虑什么呢? 确定你正在部署的软件具有下面的特性 开源软件 – 你务必要选择那些源码可以免费获得,并且可以修改的软件.确信可以恢复你的数据,即使是软件供应商/项目停 ...
- systemd 之 journalctl
Systemd 日志系统 一.前言 昨天写了一篇文章,内容为:Systemd 常规操作与彩蛋,参考了 ArchLinux 官方文档并结合培训中的思路进行了部分修改补充.如果你懂得了基础的管理,那必然还 ...
- innodb_locks_unsafe_for_binlog分析
mysql数据库中默认的隔离级别为repeat-read. innodb默认使用了next-gap算法,这种算法结合了index-row锁和gap锁.正因为这样的锁算法,innodb在可重复读这样的默 ...
- EF使用笔记
最近写接口导数据到大数据中心,但是实体数据字段非常多,如果手动去建数据库表和写插入语句效率非常低,所以想都试一试EF,效率之高,简直吓人,所以此文详细记录操作过程以备下次使用时之用.仅需六部就可完成建 ...
- python基础学习2
一.算数运算符 +加法,-减法,*乘法,/除法,//地板除,%求余,**幂运算. 二.逻辑运算符 非not.且and.或or.优先级依次为not,and,or. 三.print()end结尾 prin ...
- Centos7(Firewall)防火墙开启常见端口命令
Centos7默认安装了firewalld,如果没有安装的话,则需要YUM命令安装:firewalld真的用不习惯,与之前的iptable防火墙区别太大,但毕竟是未来主流讲究慢慢磨合它的设置规则: 安 ...
- Alpha冲刺报告(10/12)(麻瓜制造者)
今日已完成 邓弘立: 实现了登录的所有功能 符天愉: 有点事没有参与冲刺- 江郑: 刘双玉: 写商品下架接口说明的时候,就发现一个bug,因为私人原因中间离开了很长时间,最后修改完成就很晚了. 困难: ...
- toFixed四舍五入精度校正
var a = 2.255; var b = a.toFixed(2); console.log(b); 以上代码,按预期正常四舍五入得到结果应该是2.26,但实际返回值为2.25 js浮点数精度作为 ...
- 难度并不NOIP的NOIP模拟赛
今天老师请了前几届的学长来讲课,可是讲课为什么要考试呢... 学长说难度是NOIP,于是我就naive的跟着参加了,然而T3难度并不友好,感觉确实不是很适合我们现在做......不过课本来也不是给我们 ...