Submission #706561

#TimeUsernameProblemLanguageResultExecution timeMemory
706561becaidoMisspelling (JOI22_misspelling)C++17
100 / 100
310 ms62288 KiB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

const int MOD = 1e9 + 7;
const int SIZE = 5e5 + 5;

int n, m;
int mx[SIZE][2];
int dp[SIZE][26], sum[26][2];

inline void add(int &x, int y) {
    x = x + y >= MOD ? x + y - MOD : x + y < 0 ? x + y + MOD : x + y;
}

void solve() {
    cin >> n >> m;
    while (m--) {
        int a, b;
        cin >> a >> b;
        if (a < b) mx[a][0] = max(mx[a][0], b);
        else mx[b][1] = max(mx[b][1], a);
    }
    vector<int> st[2];
    for (int i = n; i >= 1; i--) {
        fill(dp[i], dp[i] + 26, 1);
        for (int t : {0, 1}) while (st[t].size() && st[t].back() <= mx[i][t]) {
            int to = st[t].back();
            st[t].pop_back();
            FOR (j, 0, 25) add(sum[j][t], -dp[to][j]);
        }
        int pre = 0;
        for (int j = 25; j >= 0; j--) {
            add(dp[i][j], pre);
            add(pre, sum[j][0]);
        }
        pre = 0;
        FOR (j, 0, 25) {
            add(dp[i][j], pre);
            add(pre, sum[j][1]);
            add(sum[j][0], dp[i][j]);
            add(sum[j][1], dp[i][j]);
        }
        st[0].pb(i);
        st[1].pb(i);
    }
    cout << accumulate(dp[1], dp[1] + 26, 0ll) % MOD << '\n';
}

int main() {
    Waimai;
    solve();
}
#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...