Submission #239621

#TimeUsernameProblemLanguageResultExecution timeMemory
239621ant101Arranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 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, 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 = N; i>=1; i--) { if (closest.find(-S[i]) != closest.end()) { closestind[i] = closest[-S[i]]; } closest[S[i]] = 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; } int main() { ios_base :: sync_with_stdio(false); cin.tie(nullptr); // cin >> N; // for (ll i = 1; i<=N; i++) cin >> S[i]; // for (ll i = N; i>=1; i--) { // if (closest.find(-S[i]) != closest.end()) { // closestind[i] = closest[-S[i]]; // } // closest[S[i]] = 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; // } // } // cout << ans << "\n"; return 0; }

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];
                    ~^~~~~~~~~
/tmp/ccpJcoAI.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccixhXPt.o:shoes.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status