이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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&&maxl!=0){
for(long long j=0;j<K;j++){
ps[i][j]=ps[i-1][j];
}
continue;
}
if(maxl==maxr){
for(int j=1;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 |
---|
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... |