제출 #420458

#제출 시각아이디문제언어결과실행 시간메모리
420458QCFiumArranging Shoes (IOI19_shoes)C++14
100 / 100
436 ms27172 KiB
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } struct SegTree { int n; std::vector<int> data; SegTree (int n_) { for (n = 1; n < n_; n <<= 1); data.resize(n << 1); for (int i = 0; i < n_; i++) data[i + n] = 1; for (int i = n; --i; ) data[i] = data[i << 1] + data[i << 1 | 1]; } void add(int i, int val) { for (i += n; i; i >>= 1) data[i] += val; } int sum(int l, int r) { int res = 0; for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (r & 1) res += data[--r]; if (l & 1) res += data[l++]; } return res; } }; long long count_swaps(std::vector<int> a) { int n = a.size(); std::map<int, std::vector<int> > index; for (int i = 0; i < n; i++) index[a[i]].push_back(i); for (auto &i : index) std::reverse(i.second.begin(), i.second.end()); SegTree tree(n); std::vector<bool> alive(n, true); int64_t res = 0; for (int i = 0; i < n; i++) { if (!alive[i]) continue; int t = index[-a[i]].back(); index[-a[i]].pop_back(); index[a[i]].pop_back(); alive[i] = false; alive[t] = false; tree.add(i, -1); tree.add(t, -1); res += tree.sum(i, t); if (a[i] > 0) res++; } return res; }

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

shoes.cpp: In function 'int ri()':
shoes.cpp:5:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...