Submission #605618

#TimeUsernameProblemLanguageResultExecution timeMemory
605618Red_InsideMisspelling (JOI22_misspelling)C++17
100 / 100
2946 ms282184 KiB
// #include <bits/stdc++.h> #define ll long long #define f first #define s second #define pb push_back #define mp make_pair #define o cout<<"BUG"<<endl; #define FOR(i, j, n) for(int j = i; j < n; ++j) #define forn(i, j, n) for(int j = i; j <= n; ++j) #define nfor(i, j, n) for(int j = n; j >= i; --j) #define all(v) v.begin(), v.end() #define ld long double #define ull unsigned long long using namespace std; const int maxn=5e5+100,LOG=17,mod=1e9+7; int block = 226, timer = 0; const ld EPS = 1e-18; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define bt(i) (1 << (i)) //#define int ll const int inf=2e9; #define y1 yy #define prev pre #define pii pair <int, int> int n, m; int t[4*maxn][28][3], dp[maxn][28], temp[30]; multiset <int> st[4]; vector <pii> start[maxn], fin[maxn]; inline void upd(int pos, int val, int x, int ty) { for(; pos <= n; pos = (pos | (pos + 1))) t[pos][x][ty] = (t[pos][x][ty] + val) % mod; } inline int Get(int r, int x, int ty) { int ret = 0; for(; r >= 1; r = ((r + 1) & r)-1) ret = (ret + t[r][x][ty]) % mod; return ret; } inline int get(int l, int r, int x, int ty) { if(l > r) return 0; int ret = mod - Get(l-1, x, ty); return (ret + Get(r, x, ty)) % mod; } main() { IOS cin >> n >> m; forn(1, i, m) { int l, r, ty; cin >> l >> r; if(l < r) ty = 2; else ty = 1, swap(l, r); start[l].pb({r, ty}); fin[r].pb({l, ty}); } st[1].insert(0); st[2].insert(0); forn(1, i, n) { for(auto j : start[i-1]) st[j.s].insert(i-1); int L, L2; L2 = max(*st[1].rbegin(), *st[2].rbegin()) + 1; L = L2; forn(0, j, 'z'-'a') { if(j > 0) dp[i][j] = (dp[i][j] + get(L, i-1, j-1, 1)) % mod; if(j < 'z'-'a') dp[i][j] = (dp[i][j] + get(L, i-1, j+1, 2)) % mod; } if(*st[1].rbegin() < *st[2].rbegin()) { auto it = *st[1].rbegin() + 1; L = it; FOR(0, j, 'z'-'a') dp[i][j] = (dp[i][j] + get(L, L2-1, j+1, 2)) % mod; } else if(*st[1].rbegin() > *st[2].rbegin()) { auto it = *st[2].rbegin() + 1; L = it; forn(1, j, 'z'-'a') dp[i][j] = (dp[i][j] + get(L, L2-1, j-1, 1)) % mod; } if(i == 1) { forn(0, j, 'z'-'a') dp[i][j] = 1; } /*cout << " FOR " << i << endl; forn(0, j, 'z'-'a') cout << (char)(j + 'a') << " " << dp[i][j] << endl; */ forn(0, j, 'z'-'a') { if(j > 0) temp[j] = (temp[j - 1] + dp[i][j]) % mod; else temp[j] = dp[i][j]; upd(i, temp[j], j, 1); // cout << "UPD " << i << " " << temp[j] << endl; } nfor(0, j, 'z'-'a') { if(j == 'z'-'a') temp[j] = dp[i][j]; else temp[j] = (temp[j + 1] + dp[i][j]) % mod; // cout << "UPD " << i << " " << temp[j] << endl; upd(i, temp[j], j, 2); } /* o for(auto j : st[1]) cout << j << " "; cout << endl; for(auto j : st[2]) cout << j << " "; cout << endl; for(auto j : fin[i]) cout << j.f << " " << j.s << endl; cout << endl;*/ for(auto j : fin[i]) st[j.s].erase(st[j.s].find(j.f)); } int ans = 0; forn(1, i, n) { forn(0, j, 'z'-'a') ans = (ans + dp[i][j]) % mod; } cout << ans; }

Compilation message (stderr)

misspelling.cpp:56:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   56 | main()
      | ^~~~
#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...