题目
A - Even But Not Even
#include<bits/stdc++.h>
#define de(x) cout<<#x<<' = '<<x<<endl;
using namespace std;
typedef long long ll;
const ll INF=0x7f7f7f7f;
int main(){
ll t;
cin>>t;
while(t--){
ll n;
string s,ans;
cin>>n;
cin>>s;
ll sum=0;
for(ll i=0;i<n;i++){
sum+=s[i]-'0';
if(s[i]!='0')
ans+=s[i];
}
n=ans.size();
if(n==0){
cout<<-1<<endl;
continue;
}
while(n-1>=0&&!((ans[n-1]-'0')&1))
n--;
if(n==0){
cout<<-1<<endl;
continue;
}
if(!(sum&1)){
for(ll i=0;i<n;i++){
printf("%c",ans[i]);
}
printf("\n");
continue;
}
ll pos=-1;
for(ll i=n-2;i>=0;i--){
if((ans[i]-'0')&1){
pos=i;
break;
}
}
if(pos==-1){
cout<<-1<<endl;
}
else{
for(ll i=0;i<n;i++){
if(i==pos)continue;
printf("%c",ans[i]);
}
printf("\n");
}
}
}
B - Array Sharpening
#include<bits/stdc++.h>
#define de(x) cout<<#x<<" = "<<x<<endl;
using namespace std;
typedef long long ll;
const ll maxn=3e5+10;
ll a[maxn];
int main(){
ll t;
cin>>t;
while(t--){
ll n;
cin>>n;
for(ll i=1;i<=n;i++){
scanf("%lld",&a[i]);
}
ll ps=n+1,pe=0;
for(ll i=1;i<=n;i++){
if(a[i]<i-1){
ps=i;
break;
}
}
for(ll i=n;i>=1;i--){
if(a[i]<n-i){
pe=i;
break;
}
}
if(ps<=pe||(ps==pe+1&&a[ps]==a[pe]))puts("NO");
else puts("YES");
}
}
C - Mind Control
#include<bits/stdc++.h>
#define de(x) cout<<#x<<' = '<<x<<endl;
using namespace std;
typedef long long ll;
const ll maxn=4e3+10;
const ll INF=0x7f7f7f7f;
ll a[maxn];
int main(){
ll t,n,m,k;
cin>>t;
while(t--){
cin>>n>>m>>k;
ll ans=0;
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
}
k=min(m-1,k);
for(ll i=0;i<=k;i++){
ll MIN=INF;
for(ll j=0;j<=m-1-k;j++){
MIN=min(MIN,max(a[i+j+1],a[n-(m-1)+i+j]));
}
ans=max(ans,MIN);
}
cout<<ans<<endl;
}
return 0;
}
D - Irreducible Anagrams
#include<bits/stdc++.h>
#define de(x) cout<<#x<<' = '<<x<<endl;
using namespace std;
typedef long long ll;
const ll maxn=2e5+10;
char s[maxn];
ll cnt[maxn][26];
int main(){
cin>>s+1;
ll q;
ll n=strlen(s+1);
cin>>q;
for(ll i=1;i<=n;i++){
for(ll j=0;j<26;j++){
cnt[i][j]=cnt[i-1][j];
}
cnt[i][s[i]-'a']++;
}
while(q--){
ll l,r,tot=0;
cin>>l>>r;
for(ll i=0;i<26;i++){
if(cnt[r][i]-cnt[l-1][i]>0)
tot++;
}
if(l==r||s[l]!=s[r]||tot>=3)puts("YES");
else puts("NO");
}
return 0;
}