Submission #20962

#TimeUsernameProblemLanguageResultExecution timeMemory
20962kdh9949Rope (JOI17_rope)C++14
100 / 100
1816 ms135280 KiB
#include <bits/stdc++.h> using namespace std; const int sz = 1048576; struct Seg{ int dat[2 * sz]; void upd(int x, int v){ x += sz - 1; dat[x] += v; for(x /= 2; x; x /= 2) dat[x] = max(dat[2 * x], dat[2 * x + 1]); } int get(){ return dat[1]; } } S; int n, m, a[1000010], b[1000010][2], c[1000010]; vector<int> d[1000010][2]; int main(){ scanf("%d%d", &n, &m); for(int i = 1; i <= n; i++) scanf("%d", a + i); for(int i = 1; i <= n; i++){ for(int j = 0; j < 2; j++){ int nx = i + 1 - (i + j) % 2 * 2; if(a[nx] && a[nx] != a[i]) d[a[i]][j].push_back(a[nx]); } S.upd(a[i], 1); c[a[i]]++; } for(int i = 1; i <= m; i++){ S.upd(i, -c[i]); int ans = n; for(int j = 0; j < 2; j++){ for(auto &k : d[i][j]) S.upd(k, -1); ans = min(ans, n - c[i] - S.get()); for(auto &k : d[i][j]) S.upd(k, 1); } S.upd(i, c[i]); printf("%d\n", ans); } }

Compilation message (stderr)

rope.cpp: In function 'int main()':
rope.cpp:18:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
                       ^
rope.cpp:19:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= n; i++) scanf("%d", a + i);
                                                ^

#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...