Submission #949558

#TimeUsernameProblemLanguageResultExecution timeMemory
949558ace5Rope (JOI17_rope)C++17
80 / 100
2571 ms121716 KiB
#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)

rope.cpp: In function 'int main()':
rope.cpp:31:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for(int k = 0;k < cc[j].size();++k)
      |                       ~~^~~~~~~~~~~~~~
rope.cpp:43:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for(int k = 0;k < cc[j].size();++k)
      |                       ~~^~~~~~~~~~~~~~
rope.cpp:56:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for(int k = 0;k < cc[j].size();++k)
      |                       ~~^~~~~~~~~~~~~~
rope.cpp:70:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for(int k = 0;k < cc[j].size();++k)
      |                       ~~^~~~~~~~~~~~~~
#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...