Submission #949603

#TimeUsernameProblemLanguageResultExecution timeMemory
949603ace5Rope (JOI17_rope)C++17
100 / 100
804 ms81748 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1000001; vector<int> cc[maxn]; int us[maxn]; int a[maxn]; int u[maxn]; int me[maxn]; int ans[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n,m; cin >> n >> m; for(int j = 0;j < n;++j) { cin >> a[j]; a[j]--; cc[a[j]].push_back(j); } for(int j = 0;j < m;++j) { me[j] = j; u[j] = cc[j].size(); ans[j] = n+1; } sort(me,me+m,[&](int a,int b){return u[a] > u[b];}); if(m == 1) { cout << 0; return 0; } for(int j = 0;j < m;++j) { us[j] = 1; int op = u[j]; int xx = 0; for(int k = 0;k < cc[j].size();++k) { if(cc[j][k] == n-1 && n%2 == 1) break; int pr = a[cc[j][k]^1]; us[pr] = 1; u[pr]--; } for(int k = 0;k < cc[j].size();++k) { if(cc[j][k] == n-1 && n%2 == 1) break; int pr = a[cc[j][k]^1]; if(pr != j) xx = max(xx,u[pr]); } for(int j = 0;j < m;++j) { if(!us[me[j]]) { xx = max(xx,u[me[j]]); break; } } ans[j] = min(ans[j],n-op-xx); for(int k = 0;k < cc[j].size();++k) { if(cc[j][k] == n-1 && n%2 == 1) break; int pr = a[cc[j][k]^1]; us[pr] = 0; u[pr]++; } us[j] = 0; } for(int j = 0;j < m;++j) { us[j] = 1; int op = u[j]; int xx = 0; 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 = a[((cc[j][k]-1)^1)+1]; us[pr] = 1; u[pr]--; } 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 = a[((cc[j][k]-1)^1)+1]; if(pr != j) xx = max(xx,u[pr]); } for(int j = 0;j < m;++j) { if(!us[me[j]]) { xx = max(xx,u[me[j]]); break; } } ans[j] = min(ans[j],n-op-xx); 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 = a[((cc[j][k]-1)^1)+1]; us[pr] = 0; u[pr]++; } us[j] = 0; cout << ans[j] << "\n"; } return 0; }

Compilation message (stderr)

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