Submission #128063

#TimeUsernameProblemLanguageResultExecution timeMemory
128063EntityITRope (JOI17_rope)C++14
80 / 100
2581 ms174228 KiB
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back using ii = pair<int, int>; int n, m; vector<int> c, cnt; vector< vector<int> > vec[2]; set<ii> rem; void upd (int col, int val) { rem.erase( { cnt[col], col } ); cnt[col] += val; rem.insert( { cnt[col], col } ); } int solve (int col, bool _) { int cnt_rem = n - cnt[col]; for (int _col : vec[_][col]) upd (_col, -1), --cnt_rem; rem.erase( { cnt[col], col } ); if (rem.size() ) cnt_rem -= (*rem.rbegin() ).fi; rem.insert( { cnt[col], col } ); for (int _col : vec[_][col]) upd (_col, 1); return cnt_rem + (int)vec[_][col].size(); } int main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; cnt.assign(m, 0); c.assign(n, 0); for (int i = 0; i < n; ++i) cin >> c[i], --c[i], ++cnt[ c[i] ]; for (int _ = 0; _ < 2; ++_) { vec[_].assign(m, vector<int>() ); for (int i = _; i + 1 < n; i += 2) { if (c[i] != c[i + 1]) { vec[_][ c[i] ].pb(c[i + 1]); vec[_][ c[i + 1] ].pb(c[i]); } } } for (int col = 0; col < m; ++col) rem.insert( { cnt[col], col } ); for (int col = 0; col < m; ++col) cout << min(solve(col, 0), solve(col, 1) ) << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...