This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#ifdef local
#define debug(...) qqbx(#__VA_ARGS__, __VA_ARGS__)
template <typename H, typename ...T> void qqbx(const char *s, const H& h, T &&...args) {
for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s;
std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n");
if constexpr(sizeof...(T)) qqbx(++s, args...);
}
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define pb emplace_back
#define all(v) begin(v),end(v)
using namespace std;
vector<pair<int,int>> TransferSE(int S[], int E[], int c, int n) {
vector<int> qq(n, 1);
vector<int> mx(n);
iota(all(mx), 0);
vector<pair<int,int>> res;
for(int i = 0; i < c; i++) {
int cnt = 0;
int L = -1, R = -1;
for(int j = 0; j < n; j++) if(qq[j]) {
if(cnt == S[i]) L = j;
else if(cnt == E[i]) R = mx[j];
++cnt;
}
for(int j = L+1; j <= R; j++) qq[j] = 0;
mx[L] = mx[R];
debug(L, R);
assert(L!=-1 && R!=-1);
res.pb(L, R);
}
return res;
}
int GetBestPosition(int n, int C, int X, int *K, int *S, int *E) {
auto segs = TransferSE(S, E, C, n);
safe;
vector<tuple<int,bool,int,int>> evt;
for(int i = 0; i < C; i++) {
auto [l, r] = segs[i];
int mx = -1;
for(int j = l; j < r; j++) mx = max(mx, K[j]);
debug(l, r, mx);
evt.pb(l, 1, i, mx);
evt.pb(r, 0, i, mx);
}
sort(all(evt));
int mx = -1, mxpos = -1;
set<int> s1, s2;
for(int i = 0, j; i < evt.size(); i = j) {
for(j = i; j < evt.size(); j++) {
if(get<0>(evt[i]) != get<0>(evt[j])) break;
auto [_, t, pos, val] = evt[j];
if(t) {
if(val > X) s1.insert(pos);
s2.insert(pos);
} else {
if(val > X) s1.erase(pos);
s2.erase(pos);
}
}
int firstLose = s1.size() ? *s1.begin() : C;
int pos = get<0>(evt[i]);
debug(firstLose, pos);
int win = 0;
for(int x: s2) if(x < firstLose) ++win;
if(win > mx) {
mx = win;
mxpos = get<0>(evt[i]);
}
}
return mxpos;
}
Compilation message (stderr)
tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:55:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, bool, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int i = 0, j; i < evt.size(); i = j) {
| ~~^~~~~~~~~~~~
tournament.cpp:56:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, bool, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(j = i; j < evt.size(); j++) {
| ~~^~~~~~~~~~~~
tournament.cpp:68:13: warning: unused variable 'pos' [-Wunused-variable]
68 | int pos = get<0>(evt[i]);
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |