请问一下,这题ODT了最后一个(在问一下一个写法的不同,为什么会导致全RE)

P2572 [SCOI2010] 序列操作

BeautifulWater @ 2022-08-02 21:11:14

/*********************************************************************
    程序名: 
    版权: 
    作者: 
    日期: 2022-08-02 19:28 
    说明: 
*********************************************************************/
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define rep(i,x,n) for(register int i=x;i<n;i++)
#define repd(i,x,n) for(register int i=x;i<=n;i++)
#define MAX 1000005
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PII pair<int,int>
#define IT set<node>::iterator
#define IOS ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e6+50,M = 1E6+50;
int n,a[N];
struct node{
    int l,r;
    mutable char c;
    node(int L,int R=-1,char C='Z'):l(L),r(R),c(C){}
    bool operator<(const node& o) const{
        return l<o.l;
    }
};
set<node> st;
IT split(int pos)
{
    IT it = st.lower_bound(node(pos));
    if(it!=st.end()&&it->l==pos)
        return it;
    --it;
    int L = it->l, R = it->r;
    char col = it->c;
    st.erase(it);
    st.insert(node(L,pos-1,col));
    return st.insert(node(pos,R,col)).first;
}
void assign_val(int l,int r,char c)
{
    IT itr = split(r+1),itl = split(l);
//  for(IT it = itl;it!=itr;itl++)
//      st.erase(it);
    st.erase(itl,itr);
    st.insert(node(l,r,c));
}
char get_c(int pos)
{
    IT it = st.lower_bound(node(pos));
    if(it!=st.end()&&it->l==pos) return it->c;
    it--;
    return it->c; 
}
bool check(int l,int r)
{
    IT itr = split(r+1),itl = split(l);
    char c = itl->c;
    for(IT it=itl;it!=itr;it++)
        if(it->c!=c){
            return true;
    }
            return false;
}
void solve()
{
    cin>>n;
    string s;
    cin>>s;
    s = '#' + s;
    int cnt = 1,len = s.length()-1;
    for(int i=2;i<=len;i++)
    {
        if(s[i]==s[i-1])
            cnt++;
        else{
            st.insert(node(i-1-cnt+1,i-1,s[i-1]));
            cnt = 1;
        }
    }
    st.insert(node(len-cnt+1,len,s[len]));
    cin>>n;
    for(int i = 1;i<=n;i++){
        char opt;
        int l,r;
        cin>>opt>>l>>r;
        if(opt=='A'){
            char ch;
            cin>>ch;
            assign_val(l,r,ch);
            continue;
        }
        if(opt=='B'){
            if(l==1||r==len) {
                if(check(l,r))
                cout<<"No\n";
                else{
                    cout<<"Yes\n";
                    assign_val(l,r,get_c(l));
                }
            }
            else{
                int lc = get_c(l-1);
                int rc = get_c(r+1);
                if(lc==rc||check(l,r))
                   cout<<"No\n";
                else{
                    cout<<"Yes\n";
                    assign_val(l,r,get_c(l));
                } 
            }
            continue;
        }
    }
}
int main()
{
    IOS;
    //int T;
    //cin>>T;
    //while(T--)
    solve();
    return 0;
}
//  for(IT it = itl;it!=itr;itl++)
//      st.erase(it);
    st.erase(itl,itr);

by Akeryep @ 2022-09-22 21:50:08

你这个代码过了几个点


by _Minmatar_Star @ 2023-10-16 20:39:22

你的it都被erase了迭代器还咋迭代,erase之后it就不能用了


|