이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
#define mem(a, b) memset(a, (b), sizeof(a))
#define all(c) (c).begin(),(c).end()
#define sz(a) ((int)(a.size()))
#define ll long long
#define linf (ll)1e18
#define inf (int)1e9
#define minf 0x3F3F3F3F
#define pb push_back
#define fs first
#define sc second
#define mp make_pair
#define mod 1000000007
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAX 100010
#define MXT 100005
#define watch(x) cerr<<#x<<" = "<<(x)<<endl;
using namespace std;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n;
string s;
int bit[40][MAX];
int arr[MAX];
vector<pii> Q;
int sum(int c, int k) {
int s = 0;
while(k>=1) {
s += bit[c][k];
k -= k&-k;
}
return s;
}
void add(int c, int k, int x) {
while(k<=MXT) {
bit[c][k] += x;
k += k&-k;
}
}
int rsum(int c, int a, int b) {
return sum(c, b)-sum(c, a-1);
}
bool valid(int id) {
bool ret = true;
for(int i=1;i<=id;i++) {
char c = s[arr[i]-1];
add(c-'a', arr[i], -1);
}
for(int i=0;i<sz(Q);i++) {
for(int j=0;j<27;j++) {
int cnt = rsum(j, Q[i].fs, Q[i].sc);
if(cnt>1) ret = false;
}
}
for(int i=1;i<=id;i++) {
char c = s[arr[i]-1];
add(c-'a', arr[i], 1);
}
return ret;
}
int main() {
IO;
cin >> s >> n;
for(int i=0;i<sz(s);i++) {
add(s[i]-'a', i+1, 1);
}
for(int i=0;i<n;i++) {
int a, b;
cin >> a >> b;
Q.pb(mp(a,b));
}
for(int i=1;i<=sz(s);i++) cin >> arr[i];
int low = 0, high = sz(s), ans = 0;
while(low<=high) {
int mid = (low+high)>>1;
if(valid(mid)) ans = mid, high = mid-1;
else low = mid+1;
}
cout << ans;
return 0;
}
# | 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... |