Submission #1176091

#TimeUsernameProblemLanguageResultExecution timeMemory
1176091MisterReaperMisspelling (JOI22_misspelling)C++20
100 / 100
692 ms152560 KiB
// #undef DEBUG #include <bits/stdc++.h> using i64 = long long; #ifdef DEBUG #include "debug.h" #else #define debug(...) void(23) #endif constexpr int md = int(1E9) + 7; struct MInt { int val; MInt() : val(0) {} template<typename T> MInt(T x) { if (-md <= x && x < md) { val = x; } else { val = x % md; } if (val < 0) { val += md; } } int operator()() { return val; } MInt& operator+= (MInt rhs) { if ((val += rhs.val) >= md) { val -= md; } return *this; } MInt& operator-= (MInt rhs) { if ((val -= rhs.val) < 0) { val += md; } return *this; } MInt& operator*= (MInt rhs) { val = int((1LL * val * rhs.val) % md); return *this; } }; MInt operator+ (MInt lhs, MInt rhs) { return lhs += rhs; } MInt operator- (MInt lhs, MInt rhs) { return lhs -= rhs; } MInt operator* (MInt lhs, MInt rhs) { return lhs *= rhs; } std::ostream& operator<< (std::ostream& os, MInt x) { return os << x.val; } std::string to_string(MInt x) { return to_string(x.val); } using Z = MInt; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int N, M; std::cin >> N >> M; std::vector<std::array<int, 2>> nxt(N, {-1, -1}); for (int i = 0; i < M; ++i) { int A, B; std::cin >> A >> B; --A, --B; int tp = 0; if (A > B) { tp = 1; std::swap(A, B); } nxt[A][tp] = std::max(nxt[A][tp], B); } std::vector<std::array<Z, 26>> dp(N); for (int i = 0; i < N; ++i) { for (int j = 0; j < 26; ++j) { dp[i][j] = 1; } } std::array<Z, 26> sum_sma {}, sum_big {}; std::array<std::vector<int>, 26> ali_sma, ali_big; for (int i = N - 1; i >= 0; --i) { for (int c = 0; c < 26; ++c) { while (!ali_sma[c].empty() && ali_sma[c].back() <= nxt[i][0]) { for (int oc = 0; oc < c; ++oc) { sum_sma[c] -= dp[ali_sma[c].back()][oc]; } ali_sma[c].pop_back(); } while (!ali_big[c].empty() && ali_big[c].back() <= nxt[i][1]) { for (int oc = c + 1; oc < 26; ++oc) { sum_big[c] -= dp[ali_big[c].back()][oc]; } ali_big[c].pop_back(); } } for (int c = 0; c < 26; ++c) { dp[i][c] += sum_sma[c]; dp[i][c] += sum_big[c]; } for (int c = 0; c < 26; ++c) { ali_sma[c].emplace_back(i); for (int oc = 0; oc < c; ++oc) { sum_sma[c] += dp[i][oc]; } ali_big[c].emplace_back(i); for (int oc = c + 1; oc < 26; ++oc) { sum_big[c] += dp[i][oc]; } } } Z ans = 0; for (int i = 0; i < 26; ++i) { ans += dp[0][i]; } std::cout << ans << '\n'; 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...