This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define isz(x) ((int)x.size())
#define sumof(x) accumulate(all(x), 0ll)
const int N=5e5+10, mod=1e9+7;
int n, m;
int f[N][26], ff[N][26];
vector<pair<int, int>> g[N];
int pf[2][26];
int add(int x, int y){
return x+y>=mod?x+y-mod:x+y;
}
int sub(int x, int y){
return x<y?x-y+mod:x-y;
}
void solve(){
cin >> n >> m;
for (int i=1; i<=m; ++i){
int u, v; cin >> u >> v;
if (u<v){
g[u].emplace_back(v, 0);
}else{
g[v].emplace_back(u, 1);
}
}
vector<set<int>> pos(2);
for (int i=1; i<=n; ++i) pos[0].insert(i);
pos[1]=pos[0];
for (int i=0; i<26; ++i) f[n][i]=1, ff[n][i]=i+1;
for (int i=0; i<26; ++i) pf[0][i]=pf[1][i]=i+1;
for (int i=n-1; i>=1; --i){
for (auto &j:g[i]){
int l=i+1, r=j.first, k=j.second;
for (auto it=pos[k^1].lower_bound(l); it!=pos[k^1].end() && (*it)<=r; it=pos[k^1].erase(it)){
for (int t=0; t<26; ++t) pf[k^1][t]=sub(pf[k^1][t], ff[*it][t]);
}
}
for (int j=0; j<26; ++j){
f[i][j]=1;
if (j) f[i][j]=add(f[i][j], pf[0][j-1]);
f[i][j]=add(f[i][j], sub(pf[1][25], pf[1][j]));
}
for (int j=0; j<26; ++j){
ff[i][j]=f[i][j];
if (j) ff[i][j]=add(ff[i][j], ff[i][j-1]);
pf[0][j]=add(pf[0][j], ff[i][j]);
pf[1][j]=add(pf[1][j], ff[i][j]);
}
}
int ans=0;
for (int j=0; j<26; ++j) ans=add(ans, f[1][j]);
cout << ans;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int ntests=1;
// cin >> ntests;
for (int i=1; i<=ntests; ++i) solve();
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... |