Periodic Signal
描述
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.
樣例輸入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的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 最简逆波兰模板
- 下一篇: 链表c++代码的实现
