이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
const int maxn = 5e5+10;
int dp[maxn][26],sum[maxn][26];
pq <pii> q1,q2;
vector <int> r1[maxn],r2[maxn];
int main() {
// freopen("input.txt","r",stdin);
std::ios::sync_with_stdio(false);cin.tie(0);
int n,m;
cin>>n>>m;
rep(i,0,m) {
int u,v;
cin>>u>>v;
if (u<v) r1[u+1].pb(v);
else r2[v+1].pb(u);
}
q1.push({1,n}),q2.push({1,n});
rep(i,0,26) dp[1][i] = sum[1][i] = 1;
rep(i,2,n+1) {
for (auto it:r1[i]) q1.push({i,it});
for (auto it:r2[i]) q2.push({i,it});
while (q1.top().se<i) q1.pop();
while (q2.top().se<i) q2.pop();
int cur1 = q1.top().fi, cur2 = q2.top().fi;
// debug(cur1),debug(cur2);
int cur = max(cur1,cur2);
int tmp = 0;
if(cur!=i) {
rep(j,0,26) inc(tmp,(sum[i-1][j] - sum[cur-1][j] + mod)%mod);
rep(j,0,26) inc(dp[i][j],tmp),inc(dp[i][j],(-sum[i-1][j] + sum[cur-1][j] + mod)%mod);
}
if (cur1<cur2) { //larger
tmp = (sum[cur2-1][0] - sum[cur1-1][0] + mod)%mod;
rep(j,1,26) {
inc(dp[i][j],tmp);
inc(tmp,(sum[cur2-1][j] - sum[cur1-1][j] + mod)%mod);
}
}
else if (cur2<cur1){ //smaller
tmp = (sum[cur1-1][25] - sum[cur2-1][25] + mod)%mod;
for (int j = 24;j>=0;j--) {
inc(dp[i][j],tmp);
inc(tmp,(sum[cur1-1][j] - sum[cur2-1][j] + mod)%mod);
}
}
rep(j,0,26) {
sum[i][j] = (sum[i-1][j] + dp[i][j])%mod;
//cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
}
}
int ans = 0;
rep(i,0,26) inc(ans,sum[n][i]);
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... |