This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
typedef long long llong;
const int MAXN = 500000 + 10;
const int ALPHABET = 26;
const int MOD = 1e9 + 7;
int n, m;
int l[MAXN];
int r[MAXN];
int type[MAXN];
int dp[MAXN][ALPHABET];
bool bl[MAXN][ALPHABET];
std::vector <int> begin[MAXN];
std::vector <int> end[MAXN];
int f(int pos, int letter)
{
if (bl[pos][letter])
{
return dp[pos][letter];
}
int cntOne = 0;
int cntTwo = 0;
bl[pos][letter] = true;
dp[pos][letter] = 1;
for (int i = pos ; i < n ; ++i)
{
for (const int &j : begin[i])
{
cntOne += (type[j] == 1);
cntTwo += (type[j] == 2);
}
for (const int &j : end[i])
{
if (l[j] < pos)
{
continue;
}
cntOne -= (type[j] == 1);
cntTwo -= (type[j] == 2);
}
if (cntOne == 0)
{
for (int j = letter + 1 ; j < 26 ; ++j)
{
dp[pos][letter] += f(i + 1, j);
if (dp[pos][letter] >= MOD) dp[pos][letter] -= MOD;
}
}
if (cntTwo == 0)
{
for (int j = letter - 1 ; j >= 0 ; --j)
{
dp[pos][letter] += f(i + 1, j);
if (dp[pos][letter] >= MOD) dp[pos][letter] -= MOD;
}
}
}
return dp[pos][letter];
}
void solve()
{
int sum = 0;
for (int i = 0 ; i < 26 ; ++i)
{
sum += f(1, i);
if (sum >= MOD) sum -= MOD;
}
std::cout << sum << '\n';
}
void input()
{
std::cin >> n >> m;
for (int i = 1 ; i <= m ; ++i)
{
std::cin >> l[i] >> r[i];
type[i] = 1;
if (l[i] > r[i])
{
std::swap(l[i], r[i]);
type[i] = 2;
}
begin[l[i]].push_back(i);
end[r[i]].push_back(i);
}
}
void fastIOI()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIOI();
input();
solve();
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... |