Submission #1106403

#TimeUsernameProblemLanguageResultExecution timeMemory
1106403VinhLuuBubble Sort 2 (JOI18_bubblesort2)C++17
17 / 100
9065 ms6992 KiB
#include <bits/stdc++.h> #define ll long long #include "bubblesort2.h" using namespace std; const int N = 1e6 + 5; int n, q, a[N], _x[N], _y[N], kq[N]; namespace sub1{ int b[N]; vector<int> solve(){ vector<int> ans; for(int k = 1; k <= q; k ++){ int x = _x[k], y = _y[k]; a[x] = y; int cnt = 0; for(int i = 1; i <= n; i ++) b[i] = a[i]; while(true){ bool ff = true; for(int i = 1; i < n; i ++) if(b[i] > b[i + 1]){ swap(b[i], b[i + 1]); ff = false; } if(ff) break; cnt++; } ans.push_back(cnt); } return ans; } } std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){ n = A.size(); for(int i = 0; i < n; i ++) a[i + 1] = A[i]; q = X.size(); for(int k = 0; k < q; k ++){ _x[k + 1] = X[k] + 1, _y[k + 1] = V[k]; } return sub1 :: solve(); int ans = 0; std::vector<int> answer(q); for(int j = 0; j < q; j ++) { answer[j] = kq[j]; } return answer; } //#define LOCAL #ifdef LOCAL int _n, _q; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "v" if(fopen(task ".inp","r")){ freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); } cin >> _n >> _q; std::vector<int> A(_n); for(int i = 0; i < _n; i ++) cin >> A[i]; std::vector<int> X(_q),V(_q); for(int j = 0; j < _q ; j++){ cin >> X[j] >> V[j]; } std::vector<int> res=countScans(A,X,V); for(int j=0;j<int(res.size());j++) cout << res[j] << "\n"; } /* 4 2 1 2 3 4 0 3 2 1 */ #endif // LOCAL

Compilation message (stderr)

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:48:7: warning: unused variable 'ans' [-Wunused-variable]
   48 |   int ans = 0;
      |       ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...