1 solutions

  • 0
    @ 2026-7-29 11:08:35
    /*
     *                                                     __----~~~~~~~~~~~------___
     *                                    .  .   ~~//====......          __--~ ~~
     *                    -.            \_|//     |||\\  ~~~~~~::::... /~
     *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
     *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
     *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
     *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
     *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
     *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
     *           '         ~-|      /|    |-~\~~       __--~~
     *                       |-~~-_/ |    |   ~\_   _-~            /\
     *                            /  \     \__   \/~                \__
     *                        _--~ _/ | .-~~____--~-/                  ~~==.
     *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
     *                                  -_     ~\      ~~---l__i__i__i--~~_/
     *                                  _-~-__   ~)  \--______________--~~
     *                                //.-~~~-~_--~- |-------~~~~~~~~
     *                                       //.-~~~--\
     *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     *
     *                                  ?                   BUG
     */
    
    /*
     * @Description: I want to be the weakest vegetable in the world!
     * @Author: I.Z.
    */
    #include<bits/stdc++.h>
    using namespace std;
    #define MOD         1000000007
    #define int         long long
    #define pii         pair<int,int>
    #define all(v)      v.begin(),v.end()
    #define pb          push_back
    #define REP(i,b,e)  for(int i=(b);i<(int)(e);++i)
    #define over(x)     {cout<<(x)<<endl;return;}
    #define lowbit(x)   ((x)&(-(x)))
    #define cntbit(x)   __builtin_popcount(x)
    #define deal(v)     sort(all(v));v.erase(unique(v.begin(),v.end()),v.end())
    #define lbound(v,x) lower_bound(all(v),x)-v.begin()
    mt19937 sd(random_device{}());
    int qpow(int a,int b,int m=MOD,int res=1){
    	a%=m;
    	while(b>0)res=(b&1)?(res*a%m):(res),a=a*a%m,b>>=1;
    	return res;
    }
    int exgcd(int x,int y,int &a,int &b){
    	if(y==0){
    		a=1;b=0;
    		return x;
    	}
    	int d=exgcd(y,x%y,a,b);
    	int z=b;
    	b=a-b*(x/y);
    	a=z;
    	return d;
    }
    int _x_,_y_;
    inline int inverse(int x,int y=MOD){
    	exgcd(x,y,_x_,_y_);
    	return (_x_+y)%y;
    }
    int fac[2000005],inv[2000005];
    void init(int n){
    	fac[0]=inv[0]=1;
    	REP(i,1,n+1)fac[i]=fac[i-1]*i%MOD;
    	inv[n]=qpow(fac[n],MOD-2);
    	for(int i=n-1;i>=1;--i)inv[i]=inv[i+1]*(i+1)%MOD;
    }
    int binom(int x,int y){
    	return x<y||y<0? 0:fac[x]*inv[y]%MOD*inv[x-y]%MOD;
    }
    signed n;
    signed a[20000005];
    signed f[20000005];
    namespace Gen
    {
    	unsigned z1, z2, z3, z4, b;
    	unsigned rand_()
    	{
    		b = ((z1 << 6) ^ z1) >> 13;
    		z1 = ((z1 & 4294967294U) << 18) ^ b;
     		b = ((z2 << 2) ^ z2) >> 27;
    		z2 = ((z2 & 4294967288U) << 2) ^ b;
    		b = ((z3 << 13) ^ z3) >> 21;
    		z3 = ((z3 & 4294967280U) << 7) ^ b;
    		b = ((z4 << 3) ^ z4) >> 12;
    		z4 = ((z4 & 4294967168U) << 13) ^ b;
    		return (z1 ^ z2 ^ z3 ^ z4);
    	}
    	void srand_(int n, int v)
    	{
    		scanf("%u%u%u%u", &z1, &z2, &z3, &z4);
    		for(int i = 1; i <= n; i++) a[i-1] = rand_() % v + 1;
    	}
    }
    signed v;
    signed s[20000005],st[20000005],tp;
    int g[20000005];
    void Main() {
    	scanf("%d%d",&n,&v);
    	Gen::srand_(n,v);
    	f[0]=1;s[1]=-1;
    	st[tp++]=-1;
    	#define sum(l,r) (s[(r)+1]-s[l])
    	int csum=0;
    	REP(i,0,n){
    		while(tp>1&&a[st[tp-1]]>a[i]){
    			--tp;
    			(csum-=g[st[tp]])%=MOD;
    		}
    		(csum+=g[i]=(sum(st[tp-1]+1,i)*1ll*a[i]))%=MOD;
    		st[tp++]=i;
    		f[i+1]=csum;
    		if(i%2==0)f[i+1]=-f[i+1];
    		s[i+2]=(s[i+1]+(i&1? -f[i+1]:f[i+1]))%MOD;
    	}
    	over((f[n]+MOD)%MOD)
    }
    void TC() {
        int tc=1;
    	while(tc--){
    		Main();
    		cout.flush();
    	}
    }
    signed main() {
    	freopen("violence.in","r",stdin);
    	freopen("violence.out","w",stdout);
    	return cin.tie(0),cout.tie(0),ios::sync_with_stdio(0),TC(),0;
    }
    /*
    1. CLEAR the arrays (ESPECIALLY multitests)
    2. DELETE useless output
     */
    
    
    • 1

    Information

    ID
    3079
    Time
    1000ms
    Memory
    512MiB
    Difficulty
    10
    Tags
    (None)
    # Submissions
    1
    Accepted
    1
    Uploaded By