#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 5e5+5;
const ll MOD = 1e9+7;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
int n, m;
ll dp[105][26];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
vector<int> MIN(n, n+1), MAX(n, n+1);
vector<vector<int>> line_min(n+1), line_max(n+1);
while(m--) {
int a, b;
cin >> a >> b;
if(a < b) line_min[a].pb(a), line_min[b].pb(-a); // menor que o anterior
else line_max[b].pb(b), line_max[a].pb(-b); // maior que o anterior
}
multiset<int> sweep_min, sweep_max;
for(int i = 0; i < n; i++) {
for(auto changes : line_min[i]) {
if(changes > 0) sweep_min.insert(changes);
else sweep_min.erase(sweep_min.find(-changes));
}
if(!sweep_min.empty()) MIN[i] = *sweep_min.rbegin();
}
for(int i = 0; i < n; i++) {
for(auto changes : line_max[i]) {
if(changes > 0) sweep_max.insert(changes);
else sweep_max.erase(sweep_max.find(-changes));
}
if(!sweep_max.empty()) MAX[i] = *sweep_max.rbegin();
}
for(int SET = 0; SET < 26; SET++) dp[0][SET] = 1;
for(int i = 1; i < n; i++) {
for(int letter = 0; letter < 26; letter++) {
for(int last = 0; last < 26; last++) {
if(last < letter)
dp[i][letter] += dp[i-1][last] - dp[MIN[i] - 1][last];
else if(last == letter)
dp[i][letter] += dp[i-1][last];
else
dp[i][letter] += dp[i-1][last] - dp[MAX[i] - 1][last];
}
dp[i][letter] %= MOD;
}
}
ll ans = 0;
for(int letter = 0; letter < 26; letter++)
ans = (ans + dp[n-1][letter])%MOD;
cout << (ans+MOD)%MOD << "\n";
}
# | 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... |