Submission #602535

#TimeUsernameProblemLanguageResultExecution timeMemory
602535SamAndMisspelling (JOI22_misspelling)C++17
100 / 100
478 ms136108 KiB
#include <bits/stdc++.h> using namespace std; #define m_p make_pair #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define fi first #define se second typedef long long ll; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937 rnf(2106); const int N = 500005, M = 1000000007; int n, m; int a[N]; vector<int> v[N]; int dp[N][26][2]; void solv() { cin >> n >> m; for (int i = 1; i <= m; ++i) { int x, y; cin >> x >> y; if (x == y) continue; if (x < y) { v[x].push_back(y); } else { v[y].push_back(-x); } } stack<int> g[2]; int s[26] = {}; for (int k = 0; k < 26; ++k) { dp[n][k][0] = 1; s[k] = 1; } for (int i = n - 1; i >= 1; --i) { /*for (int k = 0; k < 26; ++k) { for (int j = i + 1; j <= n; ++j) { s[k] = (s[k] + dp[j][k][0]) % M; s[k] = (s[k] + dp[j][k][1]) % M; } }*/ int p[26] = {}; p[0] = s[0]; for (int k = 1; k < 26; ++k) p[k] = (p[k - 1] + s[k]) % M; for (int k = 0; k < 26; ++k) { dp[i][k][1] = (p[25] - p[k] + M) % M; if (k) dp[i][k][0] = p[k - 1]; s[k] = (s[k] + dp[i][k][1]) % M; s[k] = (s[k] + dp[i][k][0]) % M; /*for (int u = k + 1; u < 26; ++u) dp[i][k][1] = (dp[i][k][1] + s[u]) % M; for (int u = 0; u < k; ++u) dp[i][k][0] = (dp[i][k][0] + s[u]) % M;*/ } g[0].push(i); g[1].push(i); for(int t = 0; t < sz(v[i]); ++t) { if (v[i][t] > 0) { while (!g[1].empty()) { int j = g[1].top(); if (j < v[i][t]) { for (int k = 0; k < 26; ++k) { s[k] = (s[k] - dp[j][k][1] + M) % M; dp[j][k][1] = 0; } g[1].pop(); } else break; } } else { while (!g[0].empty()) { int j = g[0].top(); if (j < -v[i][t]) { for (int k = 0; k < 26; ++k) { s[k] = (s[k] - dp[j][k][0] + M) % M; dp[j][k][0] = 0; } g[0].pop(); } else break; } } } } int ans = 0; for (int k = 0; k < 26; ++k) ans = (ans + s[k]) % M; cout << ans << "\n"; } int main() { #ifdef SOMETHING freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif // SOMETHING ios_base::sync_with_stdio(false), cin.tie(0); int tt = 1; //cin >> tt; while (tt--) { solv(); } 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...