CF1861C Queries for the Array
Solution我们定义cnt表示当前序列长度。cnt1表示已经排好序的最后一个位置。cnt2表示没有排好序的最前一个位置 。然后对每一种都字符都进行见到讨论即可。#includebits/stdc.h using namespace std; const int N2e55; int T; string s; int main(){ ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); cinT; while(T--){ int cnt0,cnt10,cnt20; //cnt表示当前序列长度 //cnt1表示已经排好序的最后一个位置 //cnt2表示没有排好序的最前一个位置 bool flagtrue; cins; for(int i0;is.length();i){ if(s[i]){ cnt; }else if(s[i]-){ cnt--; if(cnt1cnt){ cnt1cnt; } if(cnt2cnt){ cnt20; } }else if(s[i]1){ if(cnt2!0){ flagfalse; } cnt1cnt; }else if(s[i]0){ if(cnt1||cntcnt1){ flagfalse; } if(cnt20) cnt2cnt; } } if(flagtrue) coutYES\n; else coutNO\n; } return ~(-1); }