제출 #702512

#제출 시각아이디문제언어결과실행 시간메모리
702512zyq_Misspelling (JOI22_misspelling)C++17
100 / 100
546 ms378584 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const long long MOD = 1e9 + 7; int N, M; int inp1, inp2; deque<pair<int, int> > v1, v2; int dv[500010][30], v[500010][30], prefix[500010][30]; int pow6[500010]; bool active[500010]; vector<pair<int, int> > curstack; int lastl1[500010]; int lastl2[500010]; bool lasplace[500010][2]; int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); pow6[0] = 1; for(int a=1; a<500010; a++){ pow6[a] = pow6[a-1] * 26; pow6[a] %= MOD; } cin >> N >> M; for(int a=0; a<M; a++){ cin >> inp1 >> inp2; if(inp1 < inp2){ //then larger then v1.push_back({inp1, inp2-1}); } else{ v2.push_back({inp2, inp1-1}); } } sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); for(int a=1; a<=N; a++){ while(!curstack.empty() && curstack.back().second < a){ curstack.pop_back(); } while(!v1.empty() && v1[0].first <= a){ curstack.push_back(v1[0]); v1.pop_front(); } lastl1[a] = (curstack.empty() ? INT_MAX : curstack.back().first-1); } for(int a=1; a<=N; a++){ while(!curstack.empty() && curstack.back().second < a){ curstack.pop_back(); } while(!v2.empty() && v2[0].first <= a){ curstack.push_back(v2[0]); v2.pop_front(); } lastl2[a] = (curstack.empty() ? INT_MAX : curstack.back().first-1); } for(int a=1; a<=N; a++){ //cout << lastl1[a] << ' ' << lastl2[a] << '\n'; } for(int a=1; a<=26; a++){ dv[0][a] = 1LL; prefix[0][a] = (long long)a; v[0][a] = 0LL; } for(int a=1; a<N; a++){ int sm = 0; for(int b=1; b<=26; b++){ sm += v[a-1][b]; sm %= MOD; if(sm < 0) sm += MOD; } for(int b=1; b<=26; b++){ v[a][b] = sm; } for(int b=1; b<=26; b++){ if(lastl1[a] != INT_MAX){ //v[a][b] += (prefix[lastl1[a]][26] - prefix[lastl1[a]][b]) % MOD; v[a][b] += prefix[lastl1[a]][b-1]; } v[a][b] %= MOD; if(v[a][b] < 0) v[a][b] += MOD; if(lastl2[a] != INT_MAX){ //v[a][b] += prefix[lastl2[a]][b-1]; v[a][b] += (prefix[lastl2[a]][26] - prefix[lastl2[a]][b]) % MOD; } v[a][b] %= MOD; if(v[a][b] < 0) v[a][b] += MOD; } for(int b=1; b<=26; b++){ dv[a][b] = pow6[a] - v[a][b]; dv[a][b] %= MOD; if(dv[a][b] < 0) dv[a][b] += MOD; prefix[a][b] = prefix[a][b-1] + dv[a][b]; prefix[a][b] %= MOD; if(prefix[a][b] < 0) prefix[a][b] += MOD; } } cout << prefix[N-1][26]; }
#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...