# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
222389 | jamielim | Grudanje (COCI19_grudanje) | C++14 | 79 ms | 4220 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 <bits/stdc++.h>
using namespace std;
int main(){
char str[100005];
scanf("%s",str);
int n=(int)strlen(str),q;
scanf("%d",&q);
pair<int,int> qu[q];
for(int i=0;i<q;i++){
scanf("%d%d",&qu[i].first,&qu[i].second);
qu[i].first--;qu[i].second--;
}
sort(qu,qu+q);
int pmax[n],smin[n];
int ptr=0;
for(int i=0;i<n;i++){
if(i==0)pmax[i]=-1;
else pmax[i]=pmax[i-1];
while(ptr<q&&qu[ptr].first==i){
pmax[i]=max(pmax[i],qu[ptr].second);
ptr++;
}
}
for(int i=0;i<q;i++){swap(qu[i].first,qu[i].second);}
sort(qu,qu+q);
ptr=q-1;
for(int i=n-1;i>=0;i--){
if(i==n-1)smin[i]=n;
else smin[i]=smin[i+1];
while(ptr>=0&&qu[ptr].first==i){
smin[i]=min(smin[i],qu[ptr].second);
ptr--;
}
}
int p[n];
for(int i=0;i<n;i++){scanf("%d",&p[i]);p[i]--;}
set<int> s[26];
for(int i=n-1;i>=0;i--){
int k=str[p[i]]-'a';
auto it=s[k].upper_bound(p[i]);
if(it!=s[k].end()){
int y=(*it);
if(pmax[p[i]]>=y){
printf("%d",i+1);
return 0;
}
}
if(it!=s[k].begin()){
--it; int x=(*it);
if(smin[p[i]]<=x){
printf("%d",i+1);
return 0;
}
}
s[k].insert(p[i]);
}
printf("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... |