Submission #589744

# Submission time Handle Problem Language Result Execution time Memory
589744 2022-07-05T08:26:18 Z Huy Triple Jump (JOI19_jumps) C++17
100 / 100
906 ms 84572 KB
/// no sound bitch
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,ll>
#define fi first
#define se second
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")*/
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ldb = long double;
const ll N = (int)1e9 + 1;
const int maxN = (int)5e5 + 1;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll infty = 1e18 + 7;
const int base = (int)4e5;

void InputFile()
{
    //freopen("scrivener.inp","r",stdin);
    //freopen("scrivener.out","w",stdout);
    //freopen("test.out","r",stdin);
}

void FastInput()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

struct TQuery
{
    int lf,rt,id;
};
vector<TQuery> save_query;

bool FQ(TQuery x,TQuery y)
{
    return x.lf > y.lf;
}

int n;
int q;
int a[maxN];
vector<pii> req;
int res[maxN];

struct Node
{
    int max_a;
    int lazy;
    int val;
};

Node ST[4*maxN];

void Build(int id,int l,int r)
{
    if(l == r)
    {
        ST[id].max_a = ST[id].val = a[l];
        ST[id].lazy = 0;
        return;
    }
    int mid = (l + r) / 2;
    Build(id * 2,l,mid);
    Build(id * 2 + 1,mid + 1,r);
    ST[id].max_a = ST[id].val = max(ST[id*2].max_a,ST[id*2+1].max_a);
    ST[id].lazy = 0;
}

void Down(int id)
{
    if(!ST[id].lazy) return;
    ST[id*2].val = max(ST[id*2].val,ST[id*2].max_a + ST[id].lazy);
    ST[id*2].lazy = max(ST[id*2].lazy,ST[id].lazy);
    ST[id*2+1].val = max(ST[id*2+1].val,ST[id*2+1].max_a + ST[id].lazy);
    ST[id*2+1].lazy = max(ST[id*2+1].lazy,ST[id].lazy);
    ST[id].lazy = 0;
}

void Update(int id,int l,int r,int u,int v,int n_val)
{
    if(v < l || u > r) return;
    if(u <= l && r <= v)
    {
        ST[id].val = max(ST[id].val,ST[id].max_a + n_val);
        ST[id].lazy = max(ST[id].lazy,n_val);
        return;
    }
    Down(id);
    int mid = (l + r) / 2;
    Update(id * 2,l,mid,u,v,n_val);
    Update(id * 2 + 1,mid + 1,r,u,v,n_val);
    ST[id].val = max(ST[id*2].val,ST[id*2+1].val);
}

int Get(int id,int l,int r,int u,int v)
{
    if(v < l || u > r) return -infty;
    if(u <= l && r <= v)
    {
        return ST[id].val;
    }
    Down(id);
    int mid = (l + r) / 2;
    return max(Get(id * 2,l,mid,u,v),Get(id * 2 + 1,mid + 1,r,u,v));
}

void Read()
{
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    cin >> q;
    for(int i = 1;i <= q;i++)
    {
        int l,r;
        cin >> l >> r;
        save_query.push_back({l,r,i});
    }
}

void Solve()
{
    //cout <<"dark";return;
    vector<int> vc;
    for(int i = n;i >= 1;i--)
    {
        if(vc.empty()) vc.push_back(i);
        else
        {
            while(!vc.empty() && a[vc.back()] < a[i])
            {
                req.push_back({i,vc.back()});
                vc.pop_back();
            }
            if(!vc.empty()) req.push_back({i,vc.back()});
            vc.push_back(i);
        }
    }
    sort(req.begin(),req.end(),greater<pii>());
    sort(save_query.begin(),save_query.end(),FQ);
    /*for(pii tmp : req)
    {
        cout <<'*'<<' '<< tmp.fi <<' '<< tmp.se <<'\n';
    }
    return;*/
    Build(1,1,n);
    int pt = 0;
    for(TQuery tmp : save_query)
    {
        while(pt < req.size() && req[pt].fi >= tmp.lf)
        {
            if(2 * req[pt].se - req[pt].fi <= n)
            {
                Update(1,1,n,2*req[pt].se-req[pt].fi,n,a[req[pt].fi]+a[req[pt].se]);
            }
            pt++;
        }
        res[tmp.id] = Get(1,1,n,tmp.lf+2,tmp.rt);
    }
    for(int i = 1;i <= q;i++)
    {
        cout << res[i] <<'\n';
    }
}

void Debug()
{

}


int32_t main()
{
    FastInput();
    //InputFile();
    //int sub_type;
    //cin >> sub_type;
    //Sieve();
    //Prepare();
    int test;
    //cin >> test;
    test = 1;
    while(test--)
        //for(int prc = 1; prc <= test; prc++)
    {
        Read();
        Solve();
        //Debug();
    }
}

Compilation message

jumps.cpp: In function 'void Solve()':
jumps.cpp:160:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  160 |         while(pt < req.size() && req[pt].fi >= tmp.lf)
      |               ~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 294 ms 26528 KB Output is correct
12 Correct 298 ms 26276 KB Output is correct
13 Correct 289 ms 26268 KB Output is correct
14 Correct 289 ms 26656 KB Output is correct
15 Correct 293 ms 26504 KB Output is correct
16 Correct 290 ms 25964 KB Output is correct
17 Correct 316 ms 25768 KB Output is correct
18 Correct 298 ms 25940 KB Output is correct
19 Correct 299 ms 26412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 22356 KB Output is correct
2 Correct 80 ms 20876 KB Output is correct
3 Correct 77 ms 19216 KB Output is correct
4 Correct 132 ms 22352 KB Output is correct
5 Correct 129 ms 22356 KB Output is correct
6 Correct 130 ms 21692 KB Output is correct
7 Correct 127 ms 21560 KB Output is correct
8 Correct 126 ms 21596 KB Output is correct
9 Correct 131 ms 21928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 294 ms 26528 KB Output is correct
12 Correct 298 ms 26276 KB Output is correct
13 Correct 289 ms 26268 KB Output is correct
14 Correct 289 ms 26656 KB Output is correct
15 Correct 293 ms 26504 KB Output is correct
16 Correct 290 ms 25964 KB Output is correct
17 Correct 316 ms 25768 KB Output is correct
18 Correct 298 ms 25940 KB Output is correct
19 Correct 299 ms 26412 KB Output is correct
20 Correct 133 ms 22356 KB Output is correct
21 Correct 80 ms 20876 KB Output is correct
22 Correct 77 ms 19216 KB Output is correct
23 Correct 132 ms 22352 KB Output is correct
24 Correct 129 ms 22356 KB Output is correct
25 Correct 130 ms 21692 KB Output is correct
26 Correct 127 ms 21560 KB Output is correct
27 Correct 126 ms 21596 KB Output is correct
28 Correct 131 ms 21928 KB Output is correct
29 Correct 906 ms 84364 KB Output is correct
30 Correct 809 ms 81784 KB Output is correct
31 Correct 681 ms 76520 KB Output is correct
32 Correct 878 ms 84484 KB Output is correct
33 Correct 838 ms 84368 KB Output is correct
34 Correct 822 ms 82048 KB Output is correct
35 Correct 824 ms 81892 KB Output is correct
36 Correct 817 ms 81812 KB Output is correct
37 Correct 852 ms 83184 KB Output is correct
38 Correct 670 ms 84320 KB Output is correct
39 Correct 714 ms 84420 KB Output is correct
40 Correct 680 ms 81052 KB Output is correct
41 Correct 668 ms 80556 KB Output is correct
42 Correct 659 ms 80572 KB Output is correct
43 Correct 688 ms 82264 KB Output is correct
44 Correct 712 ms 84416 KB Output is correct
45 Correct 672 ms 84572 KB Output is correct
46 Correct 686 ms 81180 KB Output is correct
47 Correct 692 ms 80976 KB Output is correct
48 Correct 675 ms 80828 KB Output is correct
49 Correct 695 ms 82816 KB Output is correct
50 Correct 730 ms 84408 KB Output is correct
51 Correct 710 ms 84460 KB Output is correct
52 Correct 712 ms 81968 KB Output is correct
53 Correct 722 ms 81648 KB Output is correct
54 Correct 717 ms 81860 KB Output is correct
55 Correct 694 ms 83268 KB Output is correct