답안 #167857

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
167857 2019-12-10T16:14:02 Z nikolapesic2802 Kralj (COCI16_kralj) C++14
84 / 140
820 ms 55160 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=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;
}

Compilation message

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]);
         ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 820 ms 48924 KB Output is correct
2 Correct 576 ms 47816 KB Output is correct
3 Correct 737 ms 54740 KB Output is correct
4 Correct 753 ms 55016 KB Output is correct
5 Incorrect 511 ms 34948 KB Output isn't correct
6 Correct 774 ms 55160 KB Output is correct
7 Incorrect 574 ms 38580 KB Output isn't correct
8 Incorrect 466 ms 37240 KB Output isn't correct
9 Incorrect 627 ms 39416 KB Output isn't correct
10 Correct 478 ms 35980 KB Output is correct