Submission #768898

#TimeUsernameProblemLanguageResultExecution timeMemory
768898emad234Arranging Shoes (IOI19_shoes)C++17
100 / 100
331 ms33144 KiB
#include <bits/stdc++.h> #define aint(v) ((v).bvin(),(v).end()) #define ll long long #define F first #define S second using namespace std; const int mod = 1e9 + 7; const int mxN = 8e6 + 1; bool vis[mxN]; int seg[mxN]; int st,e,N; int query(int l = 1,int r = N,int ind = 1){ if(l > e || r < st) return 0; if(l >= st && r <= e) return seg[ind]; int md = (l + r) / 2; return query(l,md,ind * 2) + query(md + 1,r,ind * 2 + 1); } void update(int ind){ ind += N; seg[ind] = 1; ind /= 2; while(ind){ seg[ind] = seg[ind * 2] + seg[ind * 2 + 1]; ind /= 2; } } map<int,set<int>>mp; ll count_swaps(vector<int> s) { ll ans = 0; N = exp2(ceil(log2(s.size()))); for(int i = 0;i < s.size();i++){ mp[s[i]].insert(i); } for(int i = 0;i < s.size();i++){ if(vis[i]) continue; ans += (s[i] > 0); auto x = *(mp[s[i] * -1].begin()); mp[s[i] * -1].erase(mp[s[i] * -1].begin()); mp[s[i]].erase(mp[s[i]].begin()); vis[i] = 1; vis[x] = 1; st = i + 1;e = x + 1; ans -= query(); // cout<<query()<<' '; ans += x - i - 1; update(i); update(x); } return ans; } // // int main() { // int n; // assert(1 == scanf("%d", &n)); // vector<int> S(2 * n); // for (int i = 0; i < 2 * n; i++) // assert(1 == scanf("%d", &S[i])); // fclose(stdin); // // long long result = count_swaps(S); // // printf("%lld\n", result); // fclose(stdout); // return 0; // }

Compilation message (stderr)

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