# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
579827 | AGE | Grudanje (COCI19_grudanje) | C++14 | 114 ms | 9220 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>
#define F first
#define S second
#define int long long
#define pb push_back
using namespace std;
const int N=1e6,M=2e3+1,mod=1e9+7;
pair<int,int>a[N];
multiset<int>st[26];
int ans[N];
main(){
string s;
cin>>s;
s='.'+s;
int q;
cin>>q;
int n=q,i=0;
while(q--){
cin>>a[i].F>>a[i].S;
i++;
}
for(int i=0;i<s.size()-1;i++){
int x;
cin>>x;
ans[x]=i+1;
}
sort(a,a+n);
int lst=0,Final_ans=0;
int l=1,r=1;
for(int i=0;i<n;i++){
if(r>a[i].S)
continue;
while(r<=a[i].S){
st[s[r]-'a'].insert(ans[r]);
r++;
}
while(l<a[i].F){
st[s[l]-'a'].erase(ans[l]);
l++;
}
for(int j=0;j<26;j++){
if(st[j].size()<=1)
continue;
int x=*st[j].rbegin();
st[j].erase(st[j].find(*st[j].rbegin()));
Final_ans=max(*st[j].rbegin(),Final_ans);
st[j].insert(x);
/*cout<<i<<" "<<j<<": ";
for(auto x:st[j])
cout<<x<<" ";
cout<<endl;*/
}
}
cout<<Final_ans<<endl;
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... |