| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 299458 | XmtosX | Rope (JOI17_rope) | C++17 | 2545 ms | 117840 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,m,a[N],cnt[N],ans[N],cnt1[N];
bool yes;
vector <int> v[N],V;
set<pair<int,int> > s;
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        cnt[a[i]]++;
        cnt1[a[i]]++;
        ans[a[i]]=n-cnt[i];
    }
    for (int i=1;i<=m;i++)
        s.insert({cnt[i],i});
    for (int o=0;o<2;o++)
    {
        for (int i=1;i<=m;i++)
            v[i].clear();
        if ((n-o)%2)
            yes=true;
        else
            yes=false;
        for (int i=o;i+1<n;i+=2)
        {
            v[a[i]].push_back(i);
            if (a[i]!=a[i+1])
                v[a[i+1]].push_back(i);
        }
        for (int i=1;i<=m;i++)
        {
            V.clear();
            int tot=n;
            if (o&&a[0]==i)
            {
                cnt1[i]--;
                V.push_back(i);
                tot--;
            }
            for (int j=0;j<v[i].size();j++)
            {
                int idx= v[i][j];
                if (cnt1[a[idx]]==cnt[a[idx]])
                    V.push_back(a[idx]);
                cnt1[a[idx]]--;
                tot-=(a[idx]==i);
                idx++;
                if (cnt1[a[idx]]==cnt[a[idx]])
                    V.push_back(a[idx]);
                cnt1[a[idx]]--;
                tot-=(a[idx]==i);
            }
            if (yes&&a[n-1]==i)
            {
                cnt1[i]--;
                if (cnt[i]==cnt1[i])
                    V.push_back(i);
                tot--;
            }
            for (int j=0;j<V.size();j++)
            {
                s.erase(make_pair(cnt[V[j]],V[j]));
                s.insert(make_pair(cnt1[V[j]],V[j]));
            }
            pair<int,int> p = *s.rbegin();
            ans[i]=min(ans[i],tot-p.first);
            for (int j=0;j<V.size();j++)
            {
                s.erase(make_pair(cnt1[V[j]],V[j]));
                s.insert(make_pair(cnt[V[j]],V[j]));
                cnt1[V[j]]=cnt[V[j]];
            }
        }
    }
    for (int i=1;i<=m;i++)
        printf("%d\n",ans[i]);
    return 0;
}
/*
5 3
1 2 3 3 2
7 3
1 2 2 1 3 3 3
10 3
2 2 1 1 3 3 2 1 1 2
*/
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
