Cattle-off practice match 52 problem solution

Perhaps a better reading experience

I only made the first four questions, so write only the first four issues of the problem solution

\ (\ Mathcal {A \ count} \)

\(\mathcal{Description}\)

Given \ (n-\) , seeking
\ (\ begin {aligned} \ sum_ {i = 1} ^ n \ sum_ {j = 1} ^ ni \ times j \ end {aligned} \) and \ (\ begin { aligned} \ prod_ {i = 1
} ^ n \ prod_ {j = 1} ^ ni \ times j \ end {aligned} \) answer to \ (998,244,353 \) modulo

\(\mathcal{Solution}\)

This is a transmission sub-themes
\ (\ begin {aligned} \ sum_ {i = 1} ^ n \ sum_ {j = 1} ^ ni \ times j = \ sum_ {i = 1} ^ ni \ times \ left (\ sum_ {j = 1} ^ nj \ right) = \ left (\ sum_ {j = 1} ^ nj \ right) \ times \ left (\ sum_ {i = 1} ^ ni \ right) = \ left (\ frac {n (n + 1)}
{2} \ right) ^ 2 \ end {aligned} \) that do more topic is a matter of
its geometrical properties is a \ (n \ times n \) matrix which The number of all sub-matrix

\(\begin{aligned}\prod_{i=1}^n\prod_{j=1}^ni\times j=\prod_{i=1}^ni^n\prod_{j=1}^nj = \left(\prod_{j=1}^nj\right)^n\prod_{i=1}^ni^n = \left(\prod_{j=1}^nj^n\right)\prod_{i=1}^ni^n = \prod_{i=1}^ni^{2n}=\left(\prod_{i=1}^ni\right)^{2n}\end{aligned}\)

Not how to do push equation!
Like bloggers and direct it out!
The first is not to say
the second one is going to ride, we directly consider how many is multiplied by the not can it
be considered \ (i \) times multiplied, in the form \ (i \ times j \ ) such a case each have \ (I \) , a total of \ (n + 1 \) a \ (I \) ( \ (I \ I Times \) such case there are two \ (I \) )
form the \ (j \ times i (j ! = i) \) case for each \ (J \) will have a total of \ (n-1 \) a, so \ (I \) is multiplied by \ (2N \) times

\(\mathcal{Code}\)

/*******************************
Author:Morning_Glory
LANG:C++
Created Time:2019年09月14日 星期六 19时06分48秒
*******************************/
#include <cstdio>
#include <fstream>
#define ll long long
using namespace std;
const int maxn = 10000005;
const int mod = 998244353;
//{{{cin
struct IO{
    template<typename T>
    IO & operator>>(T&res){
        res=0;
        bool flag=false;
        char ch;
        while((ch=getchar())>'9'||ch<'0')   flag|=ch=='-';
        while(ch>='0'&&ch<='9') res=(res<<1)+(res<<3)+(ch^'0'),ch=getchar();
        if (flag)   res=~res+1;
        return *this;
    }
}cin;
//}}}
int T,n,ans1,ans2;
int s[maxn],mi[maxn];
//{{{ksm
int ksm (int a,int b)
{
    int s=1;
    for (;b;b>>=1,a=1ll*a*a%mod)
        if (b&1)    s=1ll*s*a%mod;
    return s;
}
//}}}
int main()
{
    s[1]=1;
    for (int i=2;i<=maxn-5;++i) s[i]=1ll*s[i-1]*i%mod;
    cin>>T;
    while (T--){
        cin>>n;
        ans1=1ll*n*(n+1)/2%mod;
        ans1=1ll*ans1*ans1%mod;
        ans2=ksm(s[n],2*n)%mod;
        printf("%d %d\n",ans1,ans2);
    }
    return 0;
}

\(\mathcal{B\ Galahad}\)

\(\mathcal{Description}\)

To test the ability of the Witch Knight and asked him to maintain a length \ (n \) sequence, every time you want to ask a range of and.

But the witch felt too simple, easy to remember Knight \ (n \) prefix and number.

So, witch asked him to answer a range and, if there has been a number of times in this range, this number can only be counted once.

\ (N, m \ leq 500000,1 \ leq a_i \ leq 500000 \)

\(\mathcal{Solution}\)

This problem seems to have Mo board team title, but was opened a range of data, so we the team to Mo \ (T \) a
change in thinking
first and search by \ (r \) from small to large
order \ (last_i \ ) represent numbers \ (i \) once the position appears
when we find a number \ (i \) when, just add the current position \ (i \) , in \ (last_i \) minus \ (i \) to ensure that no double counting
because we will be in accordance with the query \ (r \) from small to large sorted
so that each of the current query must pass this position now
and \ (l \ leq last_i \) case, we have \ (last_i \) answers offset, so each \ (i \) would only be counted once
and now is actually required for a range of plus and, with this Fenwick tree maintenance on it

\(\mathcal{Code}\)

/*******************************
Author:Morning_Glory
LANG:C++
Created Time:2019年09月14日 星期六 19时18分27秒
*******************************/
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = 1000006;
//{{{cin
struct IO{
    template<typename T>
        IO & operator>>(T&res){
            res=0;
            bool flag=false;
            char ch;
            while((ch=getchar())>'9'||ch<'0')   flag|=ch=='-';
            while(ch>='0'&&ch<='9') res=(res<<1)+(res<<3)+(ch^'0'),ch=getchar();
            if (flag)   res=~res+1;
            return *this;
        }
}cin;
//}}}
struct Q{
    int l,r,id;
}q[maxn];
int n,m;
int a[maxn],last[maxn];
ll c[maxn],ans[maxn];
bool cmp(Q a,Q b){  return a.r<b.r;}
//{{{query
ll query(int x)
{
    ll res=0;
    while(x>0){ res+=c[x];x-=x&-x;}
    return res;
}
//}}}
//{{{insert
void insert(int x,int v)
{
    while(x<=n){    c[x]+=v;x+=x&-x;}
}
//}}}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)   cin>>a[i];
    for(int i=1;i<=m;i++)   cin>>q[i].l>>q[i].r,q[i].id=i;
    sort(q+1,q+m+1,cmp);
    int t=1;
    for(int i=1;i<=n;i++){
        if(last[a[i]])  insert(last[a[i]],-a[i]);
        insert(i,a[i]);
        while(i==q[t].r)    ans[q[t].id]=query(q[t].r)-query(q[t].l-1),t++;
        last[a[i]]=i;
    }
    for(int i=1;i<=m;i++)   printf("%lld\n",ans[i]);
    return 0;
}

\ (\ Mathcal {C \ cooking} \)

\(\mathcal{Description}\)

Small \ (Y \) uphill study with a teacher, after (10 \) \ long years of culinary practice, when the world has become chefs, today he accepted an invitation to show their superb cooking in front of everyone.
People give small \ (Y \) provides \ (n \) kinds of food, each of an unlimited supply of food, each food has a delicious value, denoted \ (a_i \) .

Small \ (Y \) in order to demonstrate his cooking, he needs to pick out the ingredients, so that they can cook any positive integer cuisine delicious value, delicious dishes of the initial value of \ (0 \) , each time adding a food, he can choose to have delicious dishes values rise \ (a_i \) , you can also choose to have the dishes delicious value decreased \ (a_i \) (and perhaps eventually get out of the dark dishes?).

As when the world famous chef, small \ (Y \) will know how to choose the best ingredients. But he did not know how many ingredients to choose the best plan, and he found you to help.
We use the number of unordered column \ (\ left (b_1, b_2 , \ ldots, b_m \ right) \) is represented from the original (\ n-) \ kinds of ingredients are selected the \ (m \) kinds of ingredients, the \ ( i \) grown ingredients numbered \ (b_i \) program. And you need to pay attention, \ (\ left (1,2 \ right) \) and \ (\ left (2,1 \ right ) \) is the same program, and when the \ (i! = J \) when \ ( b_i! = b_j \) .
Best Choice ingredients embodiment refers species selected ingredients \ (m \) grown ingredients \ ((. 1 \ Leq m \ n-Leq) \) , so that they can be combined arbitrary positive integer food tasty value.

The answer to \ (998 244 353 \) modulo.

\(\mathcal{Solution}\)

Is a count title
count title There are many ways, \ (dp \) , inclusion and exclusion, recursive and so can count
the beginning I intend to start the calculation does not leak combined in a certain way is not heavy
but like a long time except for a few errors the method still no idea
found the time to think in a certain way as a direct count illegal
then consider the inclusion-exclusion
first of all we need to know that
can be combined in an arbitrary positive integer \ (\ Leftrightarrow \) can combine the \ (1 \)
so we will can a combination of targeting \ (1 \)
legitimate method = all methods - You can not combine the \ (1 \) method
to consider what the combination will be able to \ (1 \)
the most obvious is \ ((a, a +1) \) such as is valid
if \ (a \) is a composite number, set \ (K \) of \ (a \) is a factor
that \ ((k, a + 1 ) \) is legitimate the
can think of any \ (a, b \) as long as \ (ax-by = 1 \ ) on legitimate
as long as it is legal formula solvable\ (ax + (- by)
= 1 \) with its solvability conditions \ (gcd (a, b) = 0 \!)

In fact, a change in thinking can be obtained
as long as the prime condition to meet, since the remaining one pair of lines between them can be further obtained modulo \ (1 \) is
or is not considered as long as the prime number can not to meet the conditions, because no matter how they subtraction, the result will have their greatest common divisor in it

Thus know, have to come up with such a sequence \ (A_1, A_2, \ ldots, A_N \) , which satisfies \ (gcd (a_1, a_2,
\ ldots, a_n) = 1 \) find this number to the number of columns inclusion and exclusion can be considered a
\ (gcd = 1 \) the number of sequence \ (= \) the total number of sequence \ (-! gcd \ = 1 \) the number of sequences
considered enumerate them \ (gcd \) , so \ ( f [i] \) represented by \ (I \) a \ (GCD \) number sequence, the answer is \ (f [1] \)
and \ (f [i] = gcd \) is \ (I \ ) sequence number multiple of \ (- f [i * 2
] -f [i * 3] - \ ldots-f [i * k] \) a \ ([i] num \) indicates the number is the number of \ (I \) multiple
\ (GCD \) is \ (I \) is a multiple of the number of sequences = \ (2 ^ {NUM [I]} -. 1 \)

\ (2 ^ {num [i ]} - 1 \) is to have \ (num [i] \) number of alternative is optional, but must be at least one selected program number

This question will be resolved so that the

\(\mathcal{Code}\)

/*******************************
Author:Morning_Glory
LANG:C++
Created Time:2019年09月14日 星期六 19时33分10秒
*******************************/
#include <cstdio>
#include <fstream>
#include <algorithm>
using namespace std;
const int maxn = 3005;
const int mx = 2000;
const int mod = 998244353;
//{{{cin
struct IO{
    template<typename T>
    IO & operator>>(T&res){
        res=0;
        bool flag=false;
        char ch;
        while((ch=getchar())>'9'||ch<'0')   flag|=ch=='-';
        while(ch>='0'&&ch<='9') res=(res<<1)+(res<<3)+(ch^'0'),ch=getchar();
        if (flag)   res=~res+1;
        return *this;
    }
}cin;
//}}}
int n;
int a[maxn],num[maxn],f[maxn],s[maxn],mi[maxn];
void add (int &x,int y){    x=((x+y)%mod+mod)%mod;}
//{{{gcd
int gcd (int a,int b)
{
    if (!b) return a;
    return gcd(b,a%b);
}
//}}}
int main()
{
    mi[0]=1;
    cin>>n;
    for (int i=1;i<=n;++i)  cin>>a[i];
    for (int i=1;i<=3000;++i)   mi[i]=2ll*mi[i-1]%mod;
    for (int i=mx;i>=1;--i){
        for (int j=1;j<=n;++j)
            if (a[j]%i==0)  ++num[i];
        f[i]=(mi[num[i]]+mod-1)%mod;
        for (int j=2;i*j<=mx;++j)   add(f[i],-f[i*j]);
    }
    printf("%d\n",f[1]);
    return 0;
}

\ (\ Mathcal {D \ fan group} \)

\(\mathcal{Description}\)

In \ (wjyyy \) fan base, in addition to \ (wjy \) , a total of \ (n \) individual, numbered \ (1 \) to \ (n \) .

All ready to burst with the film \ (wjy \) , that is to say repeat \ (2n \) times the message, and because of this \ (n \) individuals in the film \ (wjy \) on the uniform, so everyone must be at least repeat once .

\ (wjy \) wants to gag off some people, but here is the \ (wjy \) fan base, not just gag film \ (wjy \) people, so \ (wjy \) set a rule:

If \ (n-\) individuals can be divided into two groups, so that the number of repetition of two groups and adding all the same, then this \ (n-\) individuals have been banned.

I \ (n \) individuals begin to discuss, they do not want to be tyranny.

So the question is, how many repeat allocation method are such that \ (wjyyy \) can not put \ (n \) people divided into two groups meet the above criteria?

However \ (wjy \) so many fans, as long as you output several methods of allocation and distribution of these methods lexicographically first \ (k \) XOR can be small and the distribution pattern.

Note: If there are two people, the repeat times were \ ((1,3) \) and the number of repeat are \ ((3,1) \) two different distribution count.

\(\mathcal{Solution}\)

That question hit the table to find the law can also be seen in
First of all repeat at least once per person, will be credited first to repeat once everyone

\(1\) \(2\) \(3\) \(\ldots\) \(n\)
\(1\) \(1\) \(1\) \(\ldots\) \(1\)

Now left \ (n \) times repetition to give these people and make them unable divided into two groups plus the number of repetition and the same

Consider the extreme case
, if these \ (n \) chances per person once again
it is the final person to repeat twice
when \ (n \) is odd, this condition is satisfied, and the \ (n \) is even is not satisfied
if this \ (n \) chance all to a person, then that person will have \ (n + 1 \) times to repeat
the rest of the people together does not exceed his number of repeat, so all to meet the conditions of a person is

Then consider the general case
, if some people have not been assigned to the repeat times (that is, only repeat once)
we repeat times larger than \ (1 \) people as possible were divided into two groups, Replay times are \ (x, y (x <y) \)
then there must be \ (yx \) the individual is the only repeat once
here you can own hands to play \ (3,4,5,6 \) so take a look to understand
these people into \ (x \) to the other side, it is just the average of the two groups
so these conditions are not met

In summary
Only \ (n \) times to repeat all of a person is absolutely satisfied
when \ (n \) is odd when everyone is also possible to repeat twice
and lexicographical definitely \ ((1,1 \ ldots1, n + 1), ( 1,1, \ ldots, n + 1,1) \ ldots (n + 1,1, \ ldots, 1,1) \) like this
consensus \ (n-\) which satisfy the conditions, when the \ (n-\) is odd even one more \ ((2,2, \ ldots,
2,2) \) in front of a stack \ (1 \) XOR it is not \ (1 \) is \ (0 \) can all be \ (O (1) \) subcontracting

\(\mathcal{Code}\)

/*******************************
Author:Morning_Glory
LANG:C++
Created Time:2019年09月14日 星期六 20时36分37秒
*******************************/
#include <cstdio>
#include <fstream>
#define ll long long
using namespace std;
//{{{cin
struct IO{
    template<typename T>
    IO & operator>>(T&res){
        res=0;
        bool flag=false;
        char ch;
        while((ch=getchar())>'9'||ch<'0')   flag|=ch=='-';
        while(ch>='0'&&ch<='9') res=(res<<1)+(res<<3)+(ch^'0'),ch=getchar();
        if (flag)   res=~res+1;
        return *this;
    }
}cin;
//}}}
ll n,k;
int main()
{
    cin>>n>>k;
    if (n==1){  printf("1\n2\n");return 0;}
    if (n&1)    printf("%lld\n%lld\n",n+1,(k==n)?2:n+1);
    else    printf("%lld\n%lld\n",n,(n+1)^1);
    return 0;
}

If not quite understand where to put it or there is an error, please correct me
if you like, you may wish to point a collection of praise about it

Guess you like

Origin www.cnblogs.com/Morning-Glory/p/11521114.html