답안 #579018

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
579018 2022-06-18T09:54:24 Z mousebeaver Two Antennas (JOI19_antennas) C++14
22 / 100
376 ms 19176 KB
#define ll long long
#define ull unsigned ll
#define pii pair<int, int>
#include <bits/stdc++.h>
using namespace std;

int left(int i)
{
    return 2*i;
}

int right(int i)
{
    return 2*i+1;
}

int par(int i)
{
    return i/2;
}

ll query(vector<ll>& s, int a, int b, int l, int r, int i)
{
    //cout<<"HERE: "<<i<<" => <<endl;
    if(l <= a && b <= r)
    {
        //cout<<"END"<<endl;
        return s[i];
    }
    if(r < a || b < l)
    {
        //cout<<"END"<<endl;
        return numeric_limits<ll>::min();
    }
    int m = (a+b)/2;
    return max(query(s, a, m, l, r, left(i)), query(s, m+1, b, l, r, right(i)));
}

void propagate(vector<ll>& s, int i)
{
    s[i] = max(s[left(i)], s[right(i)]);
    if(i > 1)
    {
        propagate(s, par(i));
    }
}

void update(vector<ll>& s, int i, ll v)
{
    s[i+(s.size()/2)] = v;
    propagate(s, par(i+(s.size()/2)));
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin>>n;
    vector<ll> h(n); //heights
    vector<pii> a(n); //Bereiche
    for(int i = 0; i < n; i++)
    {
        cin>>h[i]>>a[i].first>>a[i].second;
    }

    int segnodes = 2*pow(2, ceil(log2(n)));
    //Segtrees for max:
    vector<ll> s(segnodes, numeric_limits<ll>::min()); //positive heights
    vector<ll> ns(segnodes, numeric_limits<ll>::min()); //negative heights

    int q;
    cin>>q;
    for(int i = 0; i < q; i++)
    {
        int l, r;
        cin>>l>>r;
        ll output = -1;
        priority_queue<pii, vector<pii>, greater<pii>> st; //starts: distance, index
        priority_queue<pii, vector<pii>, greater<pii>> g; //goals: distance, index
        st.push({a[l-1].first+l, l});
        g.push({a[l-1].second+l+1, l});
        //cout<<"___________________________________NEW QUERY!!!"<<endl;
        for(int j = l+1; j <= r; j++)
        {
            //cout<<"-------->: "<<j<<endl;
            while(!st.empty() && st.top().first == j)
            {
                update(s, st.top().second-1, h[st.top().second-1]);
                update(ns, st.top().second-1, 0-h[st.top().second-1]);
                //cout<<"TAKE "<<st.top().second<<endl;
                st.pop();
            }
            while(!g.empty() && g.top().first == j)
            {
                update(s, g.top().second-1, numeric_limits<ll>::min());
                update(ns, g.top().second-1, numeric_limits<ll>::min());
                //cout<<"DROP "<<g.top().second<<endl;
                g.pop();
            }
            st.push({a[j-1].first+j, j});
            g.push({a[j-1].second+j+1, j});
            /*cout<<"SEGTREE S: "<<endl;
            for(ll y : s)
            {
                cout<<y<<" ";
            }
            cout<<endl;*/
            int left = max(j-a[j-1].second, l);
            int right = max(j-a[j-1].first, l);
            //cout<<"LEFT: "<<left<<", RIGHT: "<<right<<endl;
            ll biggest = query(s, 1, segnodes/2, left, right, 1);
            ll smallest = query(ns, 1, segnodes/2, left, right, 1);
            //cout<<"BIGGEST: "<<biggest<<", SMALLEST: "<<smallest<<endl;
            if(biggest > numeric_limits<ll>::min())
            {
                //cout<<"HEREBIG"<<endl;
                output = max(output, abs(h[j-1]-biggest));
            }
            if(smallest > numeric_limits<ll>::min())
            {
                //cout<<"HERESMALL"<<endl;
                output = max(output, abs(h[j-1]+smallest));
            }
            //cout<<"OUTPUT: "<<output<<endl;
        }
        while(!g.empty())
        {
            update(s, g.top().second-1, numeric_limits<ll>::min());
            update(ns, g.top().second-1, numeric_limits<ll>::min());
            g.pop();
        }

        cout<<output<<"\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 360 ms 14504 KB Output is correct
2 Correct 341 ms 19076 KB Output is correct
3 Correct 232 ms 15708 KB Output is correct
4 Correct 376 ms 19156 KB Output is correct
5 Correct 124 ms 9372 KB Output is correct
6 Correct 305 ms 19148 KB Output is correct
7 Correct 267 ms 16964 KB Output is correct
8 Correct 268 ms 19160 KB Output is correct
9 Correct 46 ms 2888 KB Output is correct
10 Correct 295 ms 19092 KB Output is correct
11 Correct 160 ms 10700 KB Output is correct
12 Correct 251 ms 19176 KB Output is correct
13 Correct 236 ms 19036 KB Output is correct
14 Correct 182 ms 19044 KB Output is correct
15 Correct 191 ms 18012 KB Output is correct
16 Correct 223 ms 18044 KB Output is correct
17 Correct 205 ms 19064 KB Output is correct
18 Correct 199 ms 17960 KB Output is correct
19 Correct 223 ms 19040 KB Output is correct
20 Correct 203 ms 19012 KB Output is correct
21 Correct 187 ms 19088 KB Output is correct
22 Correct 303 ms 19128 KB Output is correct
23 Correct 197 ms 18144 KB Output is correct
24 Correct 183 ms 18064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -