# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
793266 |
2023-07-25T17:00:16 Z |
anton |
Triple Jump (JOI19_jumps) |
C++17 |
|
2560 ms |
9300 KB |
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define int long long
const int MAX_N = 5*1e5;
const int INF = 1e9;
const int K = 35;
int n, q;
pii A[MAX_N];
pii B[K];
int lower_sum = 0;
int tree[MAX_N*4];
void build(int lt, int rt, int t){
if(lt == rt){
tree[t] = A[lt].first;
}
else{
int mid = (lt+rt)/2;
build(lt, mid, t*2);
build(mid+1, rt, t*2+1);
tree[t] = max(tree[t*2], tree[t*2+1]);
}
}
int get(int l, int r, int lt, int rt, int t){
if(l<=lt && rt<= r){
return tree[t];
}
else if(rt<l || r<lt){
return -INF;
}
else{
int mid = (lt+rt)/2;
return max(get(l, r, lt, mid, t*2), get(l, r, mid+1, rt, t*2+1));
}
}
int get(int l, int r){
l = max(l, 0LL);
r= min(r, n-1);
//cout<<"get "<<l<<" "<<r<<endl;
if(l>r){
return -INF;
}
return get(l, r, 0, n-1, 1);
}
int get_score(int a, int b){
//cout<<a<<" "<<b<<endl;
if(a==b){
return -INF;
}
if(a>b){
return get_score(b, a);
}
int s= A[a].first + A[b].first;
int other = 0;
int d= b-a;
other = max(other, get(0, a-d));
other = max(other, get(a+1, a+(d/2)));
other = max(other, get(b+d, n-1));
return s+other;
}
signed main(){
cin>>n;
for(int i = 0; i<n; i++){
cin>>A[i].first;
A[i].second = i;
}
auto cmp1 =[&](pii a, pii b){return a.first>b.first;};
sort(A, A +n, cmp1);
int s= min(n, K);
for(int i = 0; i<s; i++){
B[i] = A[i];
}
auto cmp2 = [&](pii a, pii b){return a.second<b.second;};
sort(A, A+n, cmp2);
sort(B, B+s, cmp2);
for(int i = 0; i<s; i++){
for(int j = i+1; j<s; j++){
for(int k= j+1; k<s; k++){
if(j-i<=k-j){
//cout<<i<<" "<<j<<" "<<k<<endl;
lower_sum = max(lower_sum, B[i].first+B[j].first+B[k].first);
}
}
}
}
cin>>q;
for(int i = 0; i<q; i++){
int a, b;
cin>>a>>b;
}
build(0, n-1, 1);
//cout<<lower_sum<<endl;
int res= 0;
for(int i = 0; i<n; i++){
for(int j = 0; j<s; j++){
res=max(res, get_score(i, B[j].second));
}
}
cout<<res<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2560 ms |
9280 KB |
Output is correct |
2 |
Correct |
1721 ms |
9300 KB |
Output is correct |
3 |
Correct |
1783 ms |
9276 KB |
Output is correct |
4 |
Incorrect |
2201 ms |
9276 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |