At first thought died of precision ... Half a day to find died in long long ...
One or two-point method:
#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;bool cmp (const int &A , const int &b) {return a>b;} int N,a[100001],b[100001];long long Ans;int main () { scanf ("%d", &n); for (int i=1;i<=n;++i) scanf ("%d", &a[i]); Sort (a+1,a+n+1,cmp); memcpy (B,a, (n+1) *sizeof (int)); for (int i=1;i<=n;++i) b[i]*=10; for (int i=1;i<=n;++i) ans+= (Long Long) (Upper_bound (b+i+1,b+n+1,a[i]*9,cmp)-b-i-1); printf ("%lld\n", ans); return 0;}
Second, the ruler of the extraction:
#include <cstdio> #include <algorithm>using namespace Std;bool cmp (const int &A,CONST int &b) {return A>b;} int N,a[100001];long long Ans;int main () { scanf ("%d", &n); for (int i=1;i<=n;++i) scanf ("%d", &a[i]); Sort (a+1,a+n+1,cmp); int head=1,tail=1; while (1) { while (a[tail]*10>=a[head]*9 && tail<=n) ++tail; if (head==n) break; ans+= (Long Long) (tail-head-1); ++head; } printf ("%lld\n", ans); return 0;}
"Dichotomy", "ruler Method" bzoj2348 [Baltic 2011]plagiarism