제출 #555221

#제출 시각아이디문제언어결과실행 시간메모리
555221Koosha_mvMisspelling (JOI22_misspelling)C++14
100 / 100
417 ms160968 KiB
#include <bits/stdc++.h> using namespace std; #define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl #define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl #define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl #define eror(x) cout<<#x<<'='<<(x)<<endl #define f_(i,a,b) for(int i=a;i>=b;i--) #define f(i,a,b) for(int i=a;i<b;i++) #define nb(x) __builtin_popcount(x) #define all(v) v.begin(),v.end() #define bit(n,k) (((n)>>(k))&1) #define Add(x,y) x=(x+y)%mod #define maxm(a,b) a=max(a,b) #define minm(a,b) a=min(a,b) #define lst(x) x[x.size()-1] #define sz(x) int(x.size()) #define mp make_pair #define ll long long #define pb push_back #define S second #define F first const int N=1e6+99,mod=1e9+7,S=26; int n,m,ps[N][S],dp[N][S],pd[N][S],res[N][S],seg[2][N]; void change(int l,int r,int x,int s){ l--,r--; for(l+=n,r+=n;l<r;l>>=1,r>>=1){ if(l&1) maxm(seg[s][l],x),l++; if(r&1) r--,maxm(seg[s][r],x); } } int get(int x,int s){ int res=0; for(x+=n-1;x>0;x>>=1) maxm(res,seg[s][x]); return res; } int32_t main(){ ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0); f(i,0,2) fill(seg[i],seg[i]+N,0); cin>>n>>m; f(i,0,m){ int u,v; cin>>u>>v; //swap(u,v); if(u<v){ change(u,v,u,0); } else{ change(v,u,v,1); } } f(i,0,S) ps[0][i]=1; f(i,1,n+1){ int s=get(i,0),t=get(i,1); f(j,0,S){ pd[i][j]=ps[i-1][j]; if(s!=0) Add(pd[i][j],mod-ps[s-1][j]); } f(j,0,S){ dp[i][j]=ps[i-1][j]; if(t!=0) Add(dp[i][j],mod-ps[t-1][j]); } int sum=0; f(j,0,S){ ps[i][j]=(ps[i-1][j]+sum)%mod; Add(sum,dp[i][j]); } sum=0; f_(j,S-1,0){ Add(ps[i][j],sum); Add(sum,pd[i][j]); } } int ans=0; f(i,0,S) Add(ans,dp[n][i]); cout<<ans; }
#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...