This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 2e5, oo = 2e9 + 1;
int n, q, h[N + 1], a[N + 1], b[N + 1];
int dp[2001][2001];
void maximize(int &a, int b)
{
if (a < b)
{
a = b;
}
}
void read()
{
cin >> n;
for (int i = 1; i <= n; ++ i)
{
cin >> h[i] >> a[i] >> b[i];
}
}
void sub2()
{
memset(dp, -1, sizeof(dp));
for (int l = 1; l <= n; ++ l)
{
for (int r = l + a[l]; r <= min(n, l + b[l]); ++ r)
{
if (r - b[r] <= l && l <= r - a[r])
{
dp[l][r] = abs(h[l] - h[r]);
}
}
}
for (int lens = 2; lens <= n; ++ lens)
{
for (int l = 1; l + lens - 1 <= n; ++ l)
{
int r = l + lens - 1;
maximize(dp[l][r], dp[l][r - 1]);
maximize(dp[l][r], dp[l + 1][r]);
}
}
cin >> q;
while(q--)
{
int l, r;
cin >> l >> r;
cout << (dp[l][r] == oo ? -1 : dp[l][r]) << '\n';
}
}
void solve()
{
if (n <= 2000)
{
sub2();
return ;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = false;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case " << __ << ": ";
read();
solve();
}
}
Compilation message (stderr)
antennas.cpp: In function 'int main()':
antennas.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
68 | freopen(TASK".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |