제출 #167857

#제출 시각아이디문제언어결과실행 시간메모리
167857nikolapesic2802Kralj (COCI16_kralj)C++14
84 / 140
820 ms55160 KiB
#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) 메시지

kralj.cpp: In function 'int main()':
kralj.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
kralj.cpp:45:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&a),a--,siz[a]++,pwrs[a].pb(i);
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
kralj.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&p[i]);
         ~~~~~^~~~~~~~~~~~
kralj.cpp:49:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&v[i]);
         ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...