이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sp << " " <<
#define int long long
#define vi vector<int>
#define pb push_back
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
#define ordered_set tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update>
const int N = 3e5+1;
const int MOD = 1e9+7;
void solve() {
string s;
cin >> s;
int n = s.size();
int q;
cin >> q;
vector<pii> ranges(q+1);
F(i,q) cin >> ranges[i].first >> ranges[i].second;
vi p(n+1);
F(i,n) cin >> p[i];
int l = 0;
int r = n;
while (l<=r) {
int m = (l+r) >> 1;
vector<bool> fucked(n+1);
F(i,m) fucked[p[i]] = 1;
vector<vi> pref(26,vi(n+1,0));
F(i,n) {
for (int j=0;j<26;j++) pref[j][i] = pref[j][i-1];
if (!fucked[i])pref[s[i-1]-'a'][i]++;
}
bool fl = 1;
for (auto it : ranges) {
for (int i=0;i<26;i++) {
if (pref[i][it.second]-pref[i][it.first-1] >= 2) {
fl = 0;
}
}
}
if (fl) r = m-1;
else l = m+1;
}
cout << l << endl;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
F(i,t) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |