描述

Profess X is an expert in signal processing. He has a device which can send a particular 1 second signal repeatedly. The signal is A0 ... An-1 under n Hz sampling.

One day, the device fell on the ground accidentally. Profess X wanted to check whether the device can still work properly. So he ran another n Hz sampling to the fallen device and got B0 ... Bn-1.

To compare two periodic signals, Profess X define the DIFFERENCE of signal A and B as follow:

You may assume that two signals are the same if their DIFFERENCE is small enough. 
Profess X is too busy to calculate this value. So the calculation is on you.

输入

The first line contains a single integer T, indicating the number of test cases.

In each test case, the first line contains an integer n. The second line contains n integers, A0 ... An-1. The third line contains n integers, B0 ... Bn-1.

T≤40 including several small test cases and no more than 4 large test cases.

For small test cases, 0<n≤6⋅103.

For large test cases, 0<n≤6⋅104.

For all test cases, 0≤Ai,Bi<220.

输出

For each test case, print the answer in a single line.

样例输入

2
9
3 0 1 4 1 5 9 2 6
5 3 5 8 9 7 9 3 2
5
1 2 3 4 5
2 3 4 5 1

样例输出

80
0

#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <ctime>
#include <cstring>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
#include <map>
#include <set>
#define LL long long
#define Pr pair<int,int>
#define fread(ch) freopen(ch,"r",stdin)
#define fwrite(ch) freopen(ch,"w",stdout)
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const double eps = 1e-3;
const int maxn = 61234;
struct Line
{
LL l,r,val;
bool operator <(const struct Line a)const
{
return l < a.l;
}
} ln[maxn];
LL bit[maxn];
LL st,en,t;
int n,m,tp;
LL to[maxn];
map <LL,int> mp;
int id,iid;
int Lowbit(int x)
{
return x&(-x);
}
void Add(int x,LL ad)
{
x++;
while(x <= id+1)
{
bit[x] += ad;
x += Lowbit(x);
}
}
LL Sum(int x)
{
LL ans = 0;
x++;
while(x)
{
ans += bit[x];
x -= Lowbit(x);
}
return ans;
}
int Search(LL x)
{
int l,r;
l = 0,r = id;
int ans = -1;
while(l <= r)
{
int mid = (l+r)>>1;
if(to[mid] <= x)
{
ans = mid;
l = mid+1;
}
else r = mid-1;
}
return ans;
}
LL solve()
{
LL mx = 0;
memset(bit,0,sizeof(bit));
sort(ln,ln+tp);
int l,r;
l = 0,r = 0;
for(int i = 0; i <= id; ++i)
{
int rr = Search(to[i]+t);
while(r < tp && mp[ln[r].l] <= rr)
{
Add(mp[ln[r].r],ln[r].val);
++r;
}
while(l < tp && mp[ln[l].l] < i)
{
Add(mp[ln[l].r],-ln[l].val);
++l;
}
mx = max(mx,Sum(rr));
//        printf("%d,%d %lld\n",i,rr,mx);
//        printf("%d %d\n",l,r-1);
}
return mx;
}
int main()
{
LL t2,x,y,val,sum;
while(~scanf("%lld%lld",&t,&t2))
{
mp.clear();
iid = 0;
scanf("%lld",&st);
en = st+t2;
scanf("%d%d",&n,&m);
tp = 0;
sum = 0;
for(int i = 0; i < n; ++i)
{
scanf("%lld%lld%lld",&x,&y,&val);
x += y;
if(st <= x && x <= en)
{
ln[tp].l = x+y;
ln[tp].r = (en-x)/(2*y)*(2*y)+ln[tp].l;
ln[tp++].val = val;
sum += val;
to[iid++] = ln[tp-1].l;
to[iid++] = ln[tp-1].r;
//                printf("%lld %lld\n",ln[tp-1].l,ln[tp-1].r);
}
}
for(int i = 0; i < m; ++i)
{
scanf("%lld%lld%lld",&x,&y,&val);
ln[tp].l = x+y;
if(st <= x+2*y && x+2*y <= en)
{
ln[tp].r = (en-x)/(2*y)*(2*y)+ln[tp].l;
}
else ln[tp].r = x+y;
ln[tp++].val = val;
sum += val;
to[iid++] = ln[tp-1].l;
to[iid++] = ln[tp-1].r;
}
sort(to,to+iid);
id = -1;
for(int i = 0; i < iid; ++i)
{
if(!i || to[i] != to[i-1])
{
++id;
to[id] = to[i];
mp[to[i]] = id;
}
}
printf("%lld\n",sum-solve());
}
return 0;
}

Periodic Signal相关推荐

  1. hihocoder #1388 : Periodic Signal NTTFFT

    传送门:hihocoder #1388 : Periodic Signal 先来几个大牛传送门:  (模板) NTT long long 版 解法一:因为我们知道FFT会精度不够,所以坚持用NTT,但 ...

  2. 【 MATLAB 】离散傅里叶级数(DFS)及 IDFS 的 MATLAB 实现

    有关离散傅里叶级数(DFS)我之前也写过一些博文,例如:离散周期信号的傅里叶级数(DFS) 这里我再次给出标准公式. 分析式: 其中: 综合式: 这里我必须先声明,关于分析式和综合式前面那个系数1/N ...

  3. 卷积滤波 英文_《信号与系统》专业术语中英文对照表

    <信号与系统>专业术语中英文对照表 第 1 章 绪论 信号 ( signal ) 系统 ( system ) 电压 ( voltage ) 电流 ( current ) 信息 ( info ...

  4. 2016 ICPC 北京网络赛 A 恶心模拟 F 循环矩阵,FFT(待补) I 模拟

    2016 ICPC 北京网络赛 A - The Book List 题意:每本书有所属种类,给出原生的存放方式,求按新的方式存放的样子. tags:坑到心态爆炸的题==  直接堆进vector里搞的, ...

  5. 基于matlab的信号合成与分解,基于matlab的信号合成与分解

    基于matlab的信号合成与分解 - I - 摘 要 为了便于进行周期信号的分析与处理,常要把复杂的周期信号进行分解,即将周期 信号分解为正余弦等此类基本信号的线性组合,通过对这些基本信号单元在时域和 ...

  6. 先知模型 facebook_使用Facebook先知进行犯罪率预测

    先知模型 facebook Time series prediction is one of the must-know techniques for any data scientist. Ques ...

  7. Github | 如何用神经网络识别系外行星?

    点上方蓝字计算机视觉联盟获取更多干货 在右上方 ··· 设为星标 ★,与你不见不散 编辑:Sophia 计算机视觉联盟  报道  | 公众号 CVLianMeng 转载于 :Github https: ...

  8. [Hector学习笔记]GNSS时间序列处理软件Hector使用备忘(批处理脚本)

    由Machiel Bos 和Rui Fernandes共同研发的Hector软件可以利用时间相关噪声来估计时间序列线性趋势,是与优秀的GNSS时间序列处理软件之一. 软件安装教程:Hector软件安装 ...

  9. 机械设备故障诊断健康监测公开数据集

    美国-凯斯西储大学轴承数据中心CWRU) 美国-机械故障预防技术学会MFPT 数据链接:(Fault Data Sets - Society For Machinery Failure Prevent ...

最新文章

  1. WebSocket 是什么原理?为什么可以实现持久连接?什么情况使用WebSocket
  2. 关于c语言的基本知识,第二章_关于C语言的基本知识.ppt
  3. 随想录(科技企业中股票和融资)
  4. putty-不输入密码直接登陆
  5. layer mvc json 中文乱码处理
  6. Direct2D教程(七)单色画刷
  7. My SQL中show命令--MySQL中帮助查看
  8. 软件测试常用方法实例与分析
  9. 网络协议分析-TCP协议分析
  10. WIN10系统微软拼音输入法无法输入中文
  11. 童甫带领下的海航科技集团的无人运输船正式亮相引关注
  12. Java如何解析个人或他人微信二维码内的信息
  13. 数据库原理及应用(六)SQL Server关系数据库系统
  14. Linux命令06 - - wget 下载网络文件
  15. 《以幽默的方式过一生》-琢磨先生读书笔记
  16. QT报make: Circular all <- first dependency dropped.错误解决。
  17. 降维算法PCA的应用----高维数据的可视化
  18. 10.8上海交大PMP每日一题
  19. java毕业生设计学习资源下载管理计算机源码+系统+mysql+调试部署+lw
  20. 交际过程的两个基本环节_小学语文“三学小组”模式口语交际课型教学流程及基本要求...

热门文章

  1. 软件工程作业 - word count
  2. c语言putchar_C语言实现变色的心!连机器都会变心,呵,男人!
  3. mysql替换json的key_mysql中json_replace函数的使用?通过json_replace对json对象的值进行替换...
  4. 如何做电脑桌面应用_CAD批量转PDF?一分钟教会你CAD如何转PDF,两种方法任你选择!...
  5. 为什么编程语言要从c语言学起,在那么多编程语言中,为什么推荐初学者学 C 语言?...
  6. 简单的php,php简单语句
  7. jquery li ul 伪分页_求教关于Jquery的ul li的分页,该怎么处理
  8. rpc 服务器不可用_RPC和微服务
  9. td之间的间距怎么改_论文的一级标题、二级标题格式怎么弄?
  10. 手机端使用ghelper_Anki手机端使用指南(一)