Submission #239628

#TimeUsernameProblemLanguageResultExecution timeMemory
239628ant101Arranging Shoes (IOI19_shoes)C++14
100 / 100
690 ms153464 KiB
#include <iostream> #include <algorithm> #include <cstring> #include <iomanip> #include <fstream> #include <cmath> #include <vector> #include <set> #include <unordered_set> #include <unordered_map> #include <map> #include <stack> #include <queue> #include <assert.h> #include <limits> #include <cstdio> #include <shoes.h> using namespace std; //#define RDEBUG 1 #ifdef RDEBUG #define D(x) x #else #define D(x) #endif #define inf 0x7fffffff #define MOD 1000000007 typedef long long ll; ll add(ll a, ll b) { a += b; if(a >= MOD) { a -= MOD; } return a; } ll sub(ll a, ll b) { a -= b; if(a < 0) { a += MOD; } return a; } ll mul(ll a, ll b) { return (a * b)%MOD; } void add_self(ll& a, ll b) { a = add(a, b); } void sub_self(ll& a, ll b) { a = sub(a, b); } void mul_self(ll& a, ll b) { a = mul(a, b); } const ll MAXN = 200010; ll tree[MAXN]; ll N; void update(ll ind, ll num) { while (ind<=MAXN) { tree[ind]+=num; ind+=(ind&-ind); } } ll getsum(ll ind) { ll sum = 0; while (ind) { sum+=tree[ind]; ind-=(ind&-ind); } return sum; } map<ll, queue<ll>> closest; ll closestind[MAXN]; ll vis[MAXN]; ll S[MAXN]; long long count_swaps(std::vector<int> s) { N = s.size(); for (ll i = 0; i<s.size(); i++) S[i+1] = s[i]; for (ll i = 1; i<=N; i++) { if (closest.find(S[i]) == closest.end()) { queue<ll> q1; closest[S[i]] = q1; } if (closest.find(-S[i]) != closest.end() && closest[-S[i]].size() > 0) { closestind[closest[-S[i]].front()] = i; closest[-S[i]].pop(); } else { closest[S[i]].push(i); } } ll ans = 0; for (ll i = 1; i<=N; i++) { if (!vis[i]) { ans+=closestind[i]-i-1-(getsum(closestind[i])-getsum(i))+(S[i] > 0); update(closestind[i], 1); vis[closestind[i]] = 1; } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:90:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (ll i = 0; i<s.size(); i++) S[i+1] = s[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...