Submission #297896

#TimeUsernameProblemLanguageResultExecution timeMemory
297896erd1Arranging Shoes (IOI19_shoes)C++14
10 / 100
1 ms384 KiB
#include "shoes.h"
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
typedef int64_t lld;
typedef pair<int, int> pii;

#include<bits/extc++.h>
using namespace __gnu_pbds;
template<typename T, typename comp = greater<T>>
using OST = tree<T, null_type, comp, rb_tree_tag, tree_order_statistics_node_update>;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> p){
	return out << "(" << p.ff << ", " << p.ss << ")";
}

map<int, int> cnt;
map<pii, int> mp;

OST<int> ost;

long long count_swaps(vector<int> s) {
	lld ans = 0, id;
	for(int i = 0; i < s.size(); i++)if(s[i] < 0)mp[{s[i], cnt[s[i]]++}] = i;
	for(int i = 0; i < s.size(); i++)if(s[i] > 0)ans += abs(i-mp[{-s[i], cnt[s[i]]}])-(i > mp[{-s[i], cnt[s[i]]}]), cnt[s[i]]++;
	return ans;
}

// x > y => x-y-1, x < y => y-x

Compilation message (stderr)

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(s[i] < 0)mp[{s[i], cnt[s[i]]++}] = i;
      |                 ~~^~~~~~~~~~
shoes.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for(int i = 0; i < s.size(); i++)if(s[i] > 0)ans += abs(i-mp[{-s[i], cnt[s[i]]}])-(i > mp[{-s[i], cnt[s[i]]}]), cnt[s[i]]++;
      |                 ~~^~~~~~~~~~
shoes.cpp:27:15: warning: unused variable 'id' [-Wunused-variable]
   27 |  lld ans = 0, id;
      |               ^~
#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...