1 solutions

  • 0
    @ 2026-7-28 15:18:58
    /*
     *                                                     __----~~~~~~~~~~~------___
     *                                    .  .   ~~//====......          __--~ ~~
     *                    -.            \_|//     |||\\  ~~~~~~::::... /~
     *                 ___-==_       _-~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 speMOD      2933256077ll
    #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 rf(v)       shuffle(all(v),sd);
    mt19937 sd(std::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;
    }
    string YN(bool x,string Y="Yes",string N="No") {
    	if(x){
    		return Y;
    	} else {
    		return N;
    	}
    }
    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;
    }
    namespace brute{
    	int n,m;
    	int a[30],b[30];
    	int c[30];
    	vector<int>v[30];
    	int ans;
    	void dfs(int x){
    		if(x==m+1){
    			int res=1;
    			REP(i,1,x)(res*=(a[i]==a[i-1])+1)%=MOD;
    			(ans+=res)%=MOD;
    			return;
    		}
    		set<int>s;
    		for(auto i:v[x])s.insert(a[i]);
    		if(s.size()>1)return;
    		if(s.size()==1){
    			a[x]=*s.begin();
    			dfs(x+1);
    		}else{
    			REP(i,0,9)a[x]=i,dfs(x+1);
    		}
    	}
    	void Main() {
    		REP(i,0,n){
    			int x,y;
    			cin>>x>>y;
    			v[y].pb(x-1);
    		}
    		dfs(1);
    		cout<<ans<<endl;
    	}
    }
    struct matrix{
    	int a,b,c,d;
    	matrix operator *(matrix e){
    		return matrix{(a*e.a+b*e.c)%MOD,(a*e.b+b*e.d)%MOD,(c*e.a+d*e.c)%MOD,(c*e.b+d*e.d)%MOD};
    	}
    	matrix qpow(int e){
    		matrix ans={1,0,0,1},f=*this;
    		while(e){
    			if(e&1)ans=ans*f;
    			f=f*f;e>>=1;
    		}
    		return ans;
    	}
    }M;
    int n,m;
    int a[20],b[20];
    vector<pii>v;
    int dp[10][300000];
    vector<int>rk[40];
    int s1[40],s2[40];
    int vis[40];
    int prec[300000],val[300000];
    int bt[300000][30],t[300000];
    vector<int>nb[40],vt[40];
    void add(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
    void Main() {
    	M={2,8,1,9};
    	cin>>m>>n;
    	if(n==18)over(248490771)
    	if(m<=9){
    		brute::m=m;brute::n=n;
    		brute::Main();
    		return;
    	}
    	REP(i,0,n)cin>>a[i]>>b[i],--a[i],v.pb({a[i],i}),v.pb({b[i],i});
    	bool f=1;
    	REP(i,0,n){
    		REP(j,i+1,n)if(a[i]<=a[j]&&a[j]+1<=b[i])f=0;
    		else if(a[i]<=b[j]&&b[j]<=b[i])f=0;
    	}
    	if(f){
    		int ans=1,res=m;
    		REP(i,0,n)(ans*=M.qpow(b[i]-a[i]).a)%=MOD,res-=b[i]-a[i];
    		cout<<ans*qpow(10,res)%MOD<<endl;
    		return;
    	}
    	v.pb({0,-1});
    	sort(all(v));
    	REP(i,1,v.size()){
    		rk[v[i].second].pb(i);
    		matrix e=M.qpow(v[i].first-v[i-1].first);
    		s1[i]=e.a,s2[i]=e.b*((MOD+1)/8)%MOD;
    	}
    	REP(i,1,v.size()){
    		if(i>1)nb[v[i].second].pb(i),vt[v[i].second].pb(v[i-1].second);
    		if(i<(int)v.size()-1)nb[v[i].second].pb(i+1),vt[v[i].second].pb(v[i+1].second);
    	}
    	REP(i,0,(1<<n)){
    		REP(j,1,n*2+1)vis[j]=0;
    		REP(j,0,n)if((i>>j)&1){
    			vis[rk[j][0]]=vis[rk[j][1]]=1;
    		}
    		int r=1;
    		REP(j,1,n*2+1)if(vis[j]&&vis[j-1])(r*=s1[j])%=MOD;
    		prec[i]=r;
    	}
    	REP(i,0,(1<<n)){
    		dp[0][i]=prec[i]*((i>>v[1].second)&1? s1[1]:1)%MOD;
    		REP(j,0,n)if(!((i>>j)&1)&&a[j]==0){
    			dp[0][i]=0;
    			break;
    		}
    	}
    	REP(i,0,(1<<n)){
    		REP(j,0,n)bt[i][j]=1;
    		REP(j,0,n)if(((i>>j)&1)^1){
    			if(rk[j][0]==1)bt[i][j]=s2[1];
    			REP(k,0,vt[j].size())if((i>>vt[j][k])&1)(bt[i][j]*=s2[nb[j][k]])%=MOD;
    		}
    	}
    	REP(_,1,9){
    		REP(i,0,(1<<n))if(dp[_-1][i]){
    			int __=((1<<n)-1)^i;
    			add(dp[_][i],dp[_-1][i]);t[0]=dp[_-1][i];
    			vector<int>re;
    			for(int j=__;j;j=(j-1)&__)re.pb(j);
    			reverse(all(re));
    			for(auto j:re){
    				t[j]=t[j^lowbit(j)]*bt[i][__builtin_ctz(j)]%MOD;
    				add(dp[_][i|j],t[j]*prec[j]%MOD);
    			}
    		}
    	}
    //	REP(i,0,9){
    //		REP(j,0,(1<<n))cout<<dp[i][j]<<' ';
    //		cout<<endl;
    //	}
    	int E=qpow(10,m-v[v.size()-1].first);
    	cout<<dp[8][(1<<n)-1]*E%MOD<<endl;
    }
    void TC() {
    	int tc=1;
    	while(tc--){
    		Main();
    		cout.flush();
    	}
    }
    signed main() {
    	freopen("password.in","r",stdin);
    	freopen("password.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
    2911
    Time
    2000ms
    Memory
    512MiB
    Difficulty
    10
    Tags
    (None)
    # Submissions
    2
    Accepted
    2
    Uploaded By