Submission #535152

#TimeUsernameProblemLanguageResultExecution timeMemory
535152devariaotaArranging Shoes (IOI19_shoes)C++17
10 / 100
2 ms3404 KiB
#include <bits/stdc++.h> #define REP(v, i, j) for (long long v = i; v < j; v++) #define FORI(v) for (auto i : v) #define FORJ(v) for (auto j : v) #define OUT(v, a) FORI(v) cout << i << a; #define OUTS(v, a, b) cout << v.size() << a; OUT(v, b) #define in(a, n) REP(i, 0, n) cin >> a[i]; #define SORT(v) sort(begin(v), end(v)) #define REV(v) reverse(begin(v), end(v)) #define pb push_back #define fi first #define se second #define detachIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); using namespace std; typedef pair<long long, long long> pii; typedef pair<pii, long long> piii; typedef pair<pii, pii> piiii; const long long MAXN = 100000; long long tree[MAXN * 4]; void update(long long l, long long r, long long idx, long long pos, long long val) { if (l == r) { tree[idx] = val; return; } long long m = (l + r) / 2; if (pos <= m) update(l, m, idx * 2, pos, val); else update(m + 1, r, idx * 2 + 1, pos, val); } long long get(long long l, long long r, long long idx, long long start, long long end) { if (r < start || l > end) return 0; if (start <= l && r <= end) return tree[idx]; long long m = (l + r) / 2; long long l1 = get(l, m, idx * 2, start, end); long long l2 = get(m + 1, r, idx * 2 + 1, start, end); return l1 + l2; } map<long long, queue<long long>> mp; long long count_swaps(vector<int> v) { memset(tree, 0, sizeof tree); long long ans = 0; REP(i, 0, v.size()) { if (mp[v[i]].size()) { auto &q = mp[v[i]]; auto x = mp[v[i]].front(); ans += i - x; ans -= get(1, v.size(), 1, x, i); if (v[i] > 0) ans--; update(1, v.size(), 1, i, 1); update(1, v.size(), 1, x, 1); q.pop(); } else mp[-v[i]].push(i); } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:2:46: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    2 | #define REP(v, i, j) for (long long v = i; v < j; v++)
......
   64 |     REP(i, 0, v.size())
      |         ~~~~~~~~~~~~~~                        
shoes.cpp:64:5: note: in expansion of macro 'REP'
   64 |     REP(i, 0, v.size())
      |     ^~~
#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...