Submission #673512

# Submission time Handle Problem Language Result Execution time Memory
673512 2022-12-20T19:45:20 Z AmirElarbi Triple Jump (JOI19_jumps) C++14
100 / 100
1909 ms 63908 KB
#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e9
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 2e5+5
using namespace std;
int MOD = 1e9+7;
const int nax = 5e5+5;
const int nax2 = 200+5;
typedef complex<int> Point;
#define X real()
#define Y imag()
using cd = complex<double>;
const double PI = acos(-1);
pair<pll,ll> st[nax*4];
bool cmp(const pair<ii,int>& x, const pair<ii,int>& y) { return x > y; }
pair<pll,ll> combine(pair<pll,ll> a, pair<pll,ll> b){
    return {{max(a.fi.fi,b.fi.fi), max(a.fi.se, b.fi.se)} , max(a.se, max(b.se, a.fi.fi+b.fi.se) ) } ;
}
pair<pll,ll> qry(int v, int l, int r, int i, int j){
    if(r < i || l > j) return {{0,0},0};
    if(i <= l && r <= j) return st[v];
    int md = (l+r)/2;
    return combine(qry(v*2, l, md, i, j), qry(v*2+1, md+1, r, i, j));
}
void update(int v, int l, int r, int pos, ll val, bool type){
    if(pos < l || r < pos) return;
    if(l == r){
        if(type) st[v].fi.se = max(val, st[v].fi.se);
        else st[v].fi.fi = max(val, st[v].fi.fi);
        st[v].se = st[v].fi.fi+st[v].fi.se;
        return;
    }
    int md = (l+r)/2;
    update(v*2, l, md, pos, val, type);
    update(v*2+1, md+1, r, pos, val, type);
    st[v] = combine(st[v*2], st[v*2+1]);
}
int main(){ 
    optimise;
    int n;
    cin >> n;
    vi s(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> s[i];
    }
    stack<ii> st;
    vii rng;
    for (int i = 0; i < n; ++i)
    {
        while(!st.empty() && st.top().fi < s[i]) st.pop();
        if(!st.empty()) rng.pb({st.top().se, i});
        st.push({s[i],i});
    }
    while(!st.empty()) st.pop();
    for (int i = n-1; i >= 0; --i)
    {
        while(!st.empty() && st.top().fi < s[i]) st.pop();
        if(!st.empty()) rng.pb({i,st.top().se});
        st.push({s[i],i});
    }
    sort(rng.begin(), rng.end(), greater<ii>());
    int q;
    cin >> q;
    ve<pair<ii,int>> query;
    int cnt = 0;
    while(q--){
        int a,b;
        cin >> a >> b;
        a--,b--;
        query.pb({{a,b},cnt});
        cnt++;
    }
    sort(query.begin(), query.end(), cmp);
    for (int i = 0; i < n; ++i)
    {
        update(1,0,n-1,i,s[i],1);
    }
    ve<ll> ans(cnt);
    q = cnt;
    cnt = 0;
    for (int i = 0; i < q; ++i)
    {
        int x = query[i].fi.fi, y = query[i].fi.se, ind = query[i].se;
        while(cnt < rng.size() &&  rng[cnt].fi >= x){
            int a = rng[cnt].fi, b = rng[cnt].se;
            update(1,0,n-1, b+(b-a) , s[a]+s[b] ,0);
            cnt++;
        }
        ans[ind] = qry(1, 0, n-1, x, y).se;
    }
    for(auto x : ans) cout << x << endl;
}

Compilation message

jumps.cpp: In function 'int main()':
jumps.cpp:101:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |         while(cnt < rng.size() &&  rng[cnt].fi >= x){
      |               ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 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 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 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 920 ms 20540 KB Output is correct
12 Correct 904 ms 20328 KB Output is correct
13 Correct 910 ms 20488 KB Output is correct
14 Correct 909 ms 20500 KB Output is correct
15 Correct 926 ms 20552 KB Output is correct
16 Correct 910 ms 19856 KB Output is correct
17 Correct 900 ms 19948 KB Output is correct
18 Correct 904 ms 19852 KB Output is correct
19 Correct 909 ms 20456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 301 ms 18488 KB Output is correct
2 Correct 164 ms 18360 KB Output is correct
3 Correct 161 ms 18492 KB Output is correct
4 Correct 269 ms 18440 KB Output is correct
5 Correct 260 ms 18368 KB Output is correct
6 Correct 274 ms 17792 KB Output is correct
7 Correct 257 ms 17612 KB Output is correct
8 Correct 253 ms 17644 KB Output is correct
9 Correct 254 ms 18008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 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 920 ms 20540 KB Output is correct
12 Correct 904 ms 20328 KB Output is correct
13 Correct 910 ms 20488 KB Output is correct
14 Correct 909 ms 20500 KB Output is correct
15 Correct 926 ms 20552 KB Output is correct
16 Correct 910 ms 19856 KB Output is correct
17 Correct 900 ms 19948 KB Output is correct
18 Correct 904 ms 19852 KB Output is correct
19 Correct 909 ms 20456 KB Output is correct
20 Correct 301 ms 18488 KB Output is correct
21 Correct 164 ms 18360 KB Output is correct
22 Correct 161 ms 18492 KB Output is correct
23 Correct 269 ms 18440 KB Output is correct
24 Correct 260 ms 18368 KB Output is correct
25 Correct 274 ms 17792 KB Output is correct
26 Correct 257 ms 17612 KB Output is correct
27 Correct 253 ms 17644 KB Output is correct
28 Correct 254 ms 18008 KB Output is correct
29 Correct 1796 ms 62760 KB Output is correct
30 Correct 1543 ms 63908 KB Output is correct
31 Correct 1528 ms 60792 KB Output is correct
32 Correct 1813 ms 62836 KB Output is correct
33 Correct 1797 ms 62876 KB Output is correct
34 Correct 1799 ms 60556 KB Output is correct
35 Correct 1802 ms 60220 KB Output is correct
36 Correct 1909 ms 60084 KB Output is correct
37 Correct 1798 ms 61556 KB Output is correct
38 Correct 1617 ms 62724 KB Output is correct
39 Correct 1643 ms 62872 KB Output is correct
40 Correct 1622 ms 59444 KB Output is correct
41 Correct 1668 ms 58944 KB Output is correct
42 Correct 1622 ms 58912 KB Output is correct
43 Correct 1633 ms 60940 KB Output is correct
44 Correct 1653 ms 62948 KB Output is correct
45 Correct 1644 ms 62768 KB Output is correct
46 Correct 1651 ms 59676 KB Output is correct
47 Correct 1639 ms 59184 KB Output is correct
48 Correct 1640 ms 59248 KB Output is correct
49 Correct 1681 ms 61268 KB Output is correct
50 Correct 1751 ms 62816 KB Output is correct
51 Correct 1868 ms 62780 KB Output is correct
52 Correct 1829 ms 60300 KB Output is correct
53 Correct 1750 ms 59976 KB Output is correct
54 Correct 1692 ms 60100 KB Output is correct
55 Correct 1708 ms 61640 KB Output is correct