# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
623423 |
2022-08-05T14:52:03 Z |
inksamurai |
Kralj (COCI16_kralj) |
C++17 |
|
568 ms |
43264 KB |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3SgiE60 ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e
signed main(){
_3SgiE60;
int n;
cin>>n;
vi a(n);
rep(i,n){
cin>>a[i];
}
vi b(n);
rep(i,n){
cin>>b[i];
}
vi c(n);
rep(i,n){
cin>>c[i];
}
vec(vi) rbts(n);
rep(i,n){
a[i]-=1;
// print(c[i]);
rbts[a[i]].pb(c[i]);
}
vec(pii) evs;
rep(i,n){
int l=i;
int now=sz(rbts[i]);
while(now>1){
now-=1;
l+=1;
now+=sz(rbts[l%n]);
}
evs.pb(pii(i,l));
if(l>n){
break;
}else{
i=l;
}
}
int r=-1;
{
for(auto p:evs){
if(p.se>=n){
assert(r==-1);
r=p.se%n;
}
}
vec(pii) nevs;
for(auto p:evs){
if(p.fi<=r) continue;
nevs.pb(p);
}
evs=nevs;
}
auto af=[&](int l,int r){
// print(l,r);
int now=0;
set<int> st;
rng(i,l,r+1){
for(auto v:rbts[i%n]){
st.insert(v);
}
assert(sz(st));
auto it=st.lower_bound(b[i%n]);
if(it==st.end()){
st.erase(st.begin());
}else{
now+=1;
st.erase(it);
}
}
return now;
};
int res=0;
for(auto p:evs){
res+=af(p.fi,p.se);
}
print(res);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
568 ms |
34840 KB |
Output is correct |
2 |
Correct |
326 ms |
33992 KB |
Output is correct |
3 |
Correct |
428 ms |
42292 KB |
Output is correct |
4 |
Correct |
415 ms |
43264 KB |
Output is correct |
5 |
Correct |
259 ms |
19508 KB |
Output is correct |
6 |
Correct |
225 ms |
20104 KB |
Output is correct |
7 |
Correct |
296 ms |
23256 KB |
Output is correct |
8 |
Correct |
244 ms |
21684 KB |
Output is correct |
9 |
Correct |
318 ms |
24424 KB |
Output is correct |
10 |
Correct |
253 ms |
21804 KB |
Output is correct |