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> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define sz(x) (int)((x).size())
//#define int long long
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const ll inf = 2e6;
const ll mod = 1e9 + 7;
const int N = 3e6 + 11;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);
int n, m, r, ans, M = -1, A[100010], bad[100010], sum[100010], t[400010], check[100010];
void build(int v, int l, int r){
if(l == r){
t[v] = 1;
return;
}
int m = l + r >> 1;
build(v * 2, l, m);
build(v * 2 + 1, m + 1, r);
t[v] = t[v * 2] + t[v * 2 + 1];
}
void update(int v, int l, int r, int tl, int tr){
if(r < tl || tr < l) return;
if(tl <= l && r <= tr){
t[v] = 0;
return;
}
int m = l + r >> 1;
update(v*2, l, m, tl, tr);
update(v*2 + 1, m + 1, r, tl, tr);
t[v] = t[v*2] + t[v*2 + 1];
}
int gets(int v, int l, int r, int val){
int m = l + r >> 1;
if(t[v] == r - l + 1 && t[v] == val) return r;
if(t[v*2] >= val) return gets(v*2, l, m, val);
return gets(v*2 + 1, m + 1, r, val - t[v*2]);
}
int gete(int v, int l, int r, int val){
int m = l + r >> 1;
if(t[v] == val) return r;
if(l == r) return -1;
if(t[v*2] > val) return gete(v*2, l, m, val);
if(t[v*2] < val) return gete(v*2 + 1, m + 1, r, val - t[v*2]);
if(t[v*2] == val) return max(gete(v*2, l, m, val), gete(v*2 + 1, m + 1, r, val - t[v*2]));
}
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E){
n = N, m = C, r = R;
for(int i = 1; i < n; i++){
if(K[i - 1] > r)bad[i] = 1;
sum[i] = bad[i];
if(i)sum[i] += sum[i - 1];
}
build(1, 1, n);
for(int i = 0; i < m; i++){
int x = S[i], y = E[i], s, e, ch = 1;
s = gets(1, 1, n, x + 1);
e = gete(1, 1, n, y + 1);
update(1, 1, n, s + 1, e);
if(sum[e - 1] - sum[s - 1] >= 1) ch = 0;
A[s] += ch, A[e + 1] += -ch;
}
for(int i = 1; i <= n; i++){
A[i] += A[i - 1];
if(M < A[i]) M = A[i], ans = i;
}
return ans - 1;
}
Compilation message (stderr)
tournament.cpp: In function 'void build(int, int, int)':
tournament.cpp:30:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
30 | int m = l + r >> 1;
| ~~^~~
tournament.cpp: In function 'void update(int, int, int, int, int)':
tournament.cpp:42:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | int m = l + r >> 1;
| ~~^~~
tournament.cpp: In function 'int gets(int, int, int, int)':
tournament.cpp:49:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
49 | int m = l + r >> 1;
| ~~^~~
tournament.cpp: In function 'int gete(int, int, int, int)':
tournament.cpp:56:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
56 | int m = l + r >> 1;
| ~~^~~
tournament.cpp:62:1: warning: control reaches end of non-void function [-Wreturn-type]
62 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |