2019 ICPC Asia Nanchang Regional E Eating Plan and discrete prefix +

Meaning of the questions:

N give you a plate, this n disks inside were filled with 1! To n! By weight of the food, a query for each k, find a shortest interval, so that the interval and the MOD  . 9 . 9 . 8 . 8 . 5 . 7 . 4 . 5 . 9 is greater than or equal to k

Number of plates n <= 1e5 interrogation frequency and m <= 1e4

 

answer:

In this pit title modulus 998 857 459 * 773 * 4 = 2803 is a composite number, so any a> = 2803 a! = 0

Thus, considering only the nonzero plate as an end point, violent enumeration $ (max (n, 2802)) ^ 2 $ intervals.

I is a recording mode using non-zero modulo factorial node and position, and then the prefix and find

Then left enumeration endpoint, the recording interval length and the section modulus and

Then the interval according to the interval and from small to large

Then small to large values ​​from the forward interval, maintain the minimum required to obtain greater than or equal to the value of the interval length.

lower_bound on the sorted segment array when asked to return to the minimum dot recording interval length.

 

#include<iostream>
#include<algorithm>
#include<vector>
#define MOD 998857459
#define INF 0x3f3f3f3f
using namespace std;
long long poww[3000];
long long res[100005];
//long long a[100005];
struct Array{
    long long val;
    long long index;
    long long sum;
A} [ 3000 ];
 Long  Long ASIZ = 0 ;
 struct Ans {
     Long  Long SUM;
     Long  Long len;
     Long  Long the minlen;
    
    friend bool operator < (const Ans &a,const Ans &b){
        return a.sum<b.sum;
    }
    friend bool operator > (const Ans &a,const Ans &b){
        return a.sum>b.sum;
    }
} years [ 9000000 ]
long  long anssiz = 0 ;
// vector <Years> years; 
int main () {
    poww[1]=1;
    for(long long i=2;i<=2805;i++){
        poww[i]=1LL*poww[i-1]*i%MOD;
        //printf("%lld\n",poww[i]);
    }
    
    long long n,m;
    scanf("%lld %lld",&n,&m);
    
    for(long long i=1;i<=n;i++){
        long long t;
        scanf("%lld",&t);
        if(t<=2805){
            Seated ++ ;
            The [sat] .Index = i;
            The [sat] .Val = poww [t];
        }
    }
    
    // a [1] .sum = a [1] .Seal; 
    for ( long  long i = 1 ; i <= helped; i ++ ) {
        a[i].sum=a[i-1].sum+a[i].val;
    }
    
    
    //memset(res,INF,sizeof res);
    for(long long i=1;i<=asiz;i++){
        for(long long j=i;j<=asiz;j++){
            //ans.push_back(aa);
            anssiz++;
            ans[anssiz].len=a[j].index-a[i].index+1;
            ans[anssiz].sum=(a[j].sum-a[i-1].sum)%MOD;
            //res[j-i+1]=max(res[j-i+1],a[j].sum-a[i-1].sum);
        }
    }
    
    sort (year + 1 , year + 1 + anssiz);
    
    years [anssiz] .minlen = years [anssiz] .len;
    
    for(long long i=anssiz-1;i>=1;i--){
        ans[i].minlen=min(ans[i+1].minlen,ans[i].len);
        //printf("*%lld %lld\n",ans[i].sum,ans[i].minlen);
    }
    //for(int i=1;i<=anssiz;i++){
        //printf("*%lld %lld %lld\n",ans[i].sum,ans[i].len,ans[i].minlen);
    //}
    for(long long i=1;i<=m;i++){
        long long k;
        scanf("%lld",&k);
        Years tmp;
        tmp.sum=k;
        long long aa=lower_bound(ans+1,ans+1+anssiz,tmp)-ans;
        //printf("%lld\n",aa);
        if(aa==anssiz+1)printf("-1\n");
        else printf("%lld\n",ans[aa].minlen);
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/isakovsky/p/12034606.html