# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
313598 | colazcy | Grudanje (COCI19_grudanje) | C++17 | 1475 ms | 13688 KiB |
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 <cstdio>
#include <cstring>
using namespace std;
const int maxn = 1e5 + 100;
struct Query{int l,r;}query[maxn];
int n,q,val[maxn];
char str[maxn];
struct BIT{
int f[maxn];
inline int lowbit(int x){return x & (-x);}
inline void add(int pos,int v){
while(pos < maxn){
f[pos] += v;
pos += lowbit(pos);
}
}
inline int query(int pos){
int res = 0;
while(pos){
res += f[pos];
pos -= lowbit(pos);
}
return res;
}
inline int query(int a,int b){return query(b) - query(a - 1);}
}bit[26];
inline void init(){
for(int i = 1;i <= n;i++)
bit[str[i] - 'a'].add(i,1);
}
inline bool check(int limit){
bool res = true;
for(int i = 1;i <= limit;i++)
bit[str[val[i]] - 'a'].add(val[i],-1);
for(int i = 1;i <= q && res;i++)
for(int j = 0;j < 26;j++)
if(bit[j].query(query[i].l,query[i].r) > 1){
res = false;
break;
}
for(int i = 1;i <= limit;i++)
bit[str[val[i]] - 'a'].add(val[i],1);
return res;
}
int main(){
scanf("%s",str + 1);
n = strlen(str + 1);
scanf("%d",&q);
for(int i = 1;i <= q;i++)scanf("%d %d",&query[i].l,&query[i].r);
for(int i = 1;i <= n;i++)scanf("%d",val + i);
init();
int l = 0,r = n,ans = 0;
while(l <= r){
int mid = (l + r) >> 1;
if(check(mid))ans = mid,r = mid - 1;
else l = mid + 1;
}
printf("%d\n",ans);
return 0;
}
Compilation message (stderr)
# | 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... |