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>
#define inbuf_len 1 << 16
#define outbuf_len 1 << 16
using namespace std;
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=1; i<=9; i++) printf("%d ", tree[i]); puts("");
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;
// printf("%d %d %d %d %d\n", x, y, s, e, 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:13:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
13 | int m = l + r >> 1;
| ~~^~~
tournament.cpp: In function 'void update(int, int, int, int, int)':
tournament.cpp:25:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
25 | int m = l + r >> 1;
| ~~^~~
tournament.cpp: In function 'int gets(int, int, int, int)':
tournament.cpp:32:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
32 | int m = l + r >> 1;
| ~~^~~
tournament.cpp: In function 'int gete(int, int, int, int)':
tournament.cpp:39:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
39 | int m = l + r >> 1;
| ~~^~~
tournament.cpp:45:1: warning: control reaches end of non-void function [-Wreturn-type]
45 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |