Submission #971383

#TimeUsernameProblemLanguageResultExecution timeMemory
971383happy_nodeMisspelling (JOI22_misspelling)C++17
29 / 100
802 ms266700 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MX=5e5+5, mod=1e9+7; int N,M; vector<pair<int,int>> open[MX], close[MX]; ll dp[MX][26], sdp[MX][26]; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin>>N>>M; for(int i=0;i<M;i++) { int a,b; cin>>a>>b; if(a<b) { open[a].push_back({b,0}); // s_{i-1} > s{i} close[b].push_back({a,0}); } else { // a > b open[b].push_back({a,1}); // s_{i-1} < s{i} close[a].push_back({b,1}); } } for(int c=0;c<26;c++) dp[1][c]=1, sdp[1][c]=1; multiset<int> st[2]; st[0].insert(0); st[1].insert(0); for(auto [j,t]:open[1]) st[t].insert(1); for(int i=2;i<=N;i++) { int p=*st[0].rbegin(); int q=*st[1].rbegin(); if(p<=q) { ll cur=0; for(int c=0;c<26;c++) { dp[i][c]+=cur; dp[i][c]%=mod; cur+=sdp[i-1][c]; cur-=sdp[min(p,q)][c]; cur+=mod; cur%=mod; } } if(p>=q) { ll cur=0; for(int c=25;c>=0;c--) { dp[i][c]+=cur; dp[i][c]%=mod; cur+=sdp[i-1][c]; cur-=sdp[min(p,q)][c]; cur+=mod; cur%=mod; } } for(int c=0;c<26;c++) { sdp[i][c]=sdp[i-1][c]+dp[i][c]; sdp[i][c]%=mod; } for(auto [j,t]:open[i]) st[t].insert(i); for(auto [j,t]:close[i]) { st[t].erase(st[t].find(j)); } } ll ans=0; for(int c=0;c<26;c++) { ans+=sdp[N][c]; ans%=mod; } cout<<ans<<'\n'; }
#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...