제출 #826778

#제출 시각아이디문제언어결과실행 시간메모리
826778kevinsogoArranging Shoes (IOI19_shoes)C++17
100 / 100
875 ms34392 KiB
#include <bits/stdc++.h> using namespace std; #include "shoes.h" using ll = long long; struct Seg { int i, j; int s = 0; Seg *l, *r; Seg(int i, int j): i(i), j(j) { if (j - i == 1) { l = r = nullptr; } else { int k = i + j >> 1; l = new Seg(i, k); r = new Seg(k, j); } } void inc(int I) { if (i <= I and I < j) { s++; if (l) l->inc(I), r->inc(I); } } int sum(int I) { return j <= I ? s : I <= i ? 0 : l->sum(I) + r->sum(I); } }; ll count_swaps(vector<int> _seq) { vector<int> found(_seq.size() + 5); vector<ll> seq; for (int v : _seq) seq.push_back(ll(v) * _seq.size() + ((v > 0) - (v < 0)) * found[v + (_seq.size() >> 1)]++); unordered_map<ll,int> pos; pos.max_load_factor(0.5); for (int i = 0; i < seq.size(); i++) pos[seq[i]] = i; sort(seq.rbegin(), seq.rend(), [&](ll i, ll j) { int d = min(pos[i], pos[-i]) - min(pos[j], pos[-j]); return d ? d < 0 : i < j; }); for (ll& v : seq) v = pos[v]; ll ans = 0; Seg s(0, seq.size()); for (ll v : seq) ans += s.sum(v), s.inc(v); return ans; }

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

shoes.cpp: In constructor 'Seg::Seg(int, int)':
shoes.cpp:14:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   14 |             int k = i + j >> 1;
      |                     ~~^~~
shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:35:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for (int i = 0; i < seq.size(); i++) pos[seq[i]] = i;
      |                     ~~^~~~~~~~~~~~
#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...