社区讨论

建议评橙

P15233「CROI · R3」浣熊的蒲公英参与者 10已保存回复 14

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
14 条
当前快照
1 份
快照标识符
@mlhw8i85
此快照首次捕获于
2026/02/11 18:35
上周
此快照最后确认于
2026/02/11 19:20
上周
查看原帖
这道题就是一道非常水的字符串语法题。
我的赛时代码:
CPP
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+1,mod=1e9+7;
#define int long long
string s;
int an,n,g,cun;
char h;
struct fhb{
 char c;
 int it;
}a[N];
int sz(int st,int nd){
 int ans=0;
 for(int i=st;i<=nd;i++){
  ans=10*ans+s[i]-'0';
  ans%=mod;
 }
 return ans;
}
int cheng(int st,int nd){
 int ans=1,cnt=0;
 for(int i=st;i<=nd;i++){
  if(isdigit(s[i])) cnt=(10*cnt+s[i]-'0')%mod;
  else ans=ans*cnt%mod,cnt=0;
 }
 return ans*cnt%mod;
}
int bds(string s){
 int ans=0;
 for(int i=0;i<=an;i++){
  if(a[i].c=='-'){
   if(a[i+1].c=='*'){
    int nd=i+2;
    while(a[nd].c=='*') nd++;
    ans-=cheng(a[i].it+1,a[nd].it-1);
    ans=(ans+mod)%mod;
   }
   else ans-=sz(a[i].it+1,a[i+1].it-1),ans=(ans+mod)%mod;
  }
  else if(a[i].c=='+'){
   if(a[i+1].c=='*'){
    int nd=i+2;
    while(a[nd].c=='*') nd++;
    ans+=cheng(a[i].it+1,a[nd].it-1),ans%=mod;
   } 
   else ans+=sz(a[i].it+1,a[i+1].it-1),ans%=mod;
  }
 }
 return ans;
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
 cin>>s>>n;
 int len=s.size();
 for(int i=0;i<len;i++) 
 if(!isdigit(s[i])) a[++an].c=s[i],a[an].it=i;
 a[0].c='+',a[0].it=-1,a[an+1].it=len;
 cun=bds(s);
 cout<<cun<<"\n";
 while(n--){
  cin>>g>>h;
  if(h=='*' || a[g].c!='*') continue;
  int zz=g-1,yz=g+1;
  while(a[zz].c=='*') zz--;
  while(a[yz].c=='*') yz++;
  int z_=cheng(a[zz].it+1,a[g].it-1);
  int y_=cheng(a[g].it+1,a[yz].it-1);
  if(a[zz].c=='-') cun=(cun+(z_*y_)%mod-z_+mod)%mod;
  else cun=(cun-(z_*y_)%mod+z_+mod)%mod;
  if(h=='+') cun+=y_;
  else cun-=y_;
  a[g].c=h,s[a[g].it]=h;
  cun=(cun+mod)%mod;
  cout<<cun<<"\n";
 }
    return 0;
}

回复

14 条回复,欢迎继续交流。

正在加载回复...