[Offer收割]编程练习赛31 register

Ended

Participants:284

Verdict:Accepted
Score:100 / 100
Submitted:2017-10-15 13:50:37

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e6;
int a[MAX];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    sort(a,a+n);
    long long ans=0;
    for(int i=0;i<n;i++)
    {
        int l=lower_bound(a,a+n,(int)ceil(0.125*a[i]+8))-a;//printf("l=%d ",l);
        int r=upper_bound(a,a+n,8*a[i]+8)-a; //printf("r=%d ",r);
        if(a[i]<88888)
        {
            int x=upper_bound(a,a+n,88888)-a; //printf("x=%d \n",x);
            r=min(r,x);
        }
        ans+=max(0,r-l);
        if(i>=l&&i<r)ans--;
    }
    cout<<ans<<endl;
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX