Submission #419036

#TimeUsernameProblemLanguageResultExecution timeMemory
419036EncryptingWolfArranging Shoes (IOI19_shoes)C++14
50 / 100
230 ms52936 KiB
#include <vector> #include <iostream> #include <set> #include <map> using namespace std; typedef long long ll; #define FOR(i,x,y) for (ll i = x; i <y; i++) vector<ll> fenwick(100000); void update(ll i, ll a) { i++; while (i < fenwick.size()) { fenwick[i]+=a; i += (i&(-i)); } } ll sum(ll i) { i++; ll sum = 0; while (i > 0) { sum+=fenwick[i]; i -= (i&(-i)); } return sum; } ll count_swaps(vector<int> S) { vector<ll> reNum; map<ll,ll> count; FOR(i, 0, S.size()) { reNum.push_back((count[S[i]] * S.size()*(abs(S[i])/S[i]) + S[i])); count[S[i]]++; } vector<ll> reNum2; map<ll, ll> numMap2; ll available = 1; FOR(i, 0, S.size()) { auto a = numMap2[abs(reNum[i])]; if (a == 0) { numMap2[abs(reNum[i])] = available*2; if (reNum[i]<0) reNum2.push_back(available*2-1); else reNum2.push_back(available*2); available++; } else { if (reNum[i] < 0) reNum2.push_back(a - 1); else reNum2.push_back(a); } } ll total = 0; update(reNum2[S.size()-1], 1); for (ll i = S.size() - 2; i >= 0; i--) { total += sum(reNum2[i]); update(reNum2[i], 1); } return total; }

Compilation message (stderr)

shoes.cpp: In function 'void update(ll, ll)':
shoes.cpp:14:11: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  while (i < fenwick.size())
      |         ~~^~~~~~~~~~~~~~~~
shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:7:37: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define FOR(i,x,y) for (ll i = x; i <y; i++)
......
   38 |  FOR(i, 0, S.size())
      |      ~~~~~~~~~~~~~~                  
shoes.cpp:38:2: note: in expansion of macro 'FOR'
   38 |  FOR(i, 0, S.size())
      |  ^~~
shoes.cpp:7:37: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define FOR(i,x,y) for (ll i = x; i <y; i++)
......
   46 |  FOR(i, 0, S.size())
      |      ~~~~~~~~~~~~~~                  
shoes.cpp:46:2: note: in expansion of macro 'FOR'
   46 |  FOR(i, 0, S.size())
      |  ^~~
#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...