Science Vol math · english · chinese · biology · chemistry · physics

A ratio of a bomb, I really only do B-roll, although I B are poor but not poor to the point

$math$

answer

Seemingly can not do but there will always be a breakthrough

$70\%$

Oscar discovery and temptation like, so to see whether the $ gcd $ $ $ 1 $ 1 $ as long as you can cobble together the number of all

$ N ^ 2 $ enumeration twenty-two $ gcd $

$80\%$

When I test ideas

Find every number and $ mod $ of $ gcd $, found that as long as any of the $ gcd $ multiples can scrape out, so enumerate every number and $ mod $ of $ gcd $, the bottleneck is the statistical answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define A 2222222
ll n,k,cnt=0;
ll a[A],dl[A],ok[A];
ll read(){
    ll x=0,f=1;char c=getchar();
    while(!isdigit(c)){
        if(c=='-')
            f=-1;
        c=getchar();
    }
    while(isdigit(c)){
        x=x*10+c-'0';
        c=getchar();
    }
    return f*x;
}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
int main(){
    n=read(),k=read();    
    for(ll i=1;i<=n;i++)
        a[i]=read(),dl[++dl[0]]=a[i];
    for(ll i=1;i<=dl[0];i++){
        ll g=gcd(dl[i],k);
        if(g==1){
            printf("%lld\n",k);
            for(ll j=0;j<=k-1;j++){
                printf("%lld ",j);
            }
            return 0;
        }
        else {
            for(ll i=g;i<k;i+=g){
                ok[i]=1;
            }
            ok[0]=1;
        }
    }
    for(ll i=0;i<=k;i++){
        if(ok[i]) cnt++;
    }
    printf("%lld\n",cnt);
    for(ll i=0;i<=k;i++){
    if(ok[i])    printf("%lld ",i);
    }
    printf("\n");
}
View Code

$100\%$

In fact, from $ 80 \% $ we can find all should see the number of $ gcd $, and then only for the $ gcd $ multiples can scrape out

I do not think even this exam!

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define A 1010101
ll n,k,cnt=0;
ll a[A],dl[A];
ll read(){
    ll f=1,x=0;
    char c=getchar();
    while(!isdigit(c)){
        if(c=='-') f=-1;
        c=getchar();
    }
    while(isdigit(c)){
        x=x*10+c-'0';
        c=getchar();
    }
    return f*x;
}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
int main(){
    n=read(),k=read();
    for(ll i=1;i<=n;i++){
        a[i]=read();
           while(a[i]<0){
            a[i]+=k;
        }
    }
    ll g=gcd(a[1],a[2]);
    g=gcd(g,k);
    for(ll i=3;i<=n;i++)
        g=gcd(a[i],g);
    for(ll i=0;i<k;i+=g){
        cnt++;
        dl[++dl[0]]=i;
    }
    printf("%lld\n",cnt);
    for(ll i=1;i<=dl[0];i++){
        printf("%lld ",dl[i]);
    }
    printf("\n");
}
View Code

$english$

answer

Breaking title fight for a long time from May to hit $ 23 $ 27 $ $ Day

However, examination of two people on the spot $ AC $

The idea is fairly simple, but very difficult to fight, not to mention my yard too weak

$ Ans1 $ fairly simple, and the number of math questions like that,

We find the most left $ l $ per a maximum value of $ r $ rightmost

Set the current value of the position is $ now $

So because it is exclusive or cause the contribution of only $ now-l $ with $ r-now $ bit in the opposite

Provided $ 0 [x] [j] $ represents $ 1 - x $ J first $ $ $ $ 0 bit number of how many (and which is a prefix)

Similar set $ 1 [x] [j] $ represents $ 1 - x $ J first $ $ $ 1 $ bit number of the number of

Then the contribution of $ $ is now $ \ sum \ limits_ {j = 1} ^ {j <= highest} (0 [now] [j] -0 [l-1] [j]) * (1 [r] [j] -1 [now-1] [j]) + (1 [now] [j] -1 [l-1] [j]) * (0 [r] [j] -0 [now-1] [j]) $

To find the problem and then converted to the left-most $ l $ is the maximum value of each of the rightmost $ r $

Here I still use my old method (stupid)

void pre(ll l,ll r,ll now,ll nowmax){
    if(l>r) return ;
    lef[now]=l,rig[now]=r;
    if(l==r) {
        len[now]=r-l+1;
        return ;
    }
    maxn=-1,ida=0;
    if(l<=now-1){    
        seg_max(1,l,now-1);
        pre(l,now-1,ida,maxn);
    }
    maxn=-1,ida=0;
    if(now+1<=r){
        seg_max(1,now+1,r);
        pre(now+1,r,ida,maxn);
    }
}

Binary tree segment sets

It said complexity metaphysical $ n * {log (n) ^ 2} $ however it is only practical to run slower than the stack monotonically $ 400ms $, faster than the number of mathematical stack monotone

$ Ans2 $ but still a little difficult to find a breakthrough

The official solution to a problem the first place

This is a good transformation, and I realize he's not the same

(Heuristic merge hard hit, but in fact I did not hit a fat transfer)

I can persist $ tire $,

Persistable $ tire $ can check interval

To find the right range of how many $ xor $ current $ a [j] $ larger than the maximum value

Into $ tire $ tree to see if the current maximum of $ 1 $ bit, you can not than it big, you must choose the opposite position, is $ 0 $ large number than it is $ size $ a (lower than its large size all )

Put about realization

void work2(){
    root[0]=newnode();
    for(ll i=1;i<=n;i++)
        root[i]=newnode(),insert(root[i-1],root[i],a[i]);
    for(ll i=1;i<=n;i++){
        ll tmp=0;
        if(rig[i]-i>i-lef[i])
            for(ll j=lef[i];j<=i;j++)
                tmp=(tmp+query(root[i-1],root[rig[i]],a[j],a[i]))%mod;
        if(rig[i]-i<=i-lef[i])
            for(ll j=i;j<=rig[i];j++)
                tmp=(tmp+query(root[lef[i]-1],root[i],a[j],a[i]))%mod;
        ans2=(ans2+tmp*a[i])%mod;
    }
}
ll query(ll F,ll C,ll now,ll big){
    ll ans=0;
    for(ll i=20;i>=0;i--){
        ll num[2];
        num[0]=sz[ch[C][0]]-sz[ch[F][0]];
        num[1]=sz[ch[C][1]]-sz[ch[F][1]];
        ll 
        nowbit=(now>>(i))&1,
        bigbit=(big>>(i))&1;
        if(bigbit) F=ch[F][nowbit^1],C=ch[C][nowbit^1];
        else F=ch[F][nowbit],C=ch[C][nowbit],ans=(ans+num[nowbit^1]%mod); 
    }
    return ans;
}

Total code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define A 222222
const ll mod=1e9+7;
ll n,q,mx,mn=0x7fffffffff,ida,maxn,idb,thebigest,thebigestid,ans1,ans2;
ll a[A],sum[A],b[A],ls[A],rs[A],len[A],_0[A][33],_1[A][33],lef[A],rig[A],sta[A];
ll root[A];
ll sz[11111111];
ll ch[11111111][2];
ll totnode=1,top=0;
char c[10];
struct tree{
    ll l,r,val,id;
}tr[A];
void init(){
    for(ll i=1;i<=n;++i){
        while(top&&a[sta[top]]<a[i]) rig[sta[top--]]=i-1;
        sta[++top]=i;
    }
    while(top) rig[sta[top--]]=n;
    for(ll i=n;i>=1;--i){
        while(top&&a[sta[top]]<=a[i]) lef[sta[top--]]=i+1;
        sta[++top]=i;
    }
    while(top) lef[sta[top--]]=1;
}
void pushup(ll p){
    if(tr[p<<1].val>tr[p<<1|1].val){
        tr[p].val=tr[p<<1].val;
        tr[p].id=tr[p<<1].id;
    }
    else {
        tr[p].val=tr[p<<1|1].val;
        tr[p].id=tr[p<<1|1].id;
    }
}
void built(ll p,ll l,ll r){
    tr[p].l=l,tr[p].r=r;
    if(l==r){
        tr[p].val=a[l];
        tr[p].id=l;
        return ;
    }
    ll mid=(l+r)>>1;
    built(p<<1,l,mid);
    built(p<<1|1,mid+1,r);
    pushup(p);
}
void seg_max(ll p,ll l,ll r){
    if(tr[p].l>=l&&tr[p].r<=r){
        if(tr[p].val>maxn){
            maxn=tr[p].val;
            ida=tr[p].id;
        }
        return ;
    }
    ll mid=(tr[p].l+tr[p].r)>>1;
    if(mid>=l)
        seg_max(p<<1,l,r);
    if(mid<r)
        seg_max(p<<1|1,l,r);
}
void pre(ll l,ll r,ll now,ll nowmax){
    if(l>r) return ;
    lef[now]=l,rig[now]=r;
    if(l==r) {
        len[now]=r-l+1;
        return ;
    }
    maxn=-1,ida=0;
    if(l<=now-1){    
        seg_max(1,l,now-1);
        pre(l,now-1,ida,maxn);
    }
    maxn=-1,ida=0;
    if(now+1<=r){
        seg_max(1,now+1,r);
        pre(now+1,r,ida,maxn);
    }
}
void work1(){
    for(ll j=0;j<=20;j++)
        for(ll i=1;i<=n;i++){
            _0[i][j]=_0[i-1][j];
            _1[i][j]=_1[i-1][j];
            if((a[i]&(1<<j))) _1[i][j]++;
            else _0[i][j]++;
        }
    for(ll i=1;i<=n;i++){
        ll tmp=0;
        for(ll j=0;j<=20;j++){
            ll 
            l0=_0[i][j]-_0[lef[i]-1][j],
            r0=_0[rig[i]][j]-_0[i-1][j],
            l1=_1[i][j]-_1[lef[i]-1][j],
            r1=_1[rig[i]][j]-_1[i-1][j];
            tmp=(tmp+(l0*(r1%mod*(1<<j)%mod)))%mod;
            tmp=(tmp+(l1*(r0%mod*(1<<j)%mod)))%mod;
        }ans1=(ans1+tmp*a[i])%mod;
    }
}
ll newnode(){
    memset(ch[totnode],0,sizeof(ch[totnode]));
    sz[totnode]=0;
    return totnode++;
}
//F之前树 C现在树 
inline void insert(ll F,ll C,ll val){
    for(ll i=20;i>=0;i--){
        ll bit=(val>>i)&1;
        if(!ch[C][bit]){
            ch[C][bit]=newnode();
            ch[C][!bit]=ch[F][!bit];
            sz[ch[C][bit]]=sz[ch[F][bit]];
        }
        C=ch[C][bit],F=ch[F][bit];
        sz[C]++;
    }
}
ll query(ll F,ll C,ll now,ll big){
    ll ans=0;
    for(ll i=20;i>=0;i--){
        ll num[2];
        num[0]=sz[ch[C][0]]-sz[ch[F][0]];
        num[1]=sz[ch[C][1]]-sz[ch[F][1]];
        ll 
        nowbit=(now>>(i))&1,
        bigbit=(big>>(i))&1;
        if(bigbit) F=ch[F][nowbit^1],C=ch[C][nowbit^1];
        else F=ch[F][nowbit],C=ch[C][nowbit],ans=(ans+num[nowbit^1]%mod); 
    }
    return ans;
}
void work2(){
    root[0]=newnode();
    for(ll i=1;i<=n;i++)
        root[i]=newnode(),insert(root[i-1],root[i],a[i]);
    for(ll i=1;i<=n;i++){
        ll tmp=0;
        if(rig[i]-i>i-lef[i])
            for(ll j=lef[i];j<=i;j++)
                tmp=(tmp+query(root[i-1],root[rig[i]],a[j],a[i]))%mod;
        if(rig[i]-i<=i-lef[i])
            for(ll j=i;j<=rig[i];j++)
                tmp=(tmp+query(root[lef[i]-1],root[i],a[j],a[i]))%mod;
        ans2=(ans2+tmp*a[i])%mod;
    }
}
int main(){
    scanf("%lld%lld",&n,&q);
    for(ll i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        if(a[i]>mx)
            ida=i,mx=a[i];
        mn=min(mn,a[i]);
    }
    thebigestid=ida;
    built(1,1,n);
    pre(1,n,ida,a[ida]);
    work1();work2();
    if(q==1)printf("%lld\n",ans1);
    if(q==2)printf("%lld\n",ans2);
    if(q==3)printf("%lld\n%lld\n",ans1,ans2);
}
View Code

chinese

answer

True eat the loss languages

Exam been doing this question (about $ 2 $ hour) but still only violence

First to figure out the meaning of sub-title Chinese

In fact, he is to let you count the number of all programs calligraphy

Too lazy to write the first official explanations put back to fix

 

Guess you like

Origin www.cnblogs.com/znsbc-13/p/11428910.html