题意:
每个点能否跟后面相邻的点交换,由01串表示;
问是否能够把数列还原成递增的;
思路:
判断01串中每一个0的位置,是这个位置的点不能跟后面进行交换,如果原数列中这个位置的及之前的数大于这个位置的标号(其实应该按1-n标号),那么还原递增数列的话就没法实现,这个点过不去;
前面用优先队列,nlogn的复杂度;
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<map>
#define PI acos(-1.0)
#define in freopen("in.txt", "r", stdin)
#define out freopen("out.txt", "w", stdout)
#define kuaidian ios::sync_with_stdio(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 2e5 + 7, maxd = 1e5 + 7;
const int mod = 1e9 + 7;
const int INF = 0x7f7f7f7f;
int n;
int a[maxn];
int cnt[maxn];
int x;
priority_queue<int, vector<int>, less<int> > qu;
int main() {
kuaidian;
memset(cnt, 0, sizeof cnt);
cin >> n;
int cur = 0;
for(int i = 0; i < n; ++i) {
cin >> a[i];
}
string s;
cin >> s;
while(!qu.empty()) qu.pop();
for(int i = 0; i < s.length(); ++i) {
qu.push(a[i]);
if(s[i] == '1') continue;
if(!qu.empty() && qu.top() > i+1) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}