Submission #670484

# Submission time Handle Problem Language Result Execution time Memory
670484 2022-12-09T08:38:33 Z Mahdi Rope (JOI17_rope) C++17
0 / 100
13 ms 23764 KB
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> pii;
const int N=1e6+5;
int n, m, c[N], cnt[N], ans[N];
vector<int>v[N];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;++i){
        cin>>c[i];
        v[c[i]].push_back(i);
        ++cnt[c[i]];
    }
    set<pii>st;
    for(int i=1;i<=m;++i)
        st.insert({cnt[i], i});
    for(int i=1;i<=m;++i){
        st.erase({cnt[i], i});
        vector<int>w;
        for(int u: v[i]){
            int z=u+((u&1) ? -1 : 1);
            if(z>0 && z<=n && c[z]!=i){
                st.erase({cnt[c[z]], c[z]});
                w.push_back(c[z]);
                --cnt[c[z]];
                st.insert({cnt[c[z]], c[z]});
            }
        }
        auto it=st.end();
        --it;
        ans[i]=cnt[i]+it->F;
        for(int u: w){
            st.erase({cnt[u], u});
            ++cnt[u];
            st.insert({cnt[u], u});
        }
        w.clear();
        for(int u: v[i]){
            int z=u+((u&1) ? 1 : -1);
            if(z>0 && z<=n && c[z]!=i){
                st.erase({cnt[c[z]], c[z]});
                w.push_back(c[z]);
                --cnt[c[z]];
                st.insert({cnt[c[z]], c[z]});
            }
        }
        it=st.end();
        --it;
        ans[i]=max(ans[i], cnt[i]+it->F);
        for(int u: w){
            st.erase({cnt[u], u});
            ++cnt[u];
            st.insert({cnt[u], u});
        }
        st.insert({c[i], i});
    }
    for(int i=1;i<=m;++i)
        cout<<n-ans[i]<<'\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -