이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Arayi
#include <bits/stdc++.h>
#define fr first
#define sc second
#define MP make_pair
#define ad push_back
#define PB push_back
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define lli long long int
#define y1 arayikhalatyan
#define j1 jigglypuff
#define ld long double
#define itn int
#define pir pair<int, int>
#define all(x) (x).begin(), (x).end()
#define str string
#define enl endl
#define en endl
#define cd complex<long double>
#define vcd vector<cd>
#define vii vector<int>
#define vlli vector<lli>
using namespace std;
lli gcd(lli a, lli b) { return (b == 0LL ? a : gcd(b, a % b)); }
ld dist(ld x, ld y1, ld x2, ld y2)
{
return sqrt((x - x2) * (x - x2) + (y1 - y2) * (y1 - y2));
}
lli S(lli a)
{
return (a * (a + 1LL)) / 2;
}
mt19937 rnd(363542);
char vow[] = {'a', 'e', 'i', 'o', 'u'};
int dx[] = {0, -1, 0, 1, -1, -1, 1, 1, 0};
int dy[] = {-1, 0, 1, 0, -1, 1, -1, 1, 0};
char dc[] = {'R', 'D', 'L', 'U'};
const int N = 5e5 + 20;
const lli mod = 1e9 + 7;
const ld pi = acos(-1);
const ld e = 1e-13;
const int T = 128;
lli bp(lli a, lli b = mod - 2LL)
{
lli ret = 1;
while (b)
{
if (b & 1)
ret *= a, ret %= mod;
a *= a;
a %= mod;
b >>= 1;
}
return ret;
}
ostream &operator<<(ostream &c, pir a)
{
c << a.fr << " " << a.sc;
return c;
}
template <class T>
void maxi(T &a, T b)
{
a = max(a, b);
}
template <class T>
void mini(T &a, T b)
{
a = min(a, b);
}
int n, m;
lli dp[N][30][3], pr[N][30][3], p[N][30][3];
int l[N], r[N];
vii fp[N], fp1[N];
bool col[N];
priority_queue<pair<int, int>> q, q1;
void f(int i1)
{
for (auto p : fp[i1])
{
if (p > 0)
q.push(MP(i1, p));
else
col[-p] = 1;
}
for (auto p : fp1[i1])
{
if (p > 0)
q1.push(MP(i1, p));
else
col[-p] = 1;
}
while (!q.empty() && col[q.top().sc])
q.pop();
while (!q1.empty() && col[q1.top().sc])
q1.pop();
}
int main()
{
fastio;
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
cin >> l[i] >> r[i];
l[i]--, r[i]--;
if (l[i] < r[i])
{
fp[l[i]].ad(i);
fp[r[i]].ad(-i);
}
else
{
fp1[r[i]].ad(i);
fp1[l[i]].ad(-i);
}
}
for (int i = 0; i < 26; i++)
{
dp[0][i][1] = 1;
pr[0][i][1] = i + 1;
}
f(0);
for (int i = 1; i < n; i++)
{
for (int j = 0; j < 26; j++)
{
dp[i][j][1] = dp[i - 1][j][0] + dp[i - 1][j][1] + dp[i - 1][j][2];
dp[i][j][1] %= mod;
}
int i1;
if (!q1.empty())
i1 = q1.top().fr;
else
i1 = -1;
for (int j = 0; j < 26; j++)
{
if (i1 == -1)
dp[i][j][0] += 25 - j;
lli sm = pr[i - 1][25][0] - pr[i - 1][j][0] + mod + mod;
if (i1 != -1)
sm -= pr[i1][25][0] - pr[i1][j][0];
dp[i][j][0] += sm;
sm = pr[i - 1][25][2] - pr[i - 1][j][2] + mod + mod;
if (i1 != -1)
sm -= pr[i1][25][2] - pr[i1][j][2];
dp[i][j][0] += sm;
dp[i][j][0] %= mod;
}
if (!q.empty())
i1 = q.top().fr;
else
i1 = -1;
for (int j = 1; j < 26; j++)
{
//cout << i1 << endl;
if (i1 == -1)
dp[i][j][2] += j;
lli sm = pr[i - 1][j - 1][0] + mod;
if (i1 != -1)
sm -= pr[i1][j - 1][0];
dp[i][j][2] += sm;
sm = pr[i - 1][j - 1][2] + mod;
if (i1 != -1)
sm -= pr[i1][j - 1][2];
dp[i][j][2] += sm;
dp[i][j][2] %= mod;
}
for (int j = 0; j < 26; j++)
{
for (auto k : {0, 1, 2})
{
pr[i][j][k] = dp[i][j][k] + pr[i - 1][j][k] + mod + mod;
if (j)
pr[i][j][k] += pr[i][j - 1][k] - pr[i - 1][j - 1][k];
pr[i][j][k] %= mod;
}
}
f(i);
}
lli sum = 0;
for (int i = 0; i < 26; i++)
for (auto k : {0, 1, 2})
sum += dp[n - 1][i][k], sum %= mod;
cout << sum << endl;
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... |