最近做的題
阿新 • • 發佈:2021-11-10
2021女生賽B
點選檢視程式碼
// Problem: B. 攻防演練 // Contest: Codeforces - 2021年中國大學生程式設計競賽女生專場 // URL: https://codeforces.com/gym/103389/problem/B // Memory Limit: 512 MB // Time Limit: 1000 ms // // Powered by CP Editor (https://cpeditor.org) #include<bits/stdc++.h> using namespace std; typedef long long ll;typedef unsigned long long ull; typedef pair<ll,ll>PLL;typedef pair<int,int>PII;typedef pair<double,double>PDD; #define I_int ll inline ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;} #define read read() #define rep(i, a, b) for(int i=(a);i<=(b);++i) #define dep(i, a, b) for(int i=(a);i>=(b);--i) ll ksm(ll a,ll b,ll p){ll res=1;while(b){if(b&1)res=res*a%p;a=a*a%p;b>>=1;}return res;} const int maxn=2e5+7,maxm=1e6+7,mod=1e9+7; char s[maxn]; int ne[maxn][27],mp[27],dp[maxn][23]; int main(){ int m=read,n=read; scanf("%s",s+1); for(int i=0;i<=26;i++) mp[i]=n+1,ne[n][i]=n+1; for(int i=n;i;i--){ int now=s[i]-'a'; ne[i][now]=mp[now]; mp[now]=i; for(int j=0;j<m;j++){ ne[i-1][j]=mp[j]; } } for(int i=0;i<=n;i++){ int now=0; for(int j=0;j<m;j++) now=max(now,ne[i][j]); dp[i][0]=now; } for(int i=0;i<22;i++) dp[n][i]=dp[n+1][i]=n+1; for(int j=1;j<22;j++) for(int i=0;i<=n;i++){ dp[i][j]=dp[dp[i][j-1]][j-1]; } int q=read; while(q--){ int l=read-1,r=read; int ans=1; for(int i=21;i>=0;i--){ // cout<<i<<" "<<l<<" "<<dp[l][i]<<" "<<ans<<endl; if(dp[l][i]<=r){ l=dp[l][i]; ans=ans+(1<<i); } } cout<<ans<<endl; } return 0; }
2020瀋陽ICPC D
點選檢視程式碼
#include<bits/stdc++.h> using namespace std; typedef long long ll;typedef unsigned long long ull; typedef pair<ll,ll>PLL;typedef pair<int,int>PII;typedef pair<double,double>PDD; #define I_int ll inline ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;} #define read read() #define rep(i, a, b) for(int i=(a);i<=(b);++i) #define dep(i, a, b) for(int i=(a);i>=(b);--i) ll ksm(ll a,ll b,ll p){ll res=1;while(b){if(b&1)res=res*a%p;a=a*a%p;b>>=1;}return res;} const int maxn=1e6+7; char s[maxn]; ll n,ans,sum; void dfs(int u,int cnt0,int cnt1,int now){ if(ans>=100||cnt0>sum||cnt1>sum) return ; if(u==n){ cout<<s<<endl; ans++; return ; } if(now%2==0){ s[u]='b'; dfs(u+1,cnt0+1,cnt1,now); s[u]='r'; dfs(u+1,cnt0,cnt1+1,now^1); } else{ s[u]='b'; dfs(u+1,cnt0,cnt1+1,now); s[u]='r'; dfs(u+1,cnt0+1,cnt1,now^1); } } int main(){ n=read; sum=(n+1)/2; ll tmp1=(n+1)/2,tmp2=(n+1)/2; if((n+1)%2) sum++,tmp1++; cout<<tmp1*tmp2<<endl; dfs(0,1,0,0); return 0; } /* */