이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 5e5+8;
const int M = 1e9+7;
int n, m, dp[N][27], ps[N][27], ans;
vector<pair<int, int>> req[N];
multiset<int> st[2];
signed main() {
    cin >> n >> m;
    while (m--) {
        int l, r;
        cin >> l >> r;
        req[max(l, r)].push_back({min(l, r), (l < r) ? 1 : 0});
        if (l < r) st[1].insert(l);
        else st[0].insert(r);
    }
    for (int i = 1; i <= 26; i++) dp[1][i] = 1, ps[1][i] = i;
    for (int i = 2; i <= n; i++) {
        for (int s = 1, k; s+1; s--) {
            auto it = st[s^1].lower_bound(i);
            if (it == st[s^1].begin()) k = 0;
            else k = *(--it);
            for (int j = 1; j <= 26; j++) {
                if (!s) (dp[i][j] += ((ps[i - 1][j - 1] - ps[k][j - 1] + M) % M)) %= M;
                else ((dp[i][j] += (ps[i - 1][26] - ps[i - 1][j] - ps[k][26] + ps[k][j] + M + M)) %= M);               
            }
        }
        for (int j = 1; j <= 26; j++) ps[i][j] = (ps[i - 1][j] + ps[i][j - 1] - ps[i - 1][j - 1] + dp[i][j] + M) % M;
        for (auto [x, y] : req[i]) st[y].erase(st[y].find(x));
    }
    cout << ps[n][26];
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |