# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
167868 | 2019-12-10T16:37:41 Z | nikolapesic2802 | Kralj (COCI16_kralj) | C++14 | 828 ms | 47208 KB |
#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=0;j<siz[i];j++){ for(auto p:pwrs[(i+j)%n]) st.insert(v[p]); auto it=st.lower_bound(p[(i+j)%n]); if(it==st.end()) st.erase(st.begin()); else ans++,st.erase(it); } } printf("%i\n",ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 828 ms | 42676 KB | Output is correct |
2 | Correct | 536 ms | 42312 KB | Output is correct |
3 | Correct | 684 ms | 46436 KB | Output is correct |
4 | Correct | 706 ms | 47208 KB | Output is correct |
5 | Correct | 502 ms | 24988 KB | Output is correct |
6 | Correct | 419 ms | 25436 KB | Output is correct |
7 | Correct | 569 ms | 27896 KB | Output is correct |
8 | Correct | 445 ms | 28152 KB | Output is correct |
9 | Correct | 566 ms | 28280 KB | Output is correct |
10 | Correct | 495 ms | 25720 KB | Output is correct |