社区讨论
WA #4
P7993[USACO21DEC] Lonely Photo B参与者 1已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mi3yjutw
- 此快照首次捕获于
- 2025/11/18 10:32 4 个月前
- 此快照最后确认于
- 2025/11/18 10:32 4 个月前
CPP
#include<bits/stdc++.h>
#define for1(a,b,c) for(auto a=b;a<=c;++a)
#define for2(a,b,c) for(auto a=b;a>=c;--a)
#define for3(a,b) for(auto a:b)
//#define for4(a,b,c) for(auto [a,b]:c)
#define for5(a,b,c,d) for(auto a=b;a<=c;a+=d)
#define for6(a,b,c,d) for(auto a=b;a>=c;a-=d)
#define int long long
using namespace std;
using ll=long long;
using ld=long double;
const int N=500005;
int lg[N],rg[N],lh[N],rh[N];
signed main(){
// freopen("photo.in","r",stdin);
// freopen("photo.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
string s;
cin>>s;
stack<int> st;
memset(lg,-1,sizeof(lg));
memset(lh,-1,sizeof(lh));
fill(rg,rg+n,n);
fill(rh,rh+n,n);
while(!st.empty()) st.pop();
for1(i,0,n-1){
if(s[i]=='G'){
while(!st.empty()) rg[st.top()]=i,st.pop();
}
st.push(i);
}
while(!st.empty()) st.pop();
for2(i,n-1,0){
if(s[i]=='G'){
while(!st.empty()) lg[st.top()]=i,st.pop();
}
st.push(i);
}
while(!st.empty()) st.pop();
for1(i,0,n-1){
if(s[i]=='H'){
while(!st.empty()) rh[st.top()]=i,st.pop();
}
st.push(i);
}
while(!st.empty()) st.pop();
for2(i,n-1,0){
if(s[i]=='H'){
while(!st.empty()) lh[st.top()]=i,st.pop();
}
st.push(i);
}
while(!st.empty()) st.pop();
// for1(i,0,n-1){cout<<"i:"<<i<<",s[i]:"<<s[i]<<",lg[i]:"<<lg[i]<<",lh[i]:"<<lh[i]<<",rg[i]:"<<rg[i]<<",rh[i]:"<<rh[i]<<'\n';for1(j,1,1000000){cout<<"";}}
int ans=0;
for1(i,0,n-1){
if(s[i]=='G')
ans+=max(0ll,(i-lg[i])*(rg[i]-i)-3);
if(s[i]=='H')
ans+=max(0ll,(i-lh[i])*(rh[i]-i)-3);
}
cout<<ans;
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...