Countries

描述

There are two antagonistic countries, country A and country B. They are in a war, and keep launching missiles towards each other.

It is known that country A will launch N missiles. The i-th missile will be launched at time Tai. It flies uniformly and take time Taci from one country to the other. Its damage capability is Dai.

It is known that country B will launch M missiles. The i-th missile will be launched at time Tbi.

It flies uniformly and takes time Tbci from one country to the other. Its damage capability is Dbi.

Both of the countries can activate their own defending system.

The defending system of country A can last for time TA, while The defending system of country B can last for time TB.

When the defending system is activated, all missiles reaching the country will turn around and fly back at the same speed as they come.

At other time, the missiles reaching the country will do damages to the country.
(Note that the defending system is still considered active at the exact moment it fails)

Country B will activate its defending system at time X.

When is the best time for country A to activate its defending system? Please calculate the minimal damage country A will suffer.

输入

There are no more than 50 test cases.

For each test case:

The first line contains two integers TA and TB, indicating the lasting time of the defending system of two countries.

The second line contains one integer X, indicating the time that country B will active its defending system.

The third line contains two integers N and M, indicating the number of missiles country A and country B will launch.

Then N lines follow. Each line contains three integers Tai, Taci and Dai, indicating the launching time, flying time and damage capability of the i-th missiles country A launches.

Then M lines follow. Each line contains three integers Tbi, Tbci and Dbi, indicating the launching time, flying time and damage capability of the i-th missiles country B launches.

0 <= TA, TB, X, Tai, Tbi<= 100000000

1 <= Taci, Tbci <= 100000000

0 <= N, M <= 10000

1 <= Dai, Dbi <= 10000

输出

For each test case, output the minimal damage country A will suffer.

提示

In the first case, country A should active its defending system at time 3.

Time 1: the missile is launched by country A.

Time 2: the missile reaches country B, and country B actives its defending system, then the missile turns around.

Time 3: the missile reaches country A, and country A actives its defending system, then the missile turn around.

Time 4: the missile reaches country B and turns around.

Time 5: the missile reaches country A and turns around.

Time 6: the missile reaches country B, causes damages to country B.


样例输入
2 2
2
1 0
1 1 10
4 5
3
2 2
1 2 10
1 5 7
1 3 2
0 4 8
样例输出
0

17

#include <cmath> #include <ctime> #include <cctype> #include <cstdio> #include <cstring> #include <cstdlib> #include <cassert> #include <set> #include <map> #include <stack> #include <queue> #include <vector> #include <bitset> #include <complex> #include <iostream> #include <algorithm> #define rep(i,s,t) for(register LL i=s,_t=t;i<_t;++i) #define per(i,s,t) for(register LL i=t-1,_s=s;i>=_s;--i) using namespace std; #define LL long long const LL mod=(LL)1e9+7,inf=0x7fffffff; const LL INF=1ll<<60; const LL P=31525197391593473,r=3; void mod_add(LL &a,LL b){     if((a+=b)>=P)a-=P; } void mod_minus(LL &a,LL b){     if((a-=b)<0)a+=P; } LL mul(LL x,LL y,LL z){ return (x*y - (LL)(x/(long double)z*y+1e-3)*z+z)%z; } LL fast_mod_pow(LL a,LL b){     LL res=1;     for(;b;b>>=1,a=mul(a,a,P))         if(b&1)res=mul(res,a,P);     return res; } inline LL calc_inv(LL x){     return fast_mod_pow(x,P-2); } const LL N=(1<<18)+5; LL rev[N],A[N],B[N],C[N]; void DFT(LL *arr,LL n,bool flag){     rep(i,0,n)if(i<rev[i])swap(arr[i],arr[rev[i]]);     for(LL m=2;m<=n;m<<=1){         LL g=fast_mod_pow(r,(P-1)/m);         if(flag)g=calc_inv(g);         for(LL i=0;i<n;i+=m){             LL cur=1;             rep(j,0,m>>1){                 LL x=arr[i+j],y=mul(cur,arr[i+j+(m>>1)],P);                 mod_add(arr[i+j]=x,y);                 mod_minus(arr[i+j+(m>>1)]=x,y);                 cur=mul(cur,g,P);             }         }     } } void NTT(LL n,LL m){     LL _n,S;     for(_n=1,S=0;_n<n+m;_n<<=1,++S);     rep(i,1,_n)rev[i]=(rev[i>>1]>>1)|((i&1)<<S-1);     rep(i,n,_n)A[i]=0;     rep(i,m,_n)B[i]=0;     DFT(A,_n,false);     DFT(B,_n,false);     rep(i,0,_n)C[i]=mul(A[i],B[i],P);     DFT(C,_n,true);     LL inv=calc_inv(_n);     rep(i,0,_n)C[i]=mul(C[i],inv,P); } int main() {     LL T;     scanf("%lld",&T); LL n; while(T-- && ~scanf("%lld",&n)){ long long ans = 0; for(LL i = 0;i < n;i++){             scanf("%lld",&A[i]);             ans += 1ll * A[i] * A[i]; } for(LL i = 0;i < n;i++){             scanf("%lld",&B[i]);             ans += 1ll * B[i] * B[i]; } for(LL i = 0;i < n;i++) A[i+n] = A[i];         reverse(B,B+n); NTT(n*2,n); ans -= *max_element(C+n,C+n*2 + 1) * 2; printf("%lld\n",ans); }     return 0; }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值