이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9+7;
int n,m;
int dp[500005][30];
int pref[500005][30];
vector<pair<int,int>> baga[500005],scoate[500005];
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>m;
int a,b;
for(int i=1;i<=m;i++)
{
cin>>a>>b;
if(a==b)
continue;
if(a<b)
{
baga[a+1].push_back({b,0});
scoate[b].push_back({a+1,0});
}
else
{
swap(a,b);
baga[a+1].push_back({b,1});
scoate[b].push_back({a+1,1});
}
}
for(int c=0;c<26;c++)
dp[1][c]=pref[1][c]=1;
int rez=26;
set<pair<int,int>> s[2];
for(int i=2;i<=n;i++)
{
for(auto [ri,tip]:baga[i])
s[tip].insert({i,ri});
int p0=1,p1=1;
if(!s[0].empty()) p0 = (*prev(s[0].end())).first;
if(!s[1].empty()) p1 = (*prev(s[1].end())).first;
for(int c=0;c<26;c++)
{
for(int u=c+1;u<26;u++)
dp[i][c] += pref[i-1][u]-pref[p1-1][u]+MOD;
for(int u=0;u<c;u++)
dp[i][c] += pref[i-1][u]-pref[p0-1][u]+MOD;
dp[i][c]%=MOD;
pref[i][c] = (pref[i-1][c] + dp[i][c])%MOD;
rez = (rez + dp[i][c])%MOD;
}
for(auto [le,tip]:scoate[i])
s[tip].erase({le,i});
}
cout<<rez;
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... |