제출 #476072

#제출 시각아이디문제언어결과실행 시간메모리
476072aris12345678Swap Swap Sort (CCO21_day1problem1)C++14
6 / 25
5074 ms2424 KiB
#include <bits/stdc++.h> using namespace std; const int mxN = 100005; int arr[mxN], bit[mxN], posi[mxN], po[mxN]; void upd(int pos, int n, int val) { while(pos <= n) { bit[pos] += val; pos += (pos&(-pos)); } } long long ask(int pos) { long long ans = 0; while(pos > 0) { ans += 1LL*bit[pos]; pos -= (pos&(-pos)); } return ans; } int main() { int n, k, q; scanf("%d %d %d", &n, &k, &q); for(int i = 1; i <= n; i++) { scanf("%d", &arr[i]); posi[i] = i, po[i] = i; } while(q--) { int t; scanf("%d", &t); swap(posi[t], posi[t+1]); po[posi[t]]--, po[posi[t+1]]++; // cout << posi[t] << " " << po[posi[t]] << " " << posi[t+1] << " " << po[posi[t+1]] << "\n"; fill(bit, bit+mxN, 0); long long ans = 0; for(int i = 1; i <= n; i++) { upd(po[arr[i]], n, 1); ans += (ask(n)-ask(po[arr[i]])); // cout << arr[i] << " " << po[arr[i]] << " " << ans << "\n"; // cout << posi[i] << " " << po[posi[i]] << "\n"; } // cout << "\n"; printf("%lld\n", ans); } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%d %d %d", &n, &k, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         scanf("%d", &arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
Main.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         scanf("%d", &t);
      |         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...