Submission #545114

#TimeUsernameProblemLanguageResultExecution timeMemory
545114leakedMisspelling (JOI22_misspelling)C++14
100 / 100
2440 ms113964 KiB
#include <bits/stdc++.h> #define f first #define s second #define m_p make_pair #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define vec vector #define pb push_back #define sz(x) (int)(x).size() #define pw(x) (1LL<<(x)) #define fast_resp ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef long double ld; typedef pair<int,ll> pil; template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);} template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);} const int M=1e9+7; const int N=5e5+1; void add(int &a,int b){ a+=b; if(a>=M) a-=M; else if(a<0) a+=M; } int mult(int a,int b){ return 1ll*a*b%M; } int dp[N][26]; set<pii> st[2]; vec<array<int,3>> del[N]; vec<array<int,3>> addt[N]; //set<int> st[2]; signed main(){ fast_resp; int n,m; cin>>n>>m; for(int i=0;i<m;i++){ int l,r; cin>>l>>r;--l;--r; if(l<r){ ++l;addt[l].pb({0,l,i}),del[r+1].pb({0,l,i}); } else{ if(l==r) continue; swap(l,r);++l; addt[l].pb({1,l,i}),del[r+1].pb({1,l,i}); } } for(int i=0;i<26;i++) dp[1][i]=1; for(int i=1;i<n;i++){ for(auto &z : addt[i]) st[z[0]].insert({z[1],z[2]}); for(auto &z : del[i]) st[z[0]].erase({z[1],z[2]}); for(int j=0;j<26;j++){ for(int k=0;k<26;k++){ add(dp[i+1][k],dp[i][j]); } } if(sz(st[0])){ for(int j=0;j<26;j++){ for(int k=j+1;k<26;k++){ add(dp[i+1][j],-dp[st[0].rbegin()->f][k]); } } } if(sz(st[1])){ for(int j=0;j<26;j++){ for(int k=0;k<j;k++){ add(dp[i+1][j],-dp[st[1].rbegin()->f][k]); } } } // for(int j=0;j<26;j++){ // cout<<"HEY "<<i+1<<' '<<j<<' '<<dp[i+1][j]<<endl; // } } int ans=0; for(int j=0;j<26;j++) add(ans,dp[n][j]); cout<<ans; return 0; } /* */
#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...