| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 949558 | ace5 | Rope (JOI17_rope) | C++17 | 2571 ms | 121716 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,m;
cin >> n >> m;
int a[n];
vector<vector<int>> cc(m);
set<pair<int,int>> ck;
for(int j = 0;j < n;++j)
{
cin >> a[j];
a[j]--;
cc[a[j]].push_back(j);
}
vector<int> u(m);
for(int j = 0;j < m;++j)
{
u[j] = cc[j].size();
}
for(int j = 0;j < m;++j)
ck.insert({-u[j],j});
vector<int> ans(m,n+1);
for(int j = 0;j < m;++j)
{
int op = u[j];
for(int k = 0;k < cc[j].size();++k)
{
if(cc[j][k] == n-1 && n%2 == 1)
break;
int pr = cc[j][k]^1;
ck.erase({-u[a[pr]],a[pr]});
u[a[pr]]--;
ck.insert({-u[a[pr]],a[pr]});
}
ck.erase({-u[j],j});
ans[j] = min(ans[j],(ck.size() == 0 ? 0 : n-op+(*ck.begin()).first));
ck.insert({-u[j],j});
for(int k = 0;k < cc[j].size();++k)
{
if(cc[j][k] == n-1 && n%2 == 1)
break;
int pr = cc[j][k]^1;
ck.erase({-u[a[pr]],a[pr]});
u[a[pr]]++;
ck.insert({-u[a[pr]],a[pr]});
}
}
for(int j = 0;j < m;++j)
{
int op = u[j];
for(int k = 0;k < cc[j].size();++k)
{
if(cc[j][k] == n-1 && n%2 == 0)
break;
if(cc[j][k] == 0)
continue;
int pr = ((cc[j][k]-1)^1)+1;
ck.erase({-u[a[pr]],a[pr]});
u[a[pr]]--;
ck.insert({-u[a[pr]],a[pr]});
}
ck.erase({-u[j],j});
ans[j] = min(ans[j],(ck.size() == 0 ? 0 : n-op+(*ck.begin()).first));
ck.insert({-u[j],j});
for(int k = 0;k < cc[j].size();++k)
{
if(cc[j][k] == n-1 && n%2 == 0)
break;
if(cc[j][k] == 0)
continue;
int pr = ((cc[j][k]-1)^1)+1;
ck.erase({-u[a[pr]],a[pr]});
u[a[pr]]++;
ck.insert({-u[a[pr]],a[pr]});
}
cout << ans[j] << "\n";
}
}
Compilation message (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... | ||||
