Submission #950114

# Submission time Handle Problem Language Result Execution time Memory
950114 2024-03-20T05:30:28 Z vjudge1 Triple Jump (JOI19_jumps) C++17
27 / 100
52 ms 8604 KB
#include <bits/stdc++.h>

#pragma optimize("Ofast,unroll-loops")
#pragma target("avx2")

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mem(a,i) memset(a,i,sizeof(a))
#define sz(s) (int)s.size()
#define y1 yy
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b) __gcd(a,b)
#define in insert
#define int ll

const int MAX=2e5+10;
const int B=500;
const int maxB=1000;
const int N=104;
const int block=450;
const int inf=2e9;  
const int mod=1e9+7;
const int mod1=1e9+9;
const ld eps=1e-9;

int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

int binpow(int a,int n){
  if(!n)return 1;
  if(n%2==1)return a*binpow(a,n-1)%mod;
  int k=binpow(a,n/2);
  return k*k%mod;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,q;
int l[MAX],r[MAX];
int a[MAX];
int nxt[MAX];

void solve(){
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  cin>>q;
  for(int i=1;i<=q;i++)cin>>l[i]>>r[i];
  for(int i=n;i>=1;i--){
    if(a[i]>a[nxt[i+1]])nxt[i]=i;
    else nxt[i]=nxt[i+1];
  }
  int ans=0;
  vector<int> vec;
  for(int i=2;i<=n;i++){
    while(!vec.empty()&&a[i-1]>=a[vec.back()])vec.ppb();
    vec.pb(i-1);
    int l=0,r=sz(vec)-1;
    while(r-l>3){
      int m1=l+(r-l)/3;
      int m2=r-(r-l)/3;
      int r1=-1,r2=-1;
      {
        int pos=vec[m1];
        if(i-pos+i>n)r1=-1;
        else{
          r1=a[pos]+a[nxt[i-pos+i]]+a[i];
        }
      }
      {
        int pos=vec[m2];
        if(i-pos+i>n)r2=-1;
        else{
          r2=a[pos]+a[nxt[i-pos+i]]+a[i];
        }
      }
      if(r1==-1){
        l=m1;
        continue;
      }
      if(r1<r2){
        l=m1;
      }
      else r=m2;
    }
    for(int j=l;j<=r;j++){
      int res=-1;
      int pos=vec[j];
      if(i-pos+i>n)res=-1;
      else{
        res=a[pos]+a[nxt[i-pos+i]]+a[i];
      }
      ans=max(ans,res);
    }
  }
  cout<<ans<<"\n";
}

signed main(){
  // freopen("triangles.in","r",stdin);
  // freopen("triangles.out","w",stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // prec();
  int t=1;
  // cin>>t;
  while(t--){
    solve();
  }
}

Compilation message

jumps.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    3 | #pragma optimize("Ofast,unroll-loops")
      | 
jumps.cpp:4: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    4 | #pragma target("avx2")
      |
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 5712 KB Output is correct
2 Correct 16 ms 6224 KB Output is correct
3 Correct 52 ms 8604 KB Output is correct
4 Correct 23 ms 6480 KB Output is correct
5 Correct 21 ms 6236 KB Output is correct
6 Correct 20 ms 5724 KB Output is correct
7 Correct 19 ms 5724 KB Output is correct
8 Correct 19 ms 5608 KB Output is correct
9 Correct 21 ms 5976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -