#include<bits/stdc++.h>
using namespace std;
#define foru(i,a,b) for(int i=(a); i<=(b); ++i)
#define ford(i,a,b) for(int i=(a); i>=(b); --i)
#define rep(i,a) for(int i=0; i<(a); ++i)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define bit(s,i) (((s)>>(i))&1)
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define fi first
#define se second
#define ll long long
#define eb emplace_back
#define pb push_back
#define __builtin_popcount __builtin_popcountll
#define _ << " " <<
template <class X, class Y> bool maxi(X &x, Y y){return x<y?x=y,true:false;}
template <class X, class Y> bool mini(X &x, Y y){return x>y?x=y,true:false;}
const int N=505050;
const int mod=1e9+7;
int n,m,A[N],B[N],dp[N][26];
int unsum[26],msum[26],psum[26];
priority_queue<int,vector<int>,greater<int>> una,ma,pa;
vector<ii> seg[N];
inline int add(int a, int b){
a+=b; if(a>=mod) a-=mod;
return a;
}
inline int sub(int a, int b){
a-=b; if(a<0) a+=mod;
return a;
}
void solve(){
cin>>n>>m;
foru(i,1,m){
cin>>A[i]>>B[i];
if(A[i]<B[i]){
seg[A[i]].eb(B[i],1);
} else{
seg[B[i]].eb(A[i],-1);
}
}
ford(i,n,1){
for(auto [r,type]:seg[i]){
if(type==1){
int tmp=0;
while(sz(una) && una.top()<=r){
int id=una.top(); una.pop(); pa.push(id);
int tot=0;
rep(c,26) tot=add(tot,dp[id][c]);
rep(c,26) unsum[c]=sub(unsum[c], sub(tot,dp[id][c]));
tmp=0;
rep(c,26){
psum[c]=add(psum[c],tmp);
tmp=add(tmp,dp[id][c]);
}
}
while(sz(ma) && ma.top()<=r){
int id=ma.top(); ma.pop();
tmp=0;
ford(c,25,0){
msum[c]=sub(msum[c],tmp);
tmp=add(tmp,dp[id][c]);
}
}
} else{
int tmp=0;
while(sz(una) && una.top()<=r){
int id=una.top(); una.pop(); ma.push(id);
int tot=0;
rep(c,26) tot=add(tot,dp[id][c]);
rep(c,26) unsum[c]=sub(unsum[c], sub(tot,dp[id][c]));
tmp=0;
ford(c,25,0){
msum[c]=add(msum[c],tmp);
tmp=add(tmp,dp[id][c]);
}
}
while(sz(pa) && pa.top()<=r){
int id=pa.top(); pa.pop();
tmp=0;
rep(c,26){
psum[c]=sub(psum[c],tmp);
tmp=add(tmp,dp[id][c]);
}
}
}
}
rep(c,26){
dp[i][c]=1;
dp[i][c]=add(dp[i][c],add(unsum[c],add(msum[c],psum[c])));
}
int tot=0;
rep(c,26) tot=add(tot,dp[i][c]);
rep(c,26) unsum[c]=add(unsum[c],sub(tot,dp[i][c]));
una.push(i);
}
int tot=0;
rep(c,26) tot=add(tot,dp[1][c]);
cout<<tot<<'\n';
}
int32_t main(){
#define task "test"
if(fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
int tc=1; //cin>>tc;
foru(i,1,tc){
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
misspelling.cpp: In function 'int32_t main()':
misspelling.cpp:126:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
126 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
misspelling.cpp:127:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
127 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |