Submission #423590

#TimeUsernameProblemLanguageResultExecution timeMemory
423590schseArranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms204 KiB
#include "shoes.h" #ifndef EVAL #include "grader.cpp" #endif #include <bits/stdc++.h> using namespace std; struct segtree { int N; vector<int> tree; int upd(int index, int b, int e, int l, int r) { if (l <= b && e <= r) return ++tree[index]; if (r <= b || e <= l) return tree[index]; return upd(index * 2, b, (e + b) / 2, l, r) + upd(index * 2 + 1, (e + b) / 2, e, l, r); } void upd(int l, int r) { upd(1, 0, N, l, r); } int query(int index, int b, int e, int pos, int cary) { tree[index] += cary; if (pos = b || e <= pos) return 0; if (e - b == 1) return tree[index]; tree[index] = 0; return query(index * 2, b, (e + b) / 2, pos, tree[index]) + query(index * 2 + 1, (e + b) / 2, e, pos, tree[index]); } int query(int pos) { int r = query(1, 0, N, pos, 0); return r; } } tree; long long count_swaps(std::vector<int> s) { tree.N = s.size(); tree.tree.resize(tree.N * 4 + 5); vector<int> posadd(s.size()); vector<bool> sorted(s.size(), false); vector<queue<int>> pleft(s.size() + 1), pright(s.size() + 1); iota(posadd.begin(), posadd.end(), 0); long long numswaps = 0; for (int i = 0; i < s.size(); i++) (s[i] > 0 ? pright : pleft)[abs(s[i])].push(i); for (int e, i = 0; i < s.size(); i++) { if (sorted[i]) continue; (s[i] > 0 ? pright : pleft)[abs(s[i])].pop(); e = (s[i] < 0 ? pright : pleft)[abs(s[i])].front(); (s[i] < 0 ? pright : pleft)[abs(s[i])].pop(); sorted[i] = sorted[e] = true; tree.upd(i + 1, e); numswaps += (e + tree.query(e)) - (i + tree.query(i)) - 1; if (s[i] > 0) numswaps++; } return numswaps; }

Compilation message (stderr)

shoes.cpp: In member function 'int segtree::query(int, int, int, int, int)':
shoes.cpp:29:11: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   29 |   if (pos = b || e <= pos)
      |       ~~~~^~~~~~~~~~~~~~~
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:57:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  for (int i = 0; i < s.size(); i++)
      |                  ~~^~~~~~~~~~
shoes.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |  for (int e, 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...