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 = 2e5 + 11;
const ll INF64 = 2e9 + 1;
const double eps = 1e-14;
const double PI = acos(-1);
//ifstream in(".in");
//ofstream out(".out");
int t[4*N];
int sum[N], ans, nxt[N];
void update(int v, int l, int r, int pos, int val){
if(l == r){
t[v] = val;
return;
}
int mid = (l + r) >> 1;
if(pos <= mid)update(2*v, l, mid, pos, val);else update(2*v + 1, mid + 1, r, pos, val);
t[v] = t[2*v] + t[2*v + 1];
}
void update2(int v, int l, int r, int pos, int val){
if(l == r){
t[v] = val;
return;
}
int mid = (l + r) >> 1;
if(pos <= mid)update2(2*v, l, mid, pos, val);else update2(2*v + 1, mid + 1, r, pos, val);
t[v] = max(t[2*v], t[2*v + 1]);
}
int xth(int v, int l, int r, int x){
if(l == r){
return l;
}
int mid = (l + r) >> 1;
if(t[2*v] >= x)return xth(2*v, l, mid, x);
return xth(2*v + 1, mid + 1, r, x - t[2*v]);
}
int mx(int v, int l, int r, int tl, int tr){
if(tl <= l && r <= tr)return t[v];
if(l > tr || r < tl)return -INF64;
int mid = (l + r) >> 1;
return max(mx(2*v, l, mid, tl, tr), mx(2*v + 1, mid + 1, r, tl ,tr));
}
int GetBestPosition(int n, int C, int R, int *K, int *S, int *E){
n--;
for(int i = 1; i <= n; i++){
nxt[i] = i + 1;
update(1, 1, n, i, 1);
}
for(int i = 1; i <= C; i++){
int a = xth(1, 1, n, S[i - 1] + 1);
int tmp = a;
for(int j = 1; j <= E[i - 1] - S[i - 1]; j++){
tmp = nxt[tmp];
update(1, 1, n, tmp, 0);
}
nxt[a] = nxt[tmp]; //cout << a << ' ' << nxt[tmp] << '\n';
E[i - 1] = nxt[tmp] - 1;
S[i - 1] = a;
}
for(int i = 1; i <= n; i++){
update(1, 1, n, i, 0);
}
for(int i = 1; i <= n; i++){
update2(1, 1, n, i, K[i - 1]);
}
//cout << "Here" << '\n';
for(int i = 0; i < C; i++){
//cout << S[i] << ' ' << E[i] << '\n';
}
for(int i = 1; i <= C; i++){
int s = mx(1, 1, n, S[i - 1], E[i - 1] - 1);
if(s < R)sum[S[i - 1]]++, sum[E[i - 1] + 1]--;
}
for(int i = 1; i <= n; i++) sum[i] += sum[i - 1];
for(int i = 1; i <= n; i++)if(sum[ans] < sum[i]) ans = i;
return ans - 1;
}
void solve(){
int n, C, R;
cin >> n >> C >> R;
//n--;
int k[n], s[C], e[C];
for(int i = 1; i < n; i++){
cin >> k[i - 1];
}
for(int i = 1; i <= C; i++){
cin >> s[i - 1];
}
for(int i = 1; i <= C; i++){
cin >> e[i - 1];
}
cout << GetBestPosition(n, C, R, k, s, e) << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |