Submission #880363

#TimeUsernameProblemLanguageResultExecution timeMemory
880363DAleksaMisspelling (JOI22_misspelling)C++17
0 / 100
1 ms1368 KiB
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int add(int x, int y) { x += y; return x >= mod ? x - mod : x; } int sub(int x, int y) { x -= y; return x < 0 ? x + mod : x; } void sadd(int& x, int y) { x = add(x, y); } void ssub(int& x, int y) { x = sub(x, y); } struct Fenwick { int n; vector<int> fenw; Fenwick() { } Fenwick(int _n) { n = _n; fenw.resize(n); for(int i = 0; i < n; i++) fenw[i] = 0; } void update(int x, int val) { x++; for(int i = x; i < n; i += (i & -i)) sadd(fenw[i], val); } int get(int r) { r++; int ans = 0; for(int i = r; i >= 1; i -= (i & -i)) sadd(ans, fenw[i]); return ans; } int get(int l, int r) { if(l > r) return 0; return sub(get(r), get(l - 1)); } }; const int N = 210, M = 26; int n, m; int a[N], b[N]; int dp[N][M][2]; int cnt[N][N][2]; int important[N][2]; int first[N]; int pref[N][M][2]; vector<Fenwick> fw(M); int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for(int i = 0; i < m; i++) { cin >> a[i] >> b[i]; for(int j = min(a[i], b[i]); j < max(a[i], b[i]); j++) { int len = j - min(a[i], b[i]) + 1; if(a[i] < b[i]) cnt[j][len][0]++; else cnt[j][len][1]++; } } for(int i = 1; i <= n; i++) { for(int len = 1; len <= i; len++) { if(cnt[i][len][0] > 0) { if(important[i][0] == 0) { important[i][0] = i - len + 1; first[i] = 1; } else { important[i][1] = i - len + 1; break; } } if(cnt[i][len][1] > 0) { if(important[i][0] == 0) { important[i][0] = i - len + 1; first[i] = 2; } else { important[i][1] = i - len + 1; break; } } } } for(int i = 0; i < M; i++) fw[i] = Fenwick(n + 2); for(int c = 0; c < M; c++) { dp[0][c][0] = dp[0][c][1] = 1; fw[c].update(0, 1); } // for(int i = 1; i <= n; i++) cout << i << ": " << important[i][0] << " " << important[i][1] << " " << first[i] << "\n"; for(int i = 1; i <= n; i++) { for(int c = 0; c < M; c++) { dp[i][c][0] = fw[c].get(important[i][0], i - 1); dp[i][c][1] = fw[c].get(important[i][1], important[i][0] - 1); // if(important[i][0] == 0) sadd(dp[i][c][0], 1); // if(important[i][1] == 0 && important[i][0] > 0) sadd(dp[i][c][1], 1); } pref[i][0][0] = dp[i][0][0]; pref[i][0][1] = dp[i][0][1]; for(int c = 1; c < M; c++) pref[i][c][0] = add(pref[i][c - 1][0], dp[i][c][0]); for(int c = 1; c < M; c++) pref[i][c][1] = add(pref[i][c - 1][1], dp[i][c][1]); for(int nwc = 0; nwc < M; nwc++) { fw[nwc].update(i, add(sub(pref[i][M - 1][0], pref[i][nwc][0]), (nwc > 0 ? pref[i][nwc - 1][0] : 0))); if(first[i] == 1) fw[nwc].update(i, sub(pref[i][M - 1][1], pref[i][nwc][1])); else if(first[i] == 2 && nwc > 0) fw[nwc].update(i, pref[i][nwc - 1][1]); } } // for(int i = 1; i <= n; i++) { // for(int j = 0; j < M; j++) cout << dp[i][j][0] + dp[i][j][1] << " "; // cout << "\n"; // } int ans = 0; for(int c = 0; c < M; c++) { sadd(ans, dp[n][c][0]); sadd(ans, dp[n][c][1]); } 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...