1002 simulation game

EDITORIAL

Today's topic is the test over last year, \ (cb \) still is rubbish \ (QAQ \) .youl.png

T1 sum

link

Idea

Prefix and

We first considered the upper left corner point \ ((1,1) \) , regarded as the lower right corner point \ ((n-, m) \) , then there is \ (\ displaystyle \ sum_ {i = 1} ^ { } n-\ sum_ {J} = ^ {m}. 1 D [I] [J] = \ FRAC {m \ n-Times \ Times (+ n-m) 2} {} \) , the push themselves. There

So \ (Ans \) is the problem and the prefix.

\ (Ans = sum [x_2] [y_2] + sum [x_1-1] [y_1-1] -sum [x_1] [y_2] -sum [x_2] [y_1-1] \)

But will burst when calculating the multiplication \ (Long \; Long \) , you can use high-precision, can also be used multiply turtle speed (this seems to be a name)youl.pngyoul.png

A simple calculation seems to have \ (70 \; PTS \) .

Code

int x1,y,x2,y2,m;
inline int mul(int n, int m, int p){
    int a=n,ans=0;
    for(;m;m>>=1){
        if(m&1) ans=(ans+a)%p;
        a=(a*2)%p;
    }
    return ans;
}
inline int power(int x,int y,int m){
    int sum=x+y;
    if(~x&1) x>>=1;
    else if(~y&1) y>>=1;
    else sum>>=1;
    return mul(mul(x,y,m),sum,m);
}
signed main(){
    freopen(File".in","r",stdin);
    freopen(File".out","w",stdout); 
    x1=read(); y=read();
    x2=read(); y2=read(); m=read();
    printf("%lld",(power(x2,y2,m)-power(x1-1,y2,m)-power(x2,y-1,m)+power(x1-1,y-1,m)+2*m)%m);
    return 0;
}

T2 packet pair

link

Idea

First called violence, he had not found a large sample.

Search .jpg

Then think of half, plus the interval want violence will blow up, so he spent doubled.Theater 1.jpg

The key is dichotomous, I adjusted the blindActually overts.png

Complexity is \ (O (the n-\ log ^ the n-2) \) , I think so. . .

Code

int a[maxn],b[maxn];
int aa[maxn],bb[maxn];
int n,M;
inline bool check(int x,int len){//判断为是否合法区间
    int y=x+len-1;
    for(int i=x;i<=y;i++) aa[i]=a[i],bb[i]=b[i];
    sort(aa+x,aa+y+1); sort(bb+x,bb+y+1);
    int res=0;
    for(int i=x;i<=y;i++) res+=aa[i]*bb[i];
    return res<=M;
}
inline int solve(){
    int QAQ=0,qwq=1;//请忽略,不知该起什么变量名
    while(qwq<=n){
        int len=1;
        for(;check(qwq,len)&&qwq+len-1<=n;len*=2);//倍增
        int l=len>>1,r=min(len-1,qwq+len-1);
        while(l<r){//二分
            int mid=(l+r+1)>>1;
            if(check(qwq,mid)) l=mid;
            else r=mid-1;
        }
        qwq+=l; QAQ++;
    }
    return QAQ;
} 
signed main(){
    freopen(File".in","r",stdin);
    freopen(File".out","w",stdout); 
    n=read(); M=read();
    for(int i=1;i<=n;i++) a[i]=read();
    for(int i=1;i<=n;i++) b[i]=read();
    printf("%d",solve());
    return 0;
}

T3 city game

link

Idea

Konjac side not deleted lb.png, then only the output \ (-. 1 \) , \ (QAQ \)

But if there \ (15 \; PTS \)ts.png , true conscience.

\[ The \quad End \]

\ [\ Text {clothes on the balcony singing actors, a Painting Spring Church; it is better to join hands hidden Red, relatively poor students forget - "Painting Spring Church"} \]

Guess you like

Origin www.cnblogs.com/cbyyc/p/11619322.html