Periodic Signal
来源:互联网 发布:三观尽毁的淘宝买家秀 编辑:程序博客网 时间:2024/05/16 10:56
描述
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.
293 0 1 4 1 5 9 2 65 3 5 8 9 7 9 3 251 2 3 4 52 3 4 5 1
800
#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
- hihocoder 1388 Periodic Signal
- hihocoder1388 Periodic Signal
- hihocoder 1388 Periodic Signal FFT
- hiho 1388 Periodic Signal FFT
- Periodic Signal BeiJing 2016 区域赛
- HihoCoder1388(Periodic Signal)-fft(快速傅里叶变换)
- HihoCoder 1388 Periodic Signal 循环卷积(FFT)
- 2016 ICPC 北京网络赛F题Periodic Signal,hiho1388 : Periodic Signal
- 北京网赛 F题 hiho1388 Periodic Signal
- 【hihoCoder #1388】【2016 acm 北京网络赛 F题】【FFT】 Periodic Signal
- hihoCoder #1388 : Periodic Signal ( 2016 acm 北京网络赛 F题) _循环卷积
- 2016ICPC北京站网络预选赛F hihoCoder1388 Periodic Signal,FFT|NTT+CRT
- 2016 acm 北京网络赛 F题 Periodic Signal 循环卷积
- hihocoder 1388 2016北京网络赛1006 Periodic Signal(卡精度的FFT)
- hihocoder 1388 2016北京网络赛1006 Periodic Signal(卡精度的FFT)
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛 F. Periodic Signal(FFT 优化乘法)
- signal
- FIREFOX浏览器下DIV如何设置滚动条
- PAT 树的遍历 1086. Tree Traversals Again
- clang: error: no such file or directory
- 图像处理、显示中的行宽(linesize)、步长(stride)、间距(pitch)
- Foreground Estimation Based on Linear Regression Model With Fused Sparsity on Outliers
- Periodic Signal
- 第29个python程序:if语句
- ubuntu-make
- 使用adb抓取进程的hprof
- 一个统计当前网段活动IP数量的脚本
- 邮件系统的实现原理和协议解析
- 基于OTP的AES数据加密
- swift使用结构体还是类
- java多级文件复制