Implication: Can we find out from the given three sequences that satisfy the given value of ai+bj+ck==given x, then output YES, otherwise output NO?

Thought: Storm search will definitely overtime, because the length of the interval is static, consider the order after dichotomy (dichotomy premise must be orderly). There are two choices for dichotomy, one of which will be timeout: 1. If dichotomy is used to find the existence of x-a[i]-b[j] i n c, then the time complexity is n * m * log (p) (assuming the length of a,b,c array is n,m,p), it will be timeout;

2. There is a better way to pre-process the sum of all combinations of a,b, and the array (put i n the ab array) and find the existence of x-c[i] in AB with a time complexity of P * log (n * m).

#include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; //Simple storm search time complexity is n^3 will TIE; //When the interval is static (i.e. without adding or deleting operations), binary search is considered. //Here the dichotomy can subtract the total value from the first two values to the third value from the dichotomy, but the time complexity is n*m*logp and the queries are k times. //This will still be TLE (why do I know, because I do TLE...) //Therefore, dichotomy should preprocess the first two items, subtract the third item from the total value, and take dichotomy from the preprocessed array. //In this way, the complexity becomes p*log(n*m), and the type should be long. ll a[666],b[666],c[666],ab[666*666];//ab arrays are used to preprocess the sum of a and B arrays (the arrays should be large enough); int main() { int i,j; int n,m,p; int t,k=0; ll x; while(scanf("%d%d%d",&n,&m,&p)!=EOF) { for(i=1;i<=n;i++) { scanf("%lld",&a[i]); } for(i=1;i<=m;i++) { scanf("%lld",&b[i]); } for(i=1;i<=p;i++) { scanf("%lld",&c[i]); } int tot=0; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { ab[++tot]=a[i]+b[j];//The sum of a and B arrays is preprocessed. } } sort(ab+1,ab+1+tot);//The condition of dichotomy is ordered sequence, so it must be sorted first. sort(c+1,c+1+p); scanf("%d",&t);//t times; printf("Case %d:\n",++k); while(t--) { scanf("%lld",&x); if((x<ab[1]+c[1])||(x>ab[tot]+c[p]))//If x is smaller than the smallest or bigger than the largest, no search is needed. { printf("NO\n"); continue; } bool flag=true;//When flag==false, the number satisfying the condition is found. for(i=1;i<=p&&flag;i++) { ll ans=x-c[i]; int l=1; int r=tot;//The pre-processed ab array is divided into two parts. while(l<=r) { int mid=(l+r)>>1; if(ab[mid]==ans) { flag=false;//Find the solution that meets the requirement. break; } else if(ab[mid]<ans) { l=mid+1; } else { r=mid-1; } } } if(!flag) { printf("YES\n"); } else { printf("NO\n"); } } } return 0; }