이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
const int MAXN = 5e5+5,MOD = 1e9+7;
int dp[26][MAXN],pre[26][MAXN],add[2][MAXN];
vector<int>rem[2][MAXN];
int main()
{
int n,m;
cin>>n>>m;
for(int i=0;i<m;i++){
int l,r;
cin>>l>>r;
if(r > l){
//red,>
add[0][l] = max(add[0][l],r);
}else{
//blue,<
add[1][r] = max(add[1][r],l);
}
}
for(int i=0;i<26;i++)dp[i][1] = pre[i][1] = 1;
multiset<int,greater<int>>blue,red;
for(int i=1;i<=n;i++){
for(int x:rem[0][i])red.erase(red.find(x));
for(int x:rem[1][i])blue.erase(blue.find(x));
int b = 0,r = 0;
if(!red.empty())r = *red.begin();
if(!blue.empty())b = *blue.begin();
//r+1 to i-1
//b+1 to i-1
// cout<<i<<" "<<r<<" "<<b<<'\n';
int sum = 0;
for(int k=0;k<26;k++){
dp[k][i] += sum;
if(dp[k][i]>=MOD)dp[k][i]-=MOD;
sum += pre[k][i-1] - pre[k][r];
if(sum>=MOD)sum-=MOD;
}
sum = 0;
for(int k=25;k>=0;k--){
dp[k][i] += sum;
if(dp[k][i]>=MOD)dp[k][i]-=MOD;
sum += pre[k][i-1] - pre[k][b];
if(sum>=MOD)sum-=MOD;
}
for(int k=0;k<26;k++){
pre[k][i] = dp[k][i] + pre[k][i-1];
if(pre[k][i]>=MOD)pre[k][i]-=MOD;
}
if(add[0][i]){
red.insert(i);
rem[0][add[0][i]+1].pb(i);
}
if(add[1][i]){
blue.insert(i);
rem[1][add[1][i]+1].pb(i);
}
}
int ans = 0;
for(int i=1;i<=n;i++){
for(int j=0;j<26;j++){
ans+=dp[j][i];
if(ans>=MOD)ans-=MOD;
}
}
cout<<ans<<'\n';
}
# | 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... |