Submission #837589

#TimeUsernameProblemLanguageResultExecution timeMemory
837589LiudasRope (JOI17_rope)C++17
80 / 100
2540 ms171672 KiB
#include <bits/stdc++.h> using namespace std; int tree[1048576 * 2] = {0}; int N = 1048576; void update(int pos, int val){ int head = N + pos; tree[head] += val; head /= 2; while(head){ tree[head] = max(tree[head * 2 + 1], tree[head * 2]); head /= 2; } } int arr[1000050]; int main(){ int N, M; cin >> N >> M; for(int i = 0; i < N; i ++){ cin >> arr[i]; arr[i]--; } vector<vector<vector<int>>> brr(M + 5, vector<vector<int>>(2)); vector<int> counts(M + 5); for(int i = 0; i < N; i ++){ for(int j = 0; j < 2; j ++){ int pi = i + 1 - (i + j) % 2 * 2; if(pi > -1 && pi < N && arr[pi] != arr[i]){ brr[arr[i]][j].push_back(arr[pi]); } } counts[arr[i]] ++; update(arr[i], 1); } for(int i = 0; i < M; i ++){ update(i, -counts[i]); int ans = N; for(int j = 0; j < 2; j ++){ for(int &k : brr[i][j])update(k, -1); ans = min(ans, N-tree[1]-counts[i]); for(int &k : brr[i][j])update(k, 1); } update(i, counts[i]); cout << ans << endl; } }
#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...