Submission #296607

#TimeUsernameProblemLanguageResultExecution timeMemory
296607zoooma13Arranging Shoes (IOI19_shoes)C++14
100 / 100
450 ms25976 KiB
#include "bits/stdc++.h" #include "shoes.h" using namespace std; vector <int> bit; void upd(int idx){ for(int i=idx+5; i<bit.size(); i+=(i&-i)) bit[i] += 1; } int ask(int idx){ int ret = 0; for(int i=idx+5; i; i-=(i&-i)) ret += bit[i]; return ret; } int qry(int l ,int r){ return r < l? 0 : r-l+1 - ask(r)+ask(l-1); } long long count_swaps(vector<int> s) { bit.resize((int)s.size() + 13); map <int ,vector<int>> mp; for(int i=(int)s.size()-1; ~i; i--) mp[s[i]].push_back(i); long long ans = 0; for(int i=0; i<s.size(); i++) if(qry(i ,i)){ int x = s[i]; mp[x].pop_back(); int y_idx = mp[-x].back(); mp[-x].pop_back(); upd(i) ,upd(y_idx); ans += qry(i+1 ,y_idx-1)+(x > 0); } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'void upd(int)':
shoes.cpp:7:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |     for(int i=idx+5; i<bit.size(); i+=(i&-i))
      |                      ~^~~~~~~~~~~
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:28:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i=0; i<s.size(); i++) if(qry(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...