Submission #363942

#TimeUsernameProblemLanguageResultExecution timeMemory
363942Vladth11Arranging Shoes (IOI19_shoes)C++14
100 / 100
292 ms207596 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define debug(x) cerr << #x << " " << x << "\n" #define debug_with_space(x) cerr << #x << " " << x << " " //#include "shoes.h" using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair <ll, ll> pii; typedef pair <ll, pii> piii; typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> OST; const ll NMAX = 300001; const ll INF = (1LL << 30); const ll MOD = 1000000007; const ll BLOCK = 101; const ll nr_of_bits = 35; queue <int> pz[NMAX]; int v[NMAX]; int aib[NMAX]; int n; void update(int x, int v){ for(int i = x; i <= n; i += i&(-i)) aib[i] += v; } int query(int x){ int v = 0; for(int i = x; i > 0; i -= i&(-i)) v += aib[i]; return v; } int cod(int x){ if(x > 0) return x + n; else return -x; } long long count_swaps(vector<int> s) { n = s.size(); for(int i = 0; i < s.size(); i++){ v[i + 1] = s[i]; pz[cod(v[i + 1])].push(i + 1); update(i + 1, 1); } ll sol = 0; for(int i = 1; i <= n; i++){ if(pz[cod(v[i])].front() != i) continue; pz[cod(v[i])].pop(); if(v[i] < 0) update(i, -1); int cn = pz[cod(-v[i])].front(); pz[cod(-v[i])].pop(); update(cn, -1); sol += 1LL * query(cn); if(v[i] > 0) update(i, -1); } return sol; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     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...