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 "holiday.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int segl[4*100005], seglco[4*100005], segr[4*100005], segrco[4*100005];
void updatel(int n, int l, int r, int i, int v, int c) {
if (l == r) {
if (c == -1) {
segl[n] = 0;
seglco[n] = 0;
} else {
segl[n] = v;
seglco[n] = 1;
}
} else {
int m = (l+r)/2;
if (l <= i && i <= m) {
updatel(2*n, l, m, i, v, c);
} else {
updatel(2*n+1, m+1, r, i, v, c);
}
segl[n] = segl[2*n] + segl[2*n+1];
seglco[n] = seglco[2*n] + seglco[2*n+1];
}
}
void updater(int n, int l, int r, int i, int v, int c) {
if (l == r) {
if (c == -1) {
segr[n] = 0;
segrco[n] = 0;
} else {
segr[n] = v;
segrco[n] = 1;
}
} else {
int m = (l+r)/2;
if (l <= i && i <= m) {
updater(2*n, l, m, i, v, c);
} else {
updater(2*n+1, m+1, r, i, v, c);
}
segr[n] = segr[2*n] + segr[2*n+1];
segrco[n] = segrco[2*n] + segrco[2*n+1];
}
}
int queryl(int n, int l, int r, int k) {
if (seglco[n] == k) {
return segl[n];
} else {
int m = (l+r)/2, v = 0;
if (seglco[2*n+1] >= k) {
return queryl(2*n+1, m+1, r, k);
} else {
v += queryl(2*n+1, m+1, r, seglco[2*n+1]);
k -= seglco[2*n+1];
v += queryl(2*n, l, m, k);
return v;
}
}
}
int queryr(int n, int l, int r, int k) {
if (segrco[n] == k) {
return segr[n];
} else {
int m = (l+r)/2, v = 0;
if (segrco[2*n+1] >= k) {
return queryr(2*n+1, m+1, r, k);
} else {
v += queryr(2*n+1, m+1, r, segrco[2*n+1]);
k -= segrco[2*n+1];
v += queryr(2*n, l, m, k);
return v;
}
}
}
int findMaxAttraction(int32_t n, int32_t st, int32_t d, int32_t at[]) {
int ans = 0;
vector<int> l(n), r(n), dpl(2*n+2, 0), dpr(2*n+2, 0);
vector<pair<int, int>> lat, rat;
for (int i = 0; i < st; i++) {
lat.push_back({at[i], i});
}
for (int i = st; i < n; i++) {
rat.push_back({at[i], i});
}
sort(lat.begin(), lat.end());
sort(rat.begin(), rat.end());
for (int i = 0; i < lat.size(); i++) {
l[lat[i].second] = i;
}
for (int i = 0; i < rat.size(); i++) {
r[rat[i].second] = i;
}
for (int i = st-1; i >= 0; i--) {
updatel(1, 0, n-1, l[i], at[i], 1);
for (int j = 1; j <= (st-i); j++) {
dpl[i+j] = max(dpl[i+j], queryl(1, 0, n-1, j));
}
}
for (int i = st; i < n; i++) {
updater(1, 0, n-1, r[i], at[i], 1);
ans = max(ans, queryr(1, 0, n-1, min(i-st+1, d-(i-st))));
}
return ans;
}
Compilation message (stderr)
holiday.cpp: In function 'long long int findMaxAttraction(int32_t, int32_t, int32_t, int32_t*)':
holiday.cpp:88:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for (int i = 0; i < lat.size(); i++) {
| ~~^~~~~~~~~~~~
holiday.cpp:91:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | for (int i = 0; i < rat.size(); i++) {
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |