이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
void read(T &x)
{
x = 0;
register int c;
while ((c = getchar()) && (c > '9' || c < '0'))
;
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
}
constexpr bool typetest = 0;
constexpr int N = 2e5 + 5;
constexpr int Inf = 1e9 + 7;
struct SegmentTree
{
int st[N * 4], n;
SegmentTree()
{
fill_n(st, N * 4, -Inf);
}
void Update(int id, int l, int r, const int &x, const int &v)
{
if (l > x || r < x)
return;
if (l == x && r == x)
{
st[id] = v;
return;
}
Update(id << 1, l, (l + r) / 2, x, v);
Update(id << 1 | 1, (l + r) / 2 + 1, r, x, v);
st[id] = max(st[id << 1], st[id << 1 | 1]);
}
void Update(int x, int v)
{
Update(1, 1, n, x, v);
}
int Get(int id, int l, int r, const int &a, const int &b)
{
if (l > b || r < a)
return -Inf;
if (l >= a && r <= b)
return st[id];
return max(Get(id << 1, l, (l + r) / 2, a, b), Get(id << 1 | 1, (l + r) / 2 + 1, r, a, b));
}
int Get(int l, int r)
{
return Get(1, 1, n, l, r);
}
} f, g;
int n, q, l[N], r[N], x[N], y[N], a[N];
vector<int> in[N], out[N];
void Read()
{
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> a[i] >> x[i] >> y[i];
if (i - x[i] > 0)
in[i - x[i]].emplace_back(i);
if (i - y[i] - 1 > 0)
out[i - y[i] - 1].emplace_back(i);
}
cin >> q;
}
void Solve()
{
f.n = g.n = n;
while (q--)
{
int l, r;
cin >> l >> r;
int ans(-Inf);
for (int i = r; i >= l; --i)
{
for (auto j : in[i])
{
f.Update(j, a[j]);
g.Update(j, -a[j]);
}
for (auto j : out[i])
{
f.Update(j, -Inf);
g.Update(j, -Inf);
}
if (i + x[i] <= r)
{
int maxn = f.Get(i + x[i], min(r, i + y[i])),
minn = -g.Get(i + x[i], min(r, i + y[i]));
if (maxn != -Inf && minn != Inf)
ans = max(ans, max(abs(a[i] - maxn), abs(a[i] - minn)));
else if (maxn != -Inf)
ans = max(ans, abs(a[i] - maxn));
else if (minn != Inf)
ans = max(ans, abs(a[i] - minn));
}
}
for (int i = r; i >= l; --i)
for (auto j : in[i])
{
f.Update(j, -Inf);
g.Update(j, -Inf);
}
cout << (ans <= -Inf ? -1 : ans) << '\n';
}
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("palesta.INP", "r"))
{
freopen("paletsa.inp", "r", stdin);
freopen("palesta.out", "w", stdout);
}
int t(1);
if (typetest)
cin >> t;
for (int _ = 1; _ <= t; ++_)
{
// cout << "Case #" << _ << ": ";
Read();
Solve();
}
// cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
antennas.cpp: In function 'void read(T&)':
antennas.cpp:12:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
12 | register int c;
| ^
antennas.cpp: In function 'int32_t main()':
antennas.cpp:141:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
141 | freopen("paletsa.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
antennas.cpp:142:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
142 | freopen("palesta.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |