이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
long long mod = 1000000007;
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//freopen("input.txt","r",stdin);
//freopen("outout.txt","w",stdout);
int n,m;
cin>>n>>m;
vector<pair<int,int>> rng[n+1];
for(int i = 0;i<m;i++){
int a,b;cin>>a>>b;
a--;b--;
if(a<b){
rng[a+1].push_back({b+1,0});
}else{
rng[b+1].push_back({a+1,1});
}
}
int dp[n+1][26];
memset(dp,0,sizeof dp);
long long lol1[26] = {0},lol2[26] = {0};
for(int i = 0;i<26;i++)dp[n][i] = 1;
set<int> s1,s2;
s1.insert(n);
s2.insert(n);
for(int i = 0;i<26;i++){
lol1[i]+=dp[n][i];
lol2[i]+=dp[n][i];
}
for(int i = n-1;i>=0;i--){
for(auto j:rng[i]){
if(j.second==0){
while(!s1.empty()&&(*s1.begin())<=j.first){
for(int e =0;e<26;e++){
lol1[e]-=dp[(*s1.begin())][e];
lol1[e]%=mod;lol1[e]+=mod;lol1[e]%=mod;
}
s1.erase(s1.begin());
}
}else{
while(!s2.empty()&&(*s2.begin())<=j.first){
for(int e =0;e<26;e++){
lol2[e]-=dp[(*s2.begin())][e];
lol2[e]%=mod;lol2[e]+=mod;lol2[e]%=mod;
}
s2.erase(s2.begin());
}
}
}
long long nah =0;
for(int j = 0;j<26;j++){
dp[i][j]+=nah;dp[i][j]%=mod;
nah+=lol1[j];nah%=mod;
}
nah = 0;
for(int j = 25;j>=0;j--){
dp[i][j]+=nah;dp[i][j]%=mod;
nah+=lol2[j];nah%=mod;
}
s1.insert(i);
s2.insert(i);
for(int j = 0;j<26;j++){
dp[i][j]++;dp[i][j]%=mod;
lol1[j]+=dp[i][j];lol1[j]%=mod;
lol2[j]+=dp[i][j];lol2[j]%=mod;
}
}
long long nah = 0;
for(int i = 0;i<26;i++){
nah+=dp[1][i];
nah%=mod;
}
cout<<nah<<endl;
}
# | 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... |