제출 #799566

#제출 시각아이디문제언어결과실행 시간메모리
799566eltu0815Misspelling (JOI22_misspelling)C++14
100 / 100
566 ms284960 KiB
#include <bits/stdc++.h> #define MAX 500005 #define MOD (ll)(1e9+7) #define INF (ll)(1e18) using namespace std; typedef long long ll; typedef pair<ll, ll> pll; ll n, m, k, tt; pair<pll, ll> inp[MAX]; ll dp[MAX][30], sum[MAX][30]; inline void update(ll i, ll j) { sum[i][j] = (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j] + 2 * MOD) % MOD; assert(sum[i][j] >= 0); } inline ll query(ll i1, ll j1, ll i2, ll j2) { return (sum[i2][j2] - sum[i2][j1 - 1] - sum[i1 - 1][j2] + sum[i1 - 1][j1 - 1] + 2 * MOD) % MOD; } struct Node { ll v; Node() { v = 0; } }; Node Merge(Node l, Node r) { Node ret; ret.v = max(l.v, r.v); return ret; } struct SEG { Node seg[MAX << 2]; void update(ll s, ll e, ll i, ll v, ll n) { if(s == e) { seg[n].v = max(seg[n].v, v); return; } ll m = (s + e) >> 1; if(i <= m) update(s, m, i, v, n << 1); else update(m + 1, e, i, v, n << 1 | 1); seg[n] = Merge(seg[n << 1], seg[n << 1 | 1]); } Node query(ll s, ll e, ll l, ll r, ll n) { if(s > r || e < l) return Node(); if(l <= s && e <= r) return seg[n]; ll m = (s + e) >> 1; return Merge(query(s, m, l, r, n << 1), query(m + 1, e, l, r, n << 1 | 1)); } }; SEG seg1, seg2; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for(ll i = 1; i <= m; ++i) { cin >> inp[i].first.first >> inp[i].first.second; inp[i].second = inp[i].first.first < inp[i].first.second; if(inp[i].first.first > inp[i].first.second) swap(inp[i].first.first, inp[i].first.second); } sort(inp + 1, inp + m + 1); for(ll i = 1; i <= 26; ++i) dp[1][i] = 1, update(1, i); for(ll i = 2, p = 1; i <= n; ++i) { while(p <= m && inp[p].first.first < i) { (inp[p].second ? seg1 : seg2).update(1, n, inp[p].first.second, inp[p].first.first, 1); ++p; } ll prv1 = seg1.query(1, n, i, n, 1).v + 1, prv2 = seg2.query(1, n, i, n, 1).v + 1; for(ll c = 1; c <= 26; ++c) { if(i > prv1 && c > 1) dp[i][c] += query(prv1, 1, i - 1, c - 1); if(i > prv2 && c < 26) dp[i][c] += query(prv2, c + 1, i - 1, 26); dp[i][c] %= MOD; update(i, c); } } ll ans = 0; for(ll i = 1; i <= n; ++i) for(ll j = 1; j <= 26; ++j) ans = (ans + dp[i][j]) % MOD; cout << ans; 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...