답안 #944026

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
944026 2024-03-12T06:53:09 Z teacup 3단 점프 (JOI19_jumps) C++17
0 / 100
4000 ms 27988 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ii pair<int,int>
typedef vector<int> vi;
#define iii tuple<int,int,int>
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef map<int,int> mii;

#ifndef debug 
    #define cerr if (0) cerr
#endif

const int INF=1e17;
template<class T>
struct RMQ{
	vector<vector<T>> jmp;
	RMQ(const vector<T>&V) : jmp(1,V){
		for (int pw=1, k=1; pw*2<=V.size(); pw*=2, k++){
			jmp.emplace_back(V.size() - pw*2+1);
			for (int j=0; j<jmp[k].size(); j++){
				jmp[k][j] = max(jmp[k-1][j], jmp[k-1][j+pw]);
			}
		}
	}
	T query(int a, int b){
		if (a>=b) return -INF;
		int dep = 31 - __builtin_clz(b-a);
		return max(jmp[dep][a], jmp[dep][b-(1<<dep)]);
	}
};

int N, Q, L, R, ans;

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	
	cin>>N; vi A(N+5);
	for (int i=1; i<=N; i++){
		cin>>A[i];
	}
	
	RMQ<int> rmq(A);
	cin>>Q;
    while (Q--){
        cin>>L>>R;
        ans = 0;
		for (int i=L; i<=R; i++){
			for (int j=i+1; j<=R; j++){
				/*
				for (int k=j+1; k<=R; k++){
					if (!(j-i <= k-j)) continue;
					ans=max(ans, A[i]+A[j]+A[k]);
				}*/
				ans=max(ans, A[i]+A[j]+rmq.query(2*j-i, R));
			}
		}
		cout<<ans<<"\n";
    }
}

Compilation message

jumps.cpp: In instantiation of 'RMQ<T>::RMQ(const std::vector<_Tp>&) [with T = long long int]':
jumps.cpp:46:16:   required from here
jumps.cpp:21:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |   for (int pw=1, k=1; pw*2<=V.size(); pw*=2, k++){
      |                       ~~~~^~~~~~~~~~
jumps.cpp:23:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |    for (int j=0; j<jmp[k].size(); j++){
      |                  ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4016 ms 27988 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -