NOI Online burst egg note

Too much food can only participate in the TG group

PJ next door than the TG test of how hard it is fat thing? ?

Egg explosion process

8:20 to get up

Then load side while other issues yeah breakfast,What a mess this server ccf

8:40 only to see the face of questions, first read it again all ABC

A50 minutes played first, then think about B (9:00)

B launched a push for a long time to exchange a maximum of only affect the adjacent reverse the conclusion of a number, but still thought the 40 minute practice, went back to see A

A 60 minutes and then found a parity of sentence on the line (do not know right), then one will hit finished, (9:30

And then went to push B, blind push even launch a conclusion: (9:50

Defined \ (S_I \) for the first \ (I \) before than the first number (I \) \ large number number, then each operation are all \ (S_I \) forward movement and a subtracted 1,0 without reduction

It is to query a number greater than the number and range and the number of period

I thought this is a dynamic two-dimensional problem of the number of points, then keep trying to write a two-dimensional BIT Han

At 10:50, when I suddenly thought, \ (S_1 \) must be 0, then it becomes a number greater than the entire array query within a certain number and the number and

right! value! line! segment! tree!

11:00 After a sample, 11:10 to complete the shoot

For each k then C is equivalent to title number n of the same size consisting of several rings, can enumerate factor, an analog answer violence

In 11:59:43 done to pay up

But there is a place to write the bombing, it may burst egg / kk

Desirable Score: 60 + 100 + 100 = 260

I have heard that C class in addition to the AK QAQ / kk %%%%%%%%%%%%%%%%%%%%%%%%

answer

A

1 to 5 for the direct determination \ (a_1-b_1 \) is equal to \ (a_2-b_2 \) to

For the 6 to 10, it is judged \ (a_1-b_1 = b_2- a_2 \) or \ (A_2-B_2 = B_1-A_1 \) , a two to satisfy

For 11 to 12, if the \ (t = 1 \) and \ (t = 2 \) operation wherein only a direct do so in accordance with the practice of 1 to 10

Otherwise, you can determine what parity judgment \ ((a_1-b_1) \ bmod 2 = (a_2-b_2) \ bmod 2 \) to

The rest will not be expected to score 60

// This code wrote by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
const int MaxN=100050;
struct Quetion
{
    int t,u,v;
}Q[MaxN];
template <class t> inline void read(t &s)
{
    s=0;
    reg int f=1;
    reg char c=getchar();
    while(!isdigit(c))
    {
        if(c=='-')
            f=-1;
        c=getchar();
    }
    while(isdigit(c))
        s=(s<<3)+(s<<1)+(c^48),c=getchar();
    s*=f;
    return;
}
int n,m;
int a[MaxN],b[MaxN];
namespace SUBTASK1
{
    inline void solve()
    {
        if(a[1]-b[1]==a[2]-b[2])
            puts("YES");
        else
            puts("NO");
        return;
    }
}
namespace SUBTASK2
{
    inline void solve()
    {
        if((a[1]-b[1]==b[2]-a[2])||(a[2]-b[2]==b[1]-a[1]))
            puts("YES");
        else
            puts("NO");
        return;
    }
}
namespace SUBTASK3
{
    inline void solve(int c1,int c2)
    {
        if(c1&&c2)
        {
            if(((a[1]-b[1])&1)==((a[2]-b[2])&1))
                puts("YES");
            else
                puts("NO");
            return;
        }
        else
        {
            if(c1)
                SUBTASK1::solve();
            else
                SUBTASK2::solve();
        }
        return;
    }
}
inline void work()
{
    read(n);read(m);
    for(int i=1;i<=n;++i)
        read(a[i]);
    for(int i=1;i<=n;++i)
        read(b[i]);
    reg int cnt1=0,cnt2=0;
    for(int i=1;i<=m;++i)
    {
        read(Q[i].t);read(Q[i].u);read(Q[i].v);
        if(Q[i].t==2)
            ++cnt2;
        if(Q[i].t==1)
            ++cnt1;
    }
    if(n==2&&m==1&&cnt1)
    {
        SUBTASK1::solve();
        return;
    }
    if(n==2&&m==1&&cnt2)
    {
        SUBTASK2::solve();
        return;
    }
    if(n==2)
    {
        SUBTASK3::solve(cnt1,cnt2);
        return;
    }
    return;
}
signed main(void)
{

    freopen("sequence.in","r",stdin);
    freopen("sequence.out","w",stdout);

    int t;cin>>t;
    while(t--)
        work();
    return 0;
}

B

We prosequence set to \ (a_i \) , \ (S_I \) of \ (a_1, a_2, \ cdots , a_ {i-1} \) is greater than \ (a_i \) number of the number of

For a \ (A \) sequence requirements \ (S \) sequence may be used Fenwick tree \ (O (n \ log n ) \) implemented

Let's look at an example (assuming that \ (s_i \) has been seeking good)

a: 1 4 3 5 2
s: 0 0 1 0 3

After bubbling round

a: 1 3 4 2 5
s: 0 0 0 2 0

One will find that each is greater than 0 \ (s_i \) are subtracted 1 and all \ (s_i \) are to the left of a

Then you will find, \ (S_1 \) certain to 0 (by the \ (s_i \) of the definition of shows)

Then left shift operation can be ignored, then \ (t = 2 \) operation becomes

Current demand \ (A \) sequence \ (\ sum_ {i = 1 } ^ n \ max (s_i-c, 0) \)

It is asked (in this case refers to the sequence \ (S \) sequence)
\ [\ text {all particles larger than the sequence} c \ text {numbers and} - \ text {greater than the sequence} c \ text {number th number} \ times c \]
this direct weight maintenance on the line segment tree (tree or two arrays may be)

Now, if the switching operation is re-evaluated by direct violence \ (S \) sequence able to get the 60 minutes

But not far away from the 100 points

We take a look at:

Suppose \ (p <q \)

a: p q
s: x y

Exchange \ (P, Q \) , since \ (p <q \) so \ (P \) corresponding to \ (S \) to \ (+ 1 \) , and \ (Q \) corresponding to \ (S \ ) will not change

a: q p
s: y x+1

\ (p> q \) almost

Therefore we use this exchange operation as long as the properties of each single point modify \ (S \) on the line, a single modification complexity \ (O (\ log n) \)

The total time complexity \ (O (m \ log n ) \)

// This code wrote by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
const int MaxN=200050;
template <class t> inline void read(t &s)
{
    s=0;
    reg int f=1;
    reg char c=getchar();
    while(!isdigit(c))
    {
        if(c=='-')
            f=-1;
        c=getchar();
    }
    while(isdigit(c))
        s=(s<<3)+(s<<1)+(c^48),c=getchar();
    s*=f;
    return;
}
int n,m;
int a[MaxN],b[MaxN];
int tr[MaxN];
int val[MaxN<<2];
int sum[MaxN<<2];
inline int lowbit(int x)
{
    return x&(-x);
}
inline void modify(int x,int k)
{
    while(x<=n)
    {
        tr[x]+=k;
        x+=lowbit(x);
    }
    return;
}
inline int queryP(int x)
{
    reg int res=0;
    while(x>0)
    {
        res+=tr[x];
        x-=lowbit(x);
    }
    return res;
}
inline int query(int l,int r)
{
    return queryP(r)-queryP(l-1);
}
#define lson (u<<1)
#define rson (u<<1|1)
inline void Spushup(int u)
{
    val[u]=val[lson]+val[rson];
    sum[u]=sum[lson]+sum[rson];
    return;
}
inline void Smodify(int u,int l,int r,int p,int k)
{
    if(l==r)
    {
        // printf("Smodify %lld %lldx%lld\n",u,k,l);
        val[u]+=k;
        sum[u]+=k*l;
        return;
    }
    reg int mid=(l+r)>>1;
    if(p<=mid)
        Smodify(lson,l,mid,p,k);
    else
        Smodify(rson,mid+1,r,p,k);
    Spushup(u);
    return;
}
inline pair<int,int> Squery(int u,int l,int r,int ql,int qr)
{
    if(ql<=l&&r<=qr)
        return make_pair(val[u],sum[u]);
    reg int mid=(l+r)>>1;
    reg pair<int,int> res=make_pair(0,0);
    if(ql<=mid)
    {
        reg pair<int,int> t=Squery(lson,l,mid,ql,qr);
        res.first+=t.first;
        res.second+=t.second;
    }
    if(mid<qr)
    {
        reg pair<int,int> t=Squery(rson,mid+1,r,ql,qr);
        res.first+=t.first;
        res.second+=t.second;
    }
    // printf("Squery %lld %lld is %lld %lld\n",l,r,res.first,res.second);
    return res;
}
inline void recalc()
{
    // memset(tr,0,sizeof tr);
    // memset(val,0,sizeof val);
    // memset(sum,0,sizeof sum);
    for(int i=1;i<=n;++i)
    {
        b[i]=query(a[i],n);
        // printf("recalc %lld is %lld\n",i,t);
        if(b[i])
            Smodify(1,1,n,b[i],1);
        modify(a[i],1);
    }
    return;
}
inline void work(int i,int j)
{
    if(a[i]>a[j])
    {
        if(b[j]>0)
            Smodify(1,1,n,b[j],-1);
        --b[j];
        if(b[j]>0)
            Smodify(1,1,n,b[j],1);
        swap(a[i],a[j]);
        swap(b[i],b[j]);
    }
    else
    {
        if(b[i]>0)
            Smodify(1,1,n,b[i],-1);
        ++b[i];
        if(b[i]>0)
            Smodify(1,1,n,b[i],1);
        swap(a[i],a[j]);
        swap(b[i],b[j]);
    }
    return;
}
signed main(void)
{

    freopen("bubble.in","r",stdin);
    freopen("bubble.out","w",stdout);

    cin>>n>>m;
    for(int i=1;i<=n;++i)
        read(a[i]);
    recalc();
    reg int t,c;
    for(int i=1;i<=m;++i)
    {
        read(t);read(c);
        if(t==1)
        {
            // swap(a[c],a[c+1]);
            work(c,c+1);
        }
        else
        {
            if(c>=n)
                puts("0");
            else
            {
                reg pair<int,int> res=Squery(1,1,n,c+1,n);
                // printf("query %lld %lld is %lld %lld\n",c+1,n,res.first,res.second);
                printf("%lld\n",res.second-res.first*c);
            }
        }
    }
    return 0;
}

C

To play with the strong hand, length of the loop is found \ (\ frac n {\ gcd (n, k)} \)

The answer must be the same length and the same ring, the factors enumerated directly, pretreatment

\ (\ {1,2,3,4,5,6 \} \) in \ (k = 1 \) when put into the \ (\ {2,4,6,5,3,1 \} \)

Can be found, from largest to smallest is the case, first put 6, 6 put five on the right, left 6 put the right place on the right of the left 4,6 3,6 2 to put the left

So obviously, to get two hands on the line

Then \ (k> 1 \) when such a process can be performed on each ring

Remember in particular deal with what \ (k = 0 \) case

// This code wrote by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
const int MaxN=200050;
template <class t> inline void read(t &s)
{
    s=0;
    reg int f=1;
    reg char c=getchar();
    while(!isdigit(c))
    {
        if(c=='-')
            f=-1;
        c=getchar();
    }
    while(isdigit(c))
        s=(s<<3)+(s<<1)+(c^48),c=getchar();
    s*=f;
    return;
}
int n;
int a[MaxN],b[MaxN],ans[MaxN];
int thezero;
inline int dfs(int l,int r)
{
    // printf("dfs %lld %lld\n",l,r);
    reg int L=1e5;
    reg int R=1e5-1;
    for(int i=r;i>=l;--i)
        if(i&1)
            b[++R]=a[i];
        else
            b[--L]=a[i];
    reg int res=0;
    for(int i=L;i<=R;++i)
        if(i==R)
            res+=b[R]*b[L];
        else
            res+=b[i]*b[i+1];
    // puts("ok");
    return res;
}
inline int gcd(int a,int b)
{
    return !b?a:gcd(b,a%b);
}
signed main(void)
{

    // freopen("ring.in","r",stdin);
    // freopen("ring.out","w",stdout);

    int m;
    cin>>n>>m;
    for(int i=1;i<=n;++i)
        read(a[i]),thezero+=a[i]*a[i];
    sort(a+1,a+n+1);
    for(int i=1;i<n;++i)
        if(!(n%i))
        {
            for(int j=1;j<=n;j+=n/i)
                ans[i]+=dfs(j,j+n/i-1);
        }
    for(int i=1;i<=m;++i)
    {
        reg int c;
        read(c);
        if(!c)
            printf("%lld\n",thezero);
        else
            printf("%lld\n",ans[gcd(c,n)]);
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/chinesepikaync/p/12445637.html