이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,x,n) for(int i=x;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3x2WzQf ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e
//snuke's mod int
template <ll mod>
struct modint{
ll x; // typedef long long ll;
modint(ll x=0):x((x%mod+mod)%mod){}
modint operator-()const{return modint(-x);}
modint& operator+=(const modint a){if((x+=a.x)>=mod) x-=mod; return *this;}
modint& operator-=(const modint a){if((x+=mod-a.x)>=mod) x-=mod; return *this;}
modint& operator*=(const modint a){(x*=a.x)%=mod; return *this;}
modint operator+(const modint a)const{modint res(*this); return res+=a;}
modint operator-(const modint a)const{modint res(*this); return res-=a;}
modint operator*(const modint a)const{modint res(*this); return res*=a;}
modint pow(ll n)const{
modint res=1,x(*this);
while(n){
if(n&1)res*=x;
x*=x;
n>>=1;
}
return res;
}
modint inv()const{return pow(mod-2);}
};
using mint=modint<1000'000'007>;
mint dp[30][2];
signed main(){
_3x2WzQf;
int n,m;
cin>>n>>m;
vec(vi) qry(n,vi(2,-1));
rep(i,m){
int l,r;
cin>>l>>r;
l-=1,r-=1;
bool type=0;
if(l>r){
swap(l,r);
type=1;
}
qry[l][type]=max(qry[l][type],r);
}
using tup=tuple<int,int,ll>;
deque<tup> dq0,dq1;
per(ch,26){
dp[ch][0]=1;
}
per(i,n-1){
int r0=qry[i][0];
int r1=qry[i][1];
vec(vec(mint)) fdp(26,vec(mint)(2));
rep(x,26){
rep(y,26){
if(x==y) continue;
if(r0!=-1 and y>x) continue;
if(r1!=-1 and y<x) continue;
rep(t,2){
int nt=(y>x?1:0);
fdp[y][nt]+=dp[x][t];
}
}
}
rep(y,26){
rep(nt,2){
if(nt) dq1.pb({i,y,fdp[y][nt].x});
else dq0.pb({i,y,fdp[y][nt].x});
dp[y][nt]+=fdp[y][nt];
}
}
while(sz(dq1)){
auto &[j,ch,val]=dq1.back();
if(j<r0){
dp[ch][1]-=mint(val);
dq1.pop_back();
}else{
break;
}
}
while(sz(dq0)){
auto &[j,ch,val]=dq0.back();
if(j<r1){
dp[ch][0]-=mint(val);
dq0.pop_back();
}else{
break;
}
}
}
mint ans=0;
rep(x,26){
rep(t,2){
ans+=dp[x][t];
}
}
print(ans.x);
//
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |