Submission #1012647

#TimeUsernameProblemLanguageResultExecution timeMemory
1012647otariusTwo Antennas (JOI19_antennas)C++17
0 / 100
146 ms66132 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <queue>
#include <map>
#include <stack>
#include <cmath>
#include <iomanip>
using namespace std;

#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long

// #define int long long
// #define int unsigned long long

const ll inf = 1e9 + 7;
const ll weirdMod = 998244353;

vector<int> ins[200005], ers[200005];
struct node {
    int lmax, lmin, rmax, rmin, ans;
} t[800040];
bool comp(pair<pii, int> a, pair<pii, int> b) {
    return a.ff.sc < b.ff.sc;
}
void build(int v, int tl, int tr) {
    t[v].lmin = t[v].rmin = inf;
    t[v].lmax = t[v].rmax = t[v].ans = -inf;
    if (tl == tr) return;
    int tm = (tl + tr) / 2;
    build(2 * v, tl, tm);
    build(2 * v + 1, tm + 1, tr);
}
void prop(int v) {
    if (t[v].rmin == inf) return;
    t[2 * v].rmin = min(t[2 * v].rmin, t[v].rmin);
    t[2 * v].rmax = max(t[2 * v].rmax, t[v].rmax);
    t[2 * v + 1].rmin = min(t[2 * v + 1].rmin, t[v].rmin);
    t[2 * v + 1].rmax = max(t[2 * v + 1].rmax, t[v].rmax);
    t[v].rmin = inf; t[v].rmax = -inf;
    t[2 * v].ans = max({t[2 * v].ans, t[2 * v].lmax - t[2 * v].rmin, t[2 * v].rmax - t[2 * v].lmin});
    t[2 * v + 1].ans = max({t[2 * v + 1].ans, t[2 * v + 1].lmax - t[2 * v + 1].rmin, t[2 * v + 1].rmax - t[2 * v + 1].lmin});
}
void update1(int v, int tl, int tr, int pos, int val) {
    if (tl == tr) {
        t[v].lmax = t[v].lmin = val;
        return;
    } prop(v);
    int tm = (tl + tr) / 2;
    if (pos <= tm) update1(2 * v, tl, tm, pos, val);
    else update1(2 * v + 1, tm + 1, tr, pos, val);
    t[v].lmin = min(t[2 * v].lmin, t[2 * v + 1].lmin);
    t[v].lmax = max(t[2 * v].lmax, t[2 * v + 1].lmax);
}
void erase(int v, int tl, int tr, int pos) {
    if (tl == tr) { 
        t[v].lmin = inf;
        t[v].lmax = -inf;
        return;
    } prop(v);
    int tm = (tl + tr) / 2;
    if (pos <= tm) erase(2 * v, tl, tm, pos);
    else erase(2 * v + 1, tm + 1, tr, pos);
    t[v].lmin = min(t[2 * v].lmin, t[2 * v + 1].lmin);
    t[v].lmax = max(t[2 * v].lmax, t[2 * v + 1].lmax);
}
void update2(int v, int tl, int tr, int l, int r, int val) {
    if (r < tl || tr < l) return;
    prop(v);
    if (l <= tl && tr <= r) {
        t[v].rmin = t[v].rmax = val;
        t[v].ans = max({t[v].ans, t[v].rmax - t[v].lmin, t[v].lmax - t[v].rmin});
        return;
    } int tm = (tl + tr) / 2;
    update2(2 * v, tl, tm, l, min(r, tm), val);
    update2(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, val);
    t[v].ans = max(t[2 * v].ans, t[2 * v + 1].ans);
}
int getmax(int v, int tl, int tr, int l, int r) {
    if (l > r) return -inf;
    prop(v);
    if (tl == l && tr == r)
        return t[v].ans;
    int tm = (tl + tr) / 2;
    return max(getmax(2 * v, tl, tm, l, min(r, tm)),
               getmax(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
}
void solve() {
    int n, q;
    cin >> n;
    int h[n + 1], a[n + 1], b[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> h[i] >> a[i] >> b[i];
        if (i + a[i] <= n) ins[i + a[i]].pb(i);
        if (i + b[i] + 1 <= n) ers[i + b[i] + 1].pb(i);
    } cin >> q;
    build(1, 1, n);
    int ans[q + 1];
    vector<pair<pii, int>> qr(q);
    for (int i = 0; i < q; i++) {
        cin >> qr[i].ff.ff >> qr[i].ff.sc; qr[i].sc = i + 1;
    } sort(qr.begin(), qr.end(), comp);
    for (int i = 1, j = 0; i <= n; i++) {
        for (int v : ins[i])
            update1(1, 1, n, v, h[v]);
        for (int v : ers[i])
            erase(1, 1, n, v);
        if (i - a[i] >= 1)
            update2(1, 1, n, max(1, i - b[i]), i - a[i], h[i]);
        while (qr[j].ff.sc == i) {
            ans[qr[j].sc] = getmax(1, 1, n, qr[j].ff.ff, qr[j].ff.sc);
            if (ans[qr[j].sc] < 0) ans[qr[j].sc] = -1; j++;
        }
    } for (int i = 1; i <= q; i++) cout << ans[i] << '\n';
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}

Compilation message (stderr)

antennas.cpp: In function 'void solve()':
antennas.cpp:120:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  120 |             if (ans[qr[j].sc] < 0) ans[qr[j].sc] = -1; j++;
      |             ^~
antennas.cpp:120:56: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  120 |             if (ans[qr[j].sc] < 0) ans[qr[j].sc] = -1; j++;
      |                                                        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...