# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
650061 | 2022-10-12T08:07:16 Z | boris_mihov | Bubble Sort 2 (JOI18_bubblesort2) | C++17 | 261 ms | 724 KB |
#include "bubblesort2.h" #include <algorithm> #include <iostream> #include <numeric> #include <vector> typedef long long llong; const int MAXN = 500000 + 10; const int INF = 1e9; int a[MAXN], n; std::vector <int> ans; llong inv; void add(int idx, int value) { for (int i = idx - 1 ; i >= 1 ; --i) { inv += (a[i] > a[idx]); } for (int i = idx + 1 ; i <= n ; ++i) { inv += (a[idx] > a[i]); } } void remove(int idx, int value) { for (int i = idx - 1 ; i >= 1 ; --i) { inv -= (a[i] > a[idx]); } for (int i = idx + 1 ; i <= n ; ++i) { inv -= (a[idx] > a[i]); } } std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V) { n = A.size(); for (int i = 1 ; i <= n ; ++i) a[i] = A[i-1]; inv = 0; for (int i = 1 ; i <= n ; ++i) { for (int j = i + 1 ; j <= n ; ++j) { inv += (a[i] > a[j]); } } ans.resize(X.size()); for (int i = 0 ; i < X.size() ; --i) { remove(X[i] + 1, a[X[i] + 1]); a[X[i] + 1] = V[i]; add(X[i] + 1, a[X[i] + 1]); ans[i] = inv; } return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 261 ms | 724 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |