이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "meetings.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
#define pb push_back
#define popb pop_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
const ll INF = 1e18;
const int nax = 1e5 + 4;
ll sp[nax][20], A[nax];
int LG[nax];
int n, q;
void build()
{
for(int i = 0 ; i < n; i++)
sp[i][0] = A[i];
for(int j = 1; j < 20; j ++)
for(int i = 0 ; i + (1 << j) <= n; i ++)
sp[i][j] = max(sp[i][j - 1], sp[i + (1 << (j-1))][j - 1]);
}
ll rmq(int l, int r)
{
if(l > r)
swap(l, r);
int j = LG[r - l + 1];
return max(sp[l][j], sp[r - (1 << j) + 1][j]);
}
vll minimum_costs(vi H, vi L, vi R)
{
n = H.size();
for(int i = 0 ; i < n; i ++)
A[i] = H[i];
q = L.size();
LG[1] = 0 ;
for(int i= 2; i <= n;i ++)
LG[i] = LG[i/2] + 1;
build();
ll pref[n][n + 1];
for(int i = 0; i < n;i ++)
{
pref[i][0] = 0ll;
for(int j = 0 ; j < n ;j++)
{
pref[i][j + 1] = pref[i][j] + rmq(i, j);
}
}
vll ans(q, INF);
for(int query = 0; query < q; query ++)
{
int l = L[query];
int r = R[query];
for(int i = l; i <= r; i ++)
{
ans[i] = min(ans[i], pref[i][r + 1] - pref[i][l]);
}
}
return ans;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |