OIer_Kevin @ 2024-08-25 22:31:01
64pts,有没有大佬帮忙看眼。
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
const int maxn=1e7+5;
int t,n,cnt,ans;
unordered_map<string,int>mp;
string o;
void solve(){
stack<string>q;
mp.clear();
cin>>n>>o;
ans=0,cnt=0;
bool flag=0;
string f="#";
for(int i=1;i<=n;i++){
char opt;
cin>>opt;
if(opt=='F'){
string name,be,ed;
cin>>name>>be>>ed;
if(flag==1){
continue;
}
if(mp[name]==1){
flag=1;
continue;
}
mp[name]=1;
q.push(name);
if(be!="n"&&ed=="n"&&f=="#"){
cnt++;
// cout<<name<<endl;
continue;
}
else if(be=="n"&&ed=="n"){
continue;
}
else if(be=="n"&&ed!="n"&&f=="#"){
f=name;
}
else if(be!="n"&&ed!="n"&&f=="#"){
bool bl=0;
for(int j=0;j<min(ed.size(),be.size());j++){
if(be[j]>ed[j]){
bl=1;
break;
}
else if(ed[j]>be[j]){
break;
}
}
// cout<<"bl:"<<bl<<endl;
if(be.size()>ed.size()){
bl=1;
}
if(bl==1){
f=name;
}
}
}
else{
if(flag==1){
continue;
}
if(q.empty()){
flag=1;
continue;
}
string s=q.top();
if(s==f){
f="#";
}
mp[s]=0;
q.pop();
if(q.empty()){
ans=max(ans,cnt);
// cout<<ans<<endl;
cnt=0;
}
}
}
if(!q.empty()){
flag=1;
}
if(flag==1){
cout<<"ERR"<<endl;
return;
}
if(o[2]=='1'){
if(ans==0){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
}
else{
if(ans==o[4]-'0'){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>t;
while(t--){
solve();
}
return 0;
}
Wa #5,#7,#8,#10