# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
167857 | nikolapesic2802 | Kralj (COCI16_kralj) | C++14 | 820 ms | 55160 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
const int N=5e5+5;
vector<int> par(N),siz(N),p(N),v(N);
vector<vector<int> > pwrs(N);
int find(int tr){return tr==par[tr]?tr:par[tr]=find(par[tr]);}
void merge(int a,int b){
a=find(a);
b=find(b);
if(a==b)
return;
siz[a]+=siz[b];
par[b]=a;
}
int main()
{
iota(all(par),0);
int n,a;
scanf("%i",&n);
for(int i=0;i<n;i++)
scanf("%i",&a),a--,siz[a]++,pwrs[a].pb(i);
for(int i=0;i<n;i++)
scanf("%i",&p[i]);
for(int i=0;i<n;i++)
scanf("%i",&v[i]);
for(int i=0;i<n;i++){
if(find(i)!=i)
continue;
for(int j=1;j<siz[i];j++)
merge(i,(i+j)%n);
}
int ans=0;
for(int i=0;i<n;i++)
if(find(i)==i)
{
set<int> st;
for(int j=siz[i]-1;j>=0;j--){
st.insert(p[(i+j)%n]);
for(auto p:pwrs[(i+j)%n]){
auto it=st.lower_bound(v[p]);
if(it!=st.begin()){
it--;
ans++;
st.erase(it);
}
}
}
}
printf("%i\n",ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |