Submission #210953

#TimeUsernameProblemLanguageResultExecution timeMemory
2109532qbingxuanArranging Shoes (IOI19_shoes)C++14
45 / 100
257 ms273568 KiB
//#include "shoes.h" #include <bits/stdc++.h> using namespace std; deque<int> vv[400001]; long long count_swaps(std::vector<int> s) { { int n = 0; vector<int> id(s.size()); for(int i = 0; i < s.size(); i++) if(s[i] < 0) { id[i] = n++; id[i] = id[i] * 2 + 1; vv[-s[i]].push_back(id[i]); } for(int i = 0; i < s.size(); i++) if(s[i] > 0) { id[i] = vv[s[i]].front() + 1; vv[s[i]].pop_front(); } s = id; } //for(int x: s) cout << x << ' '; cout << '\n'; std::reverse(s.begin(), s.end()); std::vector<int> BIT(s.size()+1); auto query = [&BIT](int p){ int res = 0; for(; p>0; p-=p&-p) res += BIT[p]; return res; }; auto add = [&BIT](int p){ for(; p<BIT.size(); p+=p&-p) ++BIT[p]; }; long long ans = 0; for(int x: s) ans += query(x-1), add(x); return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:11:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < s.size(); i++) if(s[i] < 0) {
                        ~~^~~~~~~~~~
shoes.cpp:16:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < s.size(); i++) if(s[i] > 0) {
                        ~~^~~~~~~~~~
shoes.cpp: In lambda function:
shoes.cpp:31:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(; p<BIT.size(); p+=p&-p) ++BIT[p];
               ~^~~~~~~~~~~
#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...