This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
#define pb(x) push_back(x)
#define fil(x, y) memset(x, y, sizeof(x))
#define ll long long
#define ff first
#define ss second
#define printp(x) x.ff << " " << x.ss
#define pii pair<int,int>
#define pll pair<long long,long long>
#define mp(x, y) make_pair(x,y)
#define inf 1073741823
#define infll 4611686018427387903
#define M 1000000007
#define db(x) cout << x << " ";
#define N 200007
#define sz size
#define sm 0.0000007
#define ins insert
#define ers erase
#define all(k) k.begin(), k.end()
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
using namespace std;
int cnt[N][26];
int main()
{
fastio;
string s;
cin >> s;
int n = s.sz();
fil(cnt, 0);
for(int i = 0;i < 26;i++)
cnt[0][i] = 0;
for(int i = 1;i <= n;i++)
{
for(int j = 0;j < 26;j++)
{
cnt[i][j] = cnt[i - 1][j];
}
cnt[i][s[i - 1] - 'a']++;
}
int q;
cin >> q;
pii ara[q];
for(int i = 0;i < q;i++)
{
cin >> ara[i].ff >> ara[i].ss;
}
bool e = 0;
for(int j = 0;j < q;j++)
{
for(int k = 0;k < 26;k++)
{
if(cnt[ara[j].ss][k] - cnt[ara[j].ff - 1][k] >= 2)
{
e = 1;
break;
}
}
if(e)
break;
}
if(e == 0)
{
cout << 0 << endl;
return 0;
}
for(int i = 0;i < n;i++)
{
int x;
cin >> x;
cnt[x][s[x - 1] - 'a']--;
int m = s[x - 1] - 'a';
for(int k = x + 1;k <= n;k++)
{
cnt[k][m]--;
}
bool g = 0;
for(int j = 0;j < q;j++)
{
for(int k = 0;k < 26;k++)
{
if(cnt[ara[j].ss][k] - cnt[ara[j].ff - 1][k] >= 2)
{
g = 1;
break;
}
}
if(g)
break;
}
if(g == 0)
{
cout << i + 1 << endl;
break;
}
}
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... |