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], tree[400010], check[100010];
void build(int node, int s, int e){
if(s == e){
tree[node] = 1;
return;
}
int m = s + e >> 1;
build(node * 2, s, m);
build(node * 2 + 1, m + 1, e);
tree[node] = tree[node * 2] + tree[node * 2 + 1];
}
void update(int node, int s, int e, int s1, int e1){
if(e<s1||e1<s) return;
if(s1<=s&&e<=e1){
tree[node]=0;
return;
}
int m=s+e>>1;
update(node*2, s, m, s1, e1);
update(node*2+1, m+1, e, s1, e1);
tree[node]=tree[node*2]+tree[node*2+1];
}
int gets(int node, int s, int e, int val){
int m=s+e>>1;
if(tree[node]==e-s+1&&tree[node]==val) return e;
if(tree[node*2]>=val) return gets(node*2, s, m, val);
return gets(node*2+1, m+1, e, val-tree[node*2]);
}
int gete(int node, int s, int e, int val){
int m=s+e>>1;
if(tree[node]==val) return e;
if(s==e) return -1;
if(tree[node*2]>val) return gete(node*2, s, m, val);
if(tree[node*2]<val) return gete(node*2+1, m+1, e, val-tree[node*2]);
if(tree[node*2]==val) return max(gete(node*2, s, m, val), gete(node*2+1, m+1, e, val-tree[node*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] - (s - 1 >=0 ?sum[s - 1] : 0) >= 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++){
if(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 = s + e >> 1;
| ~~^~~
tournament.cpp: In function 'void update(int, int, int, int, int)':
tournament.cpp:25:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
25 | int m=s+e>>1;
| ~^~
tournament.cpp: In function 'int gets(int, int, int, int)':
tournament.cpp:32:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
32 | int m=s+e>>1;
| ~^~
tournament.cpp: In function 'int gete(int, int, int, int)':
tournament.cpp:39:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
39 | int m=s+e>>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... |