이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;
const int N=500007;
ll DP[N][26];
ll cnt[26];
vector<int>poc1[N],kon1[N];
vector<int>poc2[N],kon2[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m,a,b;
cin>>n>>m;
for(int i=0;i<m;i++)
{
cin>>a>>b;
if(a<b)
{
poc1[a].pb(a);
kon1[b].pb(a);
}
else
{
poc2[b].pb(b);
kon2[a].pb(b);
}
}
for(int i=0;i<26;i++) DP[1][i]=1;
multiset<int>Q1,Q2;
for(auto x:poc1[1]) Q1.insert(x);
for(auto x:poc2[1]) Q2.insert(x);
for(int i=2;i<=n;i++)
{
int x=0,y=0;
if(sz(Q1)>0) x=*--Q1.end();
if(sz(Q2)>0) y=*--Q2.end();
memset(cnt,0,sizeof cnt);
//mniejszy
ll act=0;
for(int j=25;j>=0;j--)
{
cnt[j]=act;
act=(act+DP[i-1][j]-DP[y][j]+mod)%mod;
}
//wiekszy
act=0;
for(int j=0;j<26;j++)
{
cnt[j]=(cnt[j]+act)%mod;
act=(act+DP[i-1][j]-DP[x][j]+mod)%mod;
}
for(int j=0;j<26;j++) DP[i][j]=(DP[i-1][j]+cnt[j])%mod;
for(auto x:kon1[i]) Q1.erase(Q1.find(x));
for(auto x:kon2[i]) Q2.erase(Q2.find(x));
for(auto x:poc1[i]) Q1.insert(x);
for(auto x:poc2[i]) Q2.insert(x);
}
ll ans=0;
for(int i=0;i<26;i++) ans=(ans+DP[n][i])%mod;
cout<<ans;
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... |