Usaco2011open Silver Running laps

Source: Internet
Author: User

Please ignore I think of cattle as sheep ....

By test instructions, we can get T*VI-T*VJ=KC. So the number of I,j encounters is the largest K (integer). In order to get the largest k it is necessary to make T Max, and Tmax=l*c/vmax.

Then bashi the sub-finishing get:

k=l* (VI-VJ)/vmax. (Rounded down)

For the first, it is determined by the number of encounters with every sheep that is smaller than it.

The common idea is to use prefixes and bashi to accumulate, but since K is the result of an operation rounding between two sheep, the answer will change when added together. Therefore, we can calculate the effect of the additive algorithm on the correct answer.

Let's look at two formulas:

a1=[a*t+b-(c*t+d)]/t and a2= (a*t+b)/t-(c*t+d)/t (A,c is integer; b,d∈[0,t-1])

To deform:

a1=[(a-c) *t+b-d]/t

A2=a-c.

Only when b-d<0, i.e. B<d, A1!=A2 and a1=a2-1.

Now let's look at the original question:

When l*c* (VI-VJ)/(VMAX*C) becomes

(L*C*VI)/(Vmax*c)-(L*C*VI)/(VMAX*C), the answer will not change depending on l*c*vi and l*c*vj in addition to the remainder size relationship of Vmax*c.

If the former is less than the latter, the answer is minus 1.

We enumerate every sheep by speed from large to small

For the answer of sheep i = (i-1) *l*vi/vmax-l*sumv[i-1]/vmax-cnt.

Here CNT indicates that the remainder is greater than the remainder of sheep I, and the speed is less than the number of sheep I.

We'll sort the remainder by X. Then the tree-like array is used to maintain the V<VI, and the number of x>xi is OK.

#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #define LL Long
Long using namespace std;
const int m=1e5+5;
const int n=1e6+5;
int n,l,vmx,c;
int val[m],tot=0;
    struct node{int v,p;
ll MoD;
}A[M];
        void Add (int x) {//tree array update while (X<=tot) {val[x]++;
    x+=x& (-X);
    }} int sum (int x) {///tree-like array sum int res=0;
        while (x>0) {res+=val[x];
    x-=x& (-X);
} return res; } bool Cmp1 (node A,node b) {return a.v<b.v;} Sort by speed bool Cmp2 (node A,node b) {return a.mod<b.mod;}
    Sort by remainder int main () {int i,j;
    scanf ("%d%d%d", &n,&l,&c);
        for (i=1;i<=n;i++) {scanf ("%d", &AMP;A[I].V); 
    Vmx=max (VMX,A[I].V);//z find maximum speed} for (i=1;i<=n;i++) a[i].mod=1ll*l*c*a[i].v% (1LL*C*VMX);//Sort (A+1,A+1+N,CMP2);
        for (i=1;i<=n;i++) {tot++;
            for (j=i;j<=n;j++) {if (a[j].mod!=a[i].mod) break;
        A[j].p=tot;} i=j-1;
    } sort (A+1,A+1+N,CMP1);
    ll Sum_pre=0,res=0; 
        for (i=1;i<=n;i++) {ll tmp=1ll*l*a[i].v/vmx;
        ll ans=tmp* (i-1)-sum_pre+sum (A[I].P)-i+1;
        sum_pre+=tmp;
        Add (A[I].P);
    Res+=ans;
    } cout<<res<<endl;
return 0;
 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.