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 <iostream>
#include <stdio.h>
#include <fstream>
#include <string.h>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <set>
#include <deque>
#include <utility>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <math.h>
#include <algorithm>
#include <limits.h>
using namespace std ;
const int No = 2e5;
long long mx[10*No] ;
vector <long long> l, r ;
vector <pair<long long, long long>> in;
vector <long long> vals;
void update (int node, int lw, int rg, int a, long long v) {
if ( lw == a && rg == a ) {
mx[node] = v ;
return ;
}
int m = (lw + rg) >> 1 ;
if ( a <= m ) update ( node << 1, lw, m, a, v) ;
else update ( (node<<1) + 1, m+1, rg, a, v ) ;
mx[node] = max ( mx[node<<1], mx[(node<<1)+1] ) ;
}
long long query ( int node, int lw, int rg, int a, int b ) {
if ( b < lw || rg < a ) return 0 ;
if ( a <= lw && rg <= b ) return mx[node] ;
int m = (lw + rg) >> 1 ;
return max ( query(node<<1, lw, m, a, b), query ((node<<1)+1, m+1, rg, a, b) );
}
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) {
for ( int i = 0 ; i < N-1 ; ++i ) vals.push_back(K[i]) ;
pair <long long, long long> ans = {-1e17, -1};
for ( int i = 0 ; i < N ; ++i ) {
vector <long long> bf = vals ;
vals.insert (vals.begin() + i, R ) ;
int cur = 0 ;
for ( int i = 0 ; i < C ; ++i ) {
pair <long long, long long> incur = {-1e17, -1};
long long mxcur = -1e17 ;
for ( int j = S[i] ; j <= E[i] ; ++j ) {
mxcur = max ( mxcur, vals[S[i]] ) ;
vals.erase ( vals.begin() + S[i] ) ;
}
vals.insert (vals.begin() + S[i], mxcur ) ;
if ( vals[S[i]] == R ) cur++ ;
}
ans = max ( ans, {cur, -i}) ;
vals = bf ;
}
return -ans.second ;
}
Compilation message (stderr)
tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:56:37: warning: variable 'incur' set but not used [-Wunused-but-set-variable]
pair <long long, long long> incur = {-1e17, -1};
^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |