#include<bits/stdc++.h>
using namespace std;
const long long maxn=500000+10,K=27,mod=1000000007;
long long ps[maxn][K],n,m;
vector<pair<long long,long long>>allq[maxn];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(long long i=0;i<m;i++){
long long u,v;
cin>>u>>v;
if(u>v){
swap(u,v);
allq[u].push_back(make_pair(v,1));
}
else{
allq[u].push_back(make_pair(v,0));
}
}
for(long long i=1;i<K;i++){
ps[1][i]=i;
}
set<pair<long long,long long>>stl,str;
for(long long i=2;i<=n;i++){
for(auto x:allq[i-1]){
if(x.second==1){
str.insert(make_pair(i-1,x.first));
}
else{
stl.insert(make_pair(i-1,x.first));
}
}
while((long long)str.size()>0&&(*str.rbegin()).second<i){
str.erase(*str.rbegin());
}
while((long long)stl.size()>0&&(*stl.rbegin()).second<i){
stl.erase(*stl.rbegin());
}
long long maxl=0,maxr=0;
if((long long)str.size()>0){
maxr=(*str.rbegin()).first;
}
if((long long)stl.size()>0){
maxl=(*stl.rbegin()).first;
}
//cout<<maxl<<" "<<maxr<<" "<<i<<endl;
if(maxl==maxr){
for(long long j=0;j<K;j++){
ps[i][j]=ps[i-1][j];
}
continue;
}
if(maxl==maxr){
for(int j=0;j<K;j++){
ps[i][j]=ps[i-1][K-1]-ps[i-1][j]+ps[i-1][j-1];
ps[i][j]+=mod*10;
ps[i][j]%=mod;
}
for(long long j=1;j<K;j++){
ps[i][j]+=ps[i][j-1];
ps[i][j]+=mod*10;
ps[i][j]%=mod;
}
for(long long j=1;j<K;j++){
ps[i][j]+=ps[i-1][j];
ps[i][j]+=mod*10;
ps[i][j]%=mod;
}
continue;
}
if(maxl>maxr){
for(long long j=1;j<K;j++){
ps[i][j]=ps[i-1][K-1]-ps[maxl][K-1]-(ps[i-1][j]-ps[i-1][j-1]-(ps[maxl][j]-ps[maxl][j-1]));
}
for(long long j=1;j<K;j++){
ps[i][j]+=ps[maxl][K-1]-ps[maxl][j]-(ps[maxr][K-1]-ps[maxr][j]);
}
for(long long j=1;j<K;j++){
ps[i][j]+=ps[i][j-1];
ps[i][j]+=mod*10;
ps[i][j]%=mod;
}
for(long long j=1;j<K;j++){
ps[i][j]+=ps[i-1][j];
ps[i][j]+=mod*10;
ps[i][j]%=mod;
}
}
else{
swap(maxl,maxr);
for(long long j=1;j<K;j++){
ps[i][j]=ps[i-1][K-1]-ps[maxl][K-1]-(ps[i-1][j]-ps[i-1][j-1]-(ps[maxl][j]-ps[maxl][j-1]));
}
for(long long j=1;j<K;j++){
// cout<<j<<" "<<maxr<<" "<<ps[i-1][j-1]<<" "<<ps[maxr][j-1]<<endl;
ps[i][j]+=ps[maxl][j-1]-(ps[maxr][j-1]);
}
for(long long j=1;j<K;j++){
ps[i][j]+=ps[i][j-1];
ps[i][j]+=mod*10;
ps[i][j]%=mod;
}
for(long long j=1;j<K;j++){
ps[i][j]+=ps[i-1][j];
ps[i][j]+=mod*10;
ps[i][j]%=mod;
}
}
}
// for(long long i=1;i<=n;i++){
// for(long long j=1;j<K;j++){
// cout<<ps[i][j]<<" ";
// }
// cout<<"\n";
// }
cout<<ps[n][K-1]<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
Output is correct |
2 |
Correct |
3 ms |
12892 KB |
Output is correct |
3 |
Correct |
3 ms |
12892 KB |
Output is correct |
4 |
Correct |
3 ms |
12892 KB |
Output is correct |
5 |
Correct |
3 ms |
12904 KB |
Output is correct |
6 |
Correct |
3 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12892 KB |
Output is correct |
8 |
Correct |
2 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
12892 KB |
Output is correct |
10 |
Incorrect |
3 ms |
12912 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
Output is correct |
2 |
Correct |
3 ms |
12892 KB |
Output is correct |
3 |
Correct |
3 ms |
12892 KB |
Output is correct |
4 |
Correct |
3 ms |
12892 KB |
Output is correct |
5 |
Correct |
3 ms |
12904 KB |
Output is correct |
6 |
Correct |
3 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12892 KB |
Output is correct |
8 |
Correct |
2 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
12892 KB |
Output is correct |
10 |
Incorrect |
3 ms |
12912 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12888 KB |
Output is correct |
2 |
Correct |
3 ms |
12892 KB |
Output is correct |
3 |
Correct |
3 ms |
12888 KB |
Output is correct |
4 |
Correct |
3 ms |
12892 KB |
Output is correct |
5 |
Correct |
293 ms |
157520 KB |
Output is correct |
6 |
Correct |
301 ms |
156748 KB |
Output is correct |
7 |
Correct |
293 ms |
158032 KB |
Output is correct |
8 |
Correct |
304 ms |
160940 KB |
Output is correct |
9 |
Correct |
287 ms |
158040 KB |
Output is correct |
10 |
Correct |
13 ms |
18776 KB |
Output is correct |
11 |
Correct |
2 ms |
12892 KB |
Output is correct |
12 |
Correct |
2 ms |
12892 KB |
Output is correct |
13 |
Correct |
322 ms |
162164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
Output is correct |
2 |
Correct |
3 ms |
12892 KB |
Output is correct |
3 |
Correct |
3 ms |
12892 KB |
Output is correct |
4 |
Correct |
3 ms |
12892 KB |
Output is correct |
5 |
Correct |
3 ms |
12904 KB |
Output is correct |
6 |
Correct |
3 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12892 KB |
Output is correct |
8 |
Correct |
2 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
12892 KB |
Output is correct |
10 |
Incorrect |
3 ms |
12912 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
Output is correct |
2 |
Correct |
3 ms |
12892 KB |
Output is correct |
3 |
Correct |
3 ms |
12892 KB |
Output is correct |
4 |
Correct |
3 ms |
12892 KB |
Output is correct |
5 |
Correct |
3 ms |
12904 KB |
Output is correct |
6 |
Correct |
3 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12892 KB |
Output is correct |
8 |
Correct |
2 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
12892 KB |
Output is correct |
10 |
Incorrect |
3 ms |
12912 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |