Submission #894677

#TimeUsernameProblemLanguageResultExecution timeMemory
894677lunaTuBubble Sort 2 (JOI18_bubblesort2)C++17
0 / 100
18 ms4444 KiB
#include <bits/stdc++.h> #define ff first #define ss second #define all(x) x.begin(), x.end() #include "bubblesort2.h" typedef long long ll; using namespace std; const int N = 5e4 + 1; int A[N]; set<int> d[N]; set<int> s; int add(int n, int i, int x) { d[A[i]].erase(i); if (d[A[i]].empty()) s.erase(A[i]); d[x].insert(i); s.insert(x); int mx = 0, sum = 0, p = -1; for (auto e : s) { int j = *d[e].rbegin(); sum += d[e].size(); if (j > p) { mx = max(mx, j + 1 - sum); p = j; } } A[i] = x; //cout << mx << endl; return mx; } vector<int> countScans(vector<int> a, vector<int> x, vector<int> v) { int n = a.size(), q = x.size(); vector<int> b(n + q); for (int i = 0; i < n; i++) { b[i] = a[i]; } for (int i = n; i < n + q; i ++) { b[i] = v[i - n]; } sort(all(b)); int cnt = 1; map<int, int> r; for (auto e : b) { if (!r[e]) r[e] = cnt++; } for (int i = 0; i < n; i++) { int e = r[a[i]]; s.insert(e); d[e].insert(i); A[i] = e; } vector<int> answer(q); for (int j = 0; j < q; j++) { answer[j] = add(n, x[j], r[v[j]]); cout << answer[j] << endl; } return answer; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...