Submission #583488

#TimeUsernameProblemLanguageResultExecution timeMemory
583488lcjArranging Shoes (IOI19_shoes)C++17
0 / 100
1130 ms627276 KiB
#include <bits/stdc++.h> #define LSOne(s) ((s) & -(s)) using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; struct FenwickTree { vector<ll> ft; FenwickTree(int n) : ft(n+1) {} ll rsq(int i) { ll su = 0; for (; i > 0; i -= LSOne(i)) { su += ft[i]; } } ll rsq(int i, int j) { return rsq(j)-rsq(i-1); } void update(int i, int dv) { for (; i < (int)ft.size(); i += LSOne(i)) { ft[i] += dv; } } }; ll count_swaps(std::vector<int> s) { FenwickTree ft(s.size()); map<int, int> open; int csum = 0; for (int i = 0; i < s.size(); i++) { if (open.find(-s[i]) != open.end()) { csum += i-open[-s[i]]-1 + (s[i] < 0) - ft.rsq(open[-s[i]]+1, i+1); ft.update(i, 1); open.erase(-s[i]); } else { open[s[i]] = i; } } return csum; }

Compilation message (stderr)

shoes.cpp: In member function 'll FenwickTree::rsq(int)':
shoes.cpp:18:5: warning: no return statement in function returning non-void [-Wreturn-type]
   18 |     }
      |     ^
shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:33:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (int i = 0; i < s.size(); 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...