2019 Multi-University Training Contest 2

 

Question number A B C D E F G H I J K L
status .

.

. . THE . . . . THE THE THE

1005  Everything Is Generated In Equal Probability

 

//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<math.h>
#include<cmath>
#include<time.h>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<algorithm>
#include<numeric>
#include<stack>
#include<bitset>
#include<unordered_map>
const int maxn = 0x3f3f3f3f;
const double EI = 2.71828182845904523536028747135266249775724709369995957496696762772407663035354594571382178525166427;
const double PI = 3.141592653589793238462643383279;
//#ifdef TRUETRUE
//#define gets gets_s
//#endif
using namespace std;
long long p = 998244353;
long long quick(long long a, int b, int c)
{
    long long ans = 1;
    a = a % c;
    while (b != 0)
    {
        if (b & 1)
        {
            ans = (ans * a) % c;
        }
        b >>= 1;
        a = (a * a) % c;
    }
    return ans;
}
struct s
{
    long long a, b,ans;
}z[3010];
long long ans[3010], aa[3010];
int main(void)
{
    int i, j, k;
    long long zz = 2;
    z[1].a = 0;
    z[1].ans = 0;
    long long z3 = quick(3, p - 2, p);
    //printf("  %lld\n",z3);
    for (i = 2; i <= 3000; i++)
    {
        z[i].a = z[i - 1].a + zz;
        z[i].a %= p;

        z[i].ans = (z[i].a * z3) % p;

        zz += 2;
        zz %= p;
    }
    ans[1] = 0;
    aa[1] = 0;
    for (i = 2; i <= 3000; i++)
    {
        ans[i] = (ans[i - 1] + z[i].ans) % p;
        aa[i] = (ans[i] * quick(i, p - 2, p)) % p;
    }
    int N;
    while (~scanf("%d", &N))
    {
        printf("%lld\n", aa[N]);
    }
    return 0;
}
View Code

 

1010 Just Skip The Problem

 

//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<math.h>
#include<cmath>
#include<time.h>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<algorithm>
#include<numeric>
#include<stack>
#include<bitset>
#include<unordered_map>
const int maxn = 0x3f3f3f3f;
const double EI = 2.71828182845904523536028747135266249775724709369995957496696762772407663035354594571382178525166427;
const double PI = 3.141592653589793238462643383279;
//#ifdef TRUETRUE
//#define gets gets_s
//#endif
using namespace std;
long long p = 1e6 + 3;
int main(void)
{
    long long n,i,ans;
    while (~scanf("%lld",&n))
    {
        if (n >= p)
        {
            printf("0\n");
            continue;
        }
        ans = 1;
        for (i = 1;i <= n;i++)
        {
            ans *= i;
            ans %= p;
        }
        printf("%lld\n",ans);
    }
    return 0;
}
View Code

 

1011 Keen On Everything But Triangle

The meaning of problems: a match given n, q interrogation times, each time interrogation [l, r] in the section matches the longest perimeter of the triangle is composed of many.

Ideas: Consider the violence, must be within the l to r interval all digital ordering, then descending order check the adjacent three matches can make up the triangle.

  Optimization considerations, the nature of the Fibonacci number is available, the match within the range of 45 1e9 will be able to form a triangle (1,1,2,3,5 worst case, item 45 of more than 1e9), so segment tree maintenance interval of 46 maximum, and then do the above check on it.

#include<bits/stdc++.h>
#define clr(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=200010;
struct node{
    int l,r,size;
    ll a[50];
}tr[maxn<<2];
ll val[maxn];
int n,q;
inline ll rd()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline void pushup(int o,int oa,int ob){
    int i=1,j=1,k=0;
    while(++k<=tr[o].size){
        if(i<=tr[oa].size&&tr[oa].a[i]>=tr[ob].a[j]){
            tr[o].a[k]=tr[oa].a[i];
            i++;
        }else{
            tr[o].a[k]=tr[ob].a[j];
            j++;
        }
    }
}
inline void build(int o,int l,int r){
    tr[o].size=min(r-l+1,46);
    for(int i=1;i<=tr[o].size;i++){
        tr[o].a[i]=0;
    }
    if(l==r){
        tr[o].a[1]=val[l];
        return;
    }
    int mid=(l+r)>>1;
    build(o<<1,l,mid);
    build(o<<1|1,mid+1,r);
    pushup(o,o<<1,o<<1|1);
}
ll ans[50],temp[50];
int top=0;
inline void query(int o,int l,int r,int ql,int qr){
    if(ql<=l&&r<=qr){
        int si=min(46,top+tr[o].size);
        int i=1,j=1,k=0;
        while(++k<=si){
            if(i<=top&&ans[i]>=tr[o].a[j]){
                temp[k]=ans[i];
                i++;
            }else{
                temp[k]=tr[o].a[j];
                j++;
            }
        }
        top=si;
        for(int i=1;i<=top;i++){
            ans[i]=temp[i];
        }
        for(int i=top+1;i<=46;i++){
            ans[i]=0;
        }
        return;
    }
    int mid=(l+r)>>1;
    if(ql<=mid)query(o<<1,l,mid,ql,qr);
    if(mid<qr)query(o<<1|1,mid+1,r,ql,qr);
}
int main(){
    while(cin>>n>>q){
        for(int i=1;i<=n;i++){
//            scanf("%lld",&val[i]);
            val[i]=rd();
        }
        build(1,1,n);
        while(q--){
            int l,r;
            top=0;
            l=rd(),r=rd();
            query(1,1,n,l,r);
            ll an=-1;
            for(int i=1;i<=top-2;i++){
                if(ans[i]<ans[i+1]+ans[i+2]){
                    an=ans[i]+ans[i+1]+ans[i+2];
                    break;
                }
            }
            printf("%lld\n",an);
        }
    }
}
View Code

 

1012 Longest Subarray

The meaning of problems: n digital given, find a longest substring, the number of times this number string contains requirements must be greater than equal to k.

Thinking: first the whole string of k times less than the number of all removed, to obtain a plurality of non-contiguous substrings of these substrings recursively do the job. Adjustment to the parameters, the recursive return directly to layer 30 when.

(This approach can be hack, but the data more difficult to make, bet on the topic and people do not practice this card, his teammates tql)

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=b;i>=a;i--)
using namespace std;
#define ll long long
const int N=3e5+5;
const int mod = 998244353;
int a[301010],c[301010],q[301010];
int n,C,k,ans;
ll rd()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void solve(int l,int r,int dep)
{
    if(dep>=30) return;
    //printf("l=%d r=%d\n",l,r);
    if(r-l+1<=ans) return;
    int flag=0,pre,cnt=0;
    rep(i,l,r) c[a[i]]=0;
    rep(i,l,r) ++c[a[i]];
    q[++cnt]=l-1;
    rep(i,l,r) 
    {
        if(c[a[i]]<k) 
        {
            q[++cnt]=i;
            flag=1;
        }
    }
    q[++cnt]=r+1;
    if(flag==0)
    {
        ans=r-l+1;    
    }    
    rep(i,1,cnt) solve(q[i]+1,q[i+1]-1,dep+1);
}
int main()
{
//    freopen("1.in","r",stdin);
//    freopen("1.out","w",stdout);
    while(~scanf("%d%d%d",&n,&c,&k))
    {    
        ans=0;
        rep(i,1,n) a[i]=rd();
        solve(1,n,1);
        printf("%d\n",ans);
    }
}
View Code

 

Guess you like

Origin www.cnblogs.com/mountaink/p/11240079.html