Test instructions
Give you a sequence of length n, M inquiry, one number per learning
Let you answer how many pairs of products in a sequence are not less than it.
Ideas:
Preprocessing the number of pairs that are not more than the current value in the current sequence, and then subtracting the number from the previous one is the answer.
/************************************************author:d evil*********************************************** * */#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<cmath>#include<stdlib.h>using namespaceStd;typedefLong LongLL;Const intinf=0x3f3f3f3f;Const intmod=1e9+7;Const intn=3e6;intN,m,ma; LL Cnt[n],sum[n];intMain () {//freopen ("In.txt", "R", stdin);scanf"%d",&N); for(intI=1; i<=n;i++) {scanf ("%d",&m); CNT[M]++; Ma=Max (ma,m); } for(intI=1; i<=ma;i++) for(intj=1; j<=ma;j++) { if(1ll*i*j>n) Break; if(i==j) sum[i*j]+=cnt[i]* (cnt[j]-1); Elsesum[i*j]+=cnt[i]*Cnt[j]; } for(intI=2; i<=n;i++) Sum[i]+=sum[i-1]; scanf ("%d",&m); LL tmp=1ll*n* (n1); while(m--) {scanf ("%d",&MA); printf ("%i64d\n", tmp-sum[ma-1]); } return 0;}
Codeforces 691F Couple Cover (brute force pretreatment)