Submission #1136092

#TimeUsernameProblemLanguageResultExecution timeMemory
1136092imarnMisspelling (JOI22_misspelling)C++20
100 / 100
406 ms172116 KiB
#include<bits/stdc++.h> #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define plx pair<ll,int> #define f first #define s second #define pb push_back #define all(x) x.begin(),x.end() #define vi vector<int> #define vvi vector<vi> #define pp pair<ll,int> #define ub(x,i) upper_bound(all(x),i)-x.begin() using namespace std; const int mxn=5e5+5,inf=1e9+7; vector<int>up[mxn],dw[mxn]; ll dp[mxn][27]{0}; ll pu[27]{0},pd[27]{0}; multiset<int>um,dm; int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n,m;cin>>n>>m; for(int i=1;i<=m;i++){ int a,b;cin>>a>>b; if(a<b)up[a].pb(b); else dw[b].pb(a); } for(int i=1;i<=26;i++)dp[n][i]=1; for(int i=n-1;i>=1;i--){ um.insert(i+1);dm.insert(i+1); for(int j=1;j<=26;j++)pu[j]+=dp[i+1][j],pd[j]+=dp[i+1][j],pu[j]%=inf,pd[j]%=inf; for(auto r : up[i]){ while(!um.empty()&&*um.begin()<=r){ for(int j=1;j<=26;j++)pu[j]-=dp[*um.begin()][j],pu[j]%=inf; um.erase(um.begin()); } } for(auto r : dw[i]){ while(!dm.empty()&&*dm.begin()<=r){ for(int j=1;j<=26;j++)pd[j]-=dp[*dm.begin()][j],pd[j]%=inf; dm.erase(dm.begin()); } } ll u=0; for(int j=26;j>=1;j--){ dp[i][j]=u+1; u+=pu[j];u%=inf; }u=0; for(int j=1;j<=26;j++){ dp[i][j]+=u;dp[i][j]%=inf; u+=pd[j];u%=inf; } }ll ans=0; for(int i=1;i<=26;i++)ans+=dp[1][i],ans%=inf; cout<<(ans%inf+inf)%inf; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...