답안 #859323

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
859323 2023-10-10T04:05:04 Z nnhzzz 3단 점프 (JOI19_jumps) C++14
100 / 100
482 ms 91476 KB
#include<bits/stdc++.h>

using namespace std;

#define task "test"
#define REP(i,a,b) for(int i = (a); i<=(b); ++i)
#define REPD(i,a,b) for(int i = (a); i>=(b); --i)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int)(x).size()
#define BIT(x,i) ((x>>i)&1LL)
#define MASK(i) (1LL<<i)
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int,int>
//-----------------------------------------------------------------------//
const int oo = 1e9,LOG = 19,MAXN = MASK(19),N = 1e2+3;
const int MOD = 1e9+7,MOD1 = 1e9+207,MOD2 = 1e9+407,MOD3 = 998244353;
//-----------------------------------------------------------------------//
template<typename T> bool mini(T &a, T b){if(a>b){a=b;return true;} return false;}
template<typename T> bool maxi(T &a, T b){if(a<b){a=b;return true;} return false;}

int a[MAXN],res[MAXN];
vector<pii> query[MAXN],adj[MAXN];
int n,q;

struct Node{
    int a,b,v;
    Node(){a = b = v = 0;}
    Node(int a, int b, int v):a(a),b(b),v(v){}
    friend Node operator + (const Node &l, const Node &r){
        return Node(max(l.a,r.a),max(l.b,r.b),max({l.v,r.v,l.a+r.b}));
    }
}seg[MAXN<<1];

void update(int x, int v){
    x |= MAXN;
    maxi(seg[x].a,v);
    seg[x].v = seg[x].a+seg[x].b;
    while(x >>= 1) seg[x] = seg[x<<1]+seg[x<<1|1];
}

int get(int l, int r){
    Node cl,cr; l |= MAXN; r |= MAXN;
    while(l<=r){
        if(l&1) cl = cl+seg[l++];
        if(~r&1) cr = seg[r--]+cr;
        l >>= 1; r >>= 1;
    }
    return (cl+cr).v;
}

void sub4(){
    REP(i,0,MAXN-1) seg[i|MAXN].b = seg[i|MAXN].v = a[i];
    REPD(i,MAXN-1,0) seg[i] = seg[i<<1]+seg[i<<1|1];
    REP(i,1,q){
        int l,r; cin >> l >> r;
        query[l].emplace_back(r,i);
    }
    stack<int> st;
    REP(i,1,n){
        while(SZ(st)!=0){
            int j = st.top();
            adj[j].emplace_back(i,a[i]+a[j]);
            if(a[i]<=a[j]) break;
            st.pop();
        }
        st.push(i);
    }
    REPD(i,n,1){
        for(auto &it:adj[i]){
            int id = it.fi,val = it.se;
            if(id*2-i>n) continue;
            update(id*2-i,val);
        }
        for(auto &it:query[i]){
            int j = it.fi,id = it.se;
            res[id] = get(i,j);
        }
    }
    REP(i,1,q) cout << res[i] << "\n";
}

void solve(){
    cin >> n;
    REP(i,1,n){
        cin >> a[i];
    }
    cin >> q;
    sub4(); return;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if(fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    solve();
    return 0;
}

Compilation message

jumps.cpp: In function 'int main()':
jumps.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
jumps.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 39512 KB Output is correct
2 Correct 10 ms 39516 KB Output is correct
3 Correct 12 ms 39388 KB Output is correct
4 Correct 10 ms 39512 KB Output is correct
5 Correct 10 ms 39516 KB Output is correct
6 Correct 11 ms 39512 KB Output is correct
7 Correct 10 ms 39588 KB Output is correct
8 Correct 10 ms 39516 KB Output is correct
9 Correct 11 ms 39516 KB Output is correct
10 Correct 10 ms 39632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 39512 KB Output is correct
2 Correct 10 ms 39516 KB Output is correct
3 Correct 12 ms 39388 KB Output is correct
4 Correct 10 ms 39512 KB Output is correct
5 Correct 10 ms 39516 KB Output is correct
6 Correct 11 ms 39512 KB Output is correct
7 Correct 10 ms 39588 KB Output is correct
8 Correct 10 ms 39516 KB Output is correct
9 Correct 11 ms 39516 KB Output is correct
10 Correct 10 ms 39632 KB Output is correct
11 Correct 143 ms 54100 KB Output is correct
12 Correct 142 ms 53844 KB Output is correct
13 Correct 138 ms 53992 KB Output is correct
14 Correct 144 ms 53900 KB Output is correct
15 Correct 147 ms 53916 KB Output is correct
16 Correct 144 ms 53328 KB Output is correct
17 Correct 148 ms 53216 KB Output is correct
18 Correct 145 ms 53332 KB Output is correct
19 Correct 145 ms 53840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 47696 KB Output is correct
2 Correct 47 ms 46416 KB Output is correct
3 Correct 49 ms 47192 KB Output is correct
4 Correct 80 ms 47700 KB Output is correct
5 Correct 80 ms 47444 KB Output is correct
6 Correct 78 ms 47700 KB Output is correct
7 Correct 81 ms 47696 KB Output is correct
8 Correct 78 ms 47708 KB Output is correct
9 Correct 80 ms 47700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 39512 KB Output is correct
2 Correct 10 ms 39516 KB Output is correct
3 Correct 12 ms 39388 KB Output is correct
4 Correct 10 ms 39512 KB Output is correct
5 Correct 10 ms 39516 KB Output is correct
6 Correct 11 ms 39512 KB Output is correct
7 Correct 10 ms 39588 KB Output is correct
8 Correct 10 ms 39516 KB Output is correct
9 Correct 11 ms 39516 KB Output is correct
10 Correct 10 ms 39632 KB Output is correct
11 Correct 143 ms 54100 KB Output is correct
12 Correct 142 ms 53844 KB Output is correct
13 Correct 138 ms 53992 KB Output is correct
14 Correct 144 ms 53900 KB Output is correct
15 Correct 147 ms 53916 KB Output is correct
16 Correct 144 ms 53328 KB Output is correct
17 Correct 148 ms 53216 KB Output is correct
18 Correct 145 ms 53332 KB Output is correct
19 Correct 145 ms 53840 KB Output is correct
20 Correct 86 ms 47696 KB Output is correct
21 Correct 47 ms 46416 KB Output is correct
22 Correct 49 ms 47192 KB Output is correct
23 Correct 80 ms 47700 KB Output is correct
24 Correct 80 ms 47444 KB Output is correct
25 Correct 78 ms 47700 KB Output is correct
26 Correct 81 ms 47696 KB Output is correct
27 Correct 78 ms 47708 KB Output is correct
28 Correct 80 ms 47700 KB Output is correct
29 Correct 482 ms 84088 KB Output is correct
30 Correct 366 ms 82808 KB Output is correct
31 Correct 357 ms 84772 KB Output is correct
32 Correct 451 ms 85840 KB Output is correct
33 Correct 472 ms 86124 KB Output is correct
34 Correct 449 ms 83796 KB Output is correct
35 Correct 442 ms 83380 KB Output is correct
36 Correct 447 ms 83192 KB Output is correct
37 Correct 465 ms 85240 KB Output is correct
38 Correct 332 ms 91476 KB Output is correct
39 Correct 332 ms 91476 KB Output is correct
40 Correct 332 ms 88548 KB Output is correct
41 Correct 327 ms 87636 KB Output is correct
42 Correct 323 ms 87892 KB Output is correct
43 Correct 325 ms 89460 KB Output is correct
44 Correct 352 ms 91048 KB Output is correct
45 Correct 344 ms 91052 KB Output is correct
46 Correct 362 ms 87832 KB Output is correct
47 Correct 338 ms 87528 KB Output is correct
48 Correct 343 ms 87436 KB Output is correct
49 Correct 337 ms 89552 KB Output is correct
50 Correct 386 ms 88884 KB Output is correct
51 Correct 379 ms 88836 KB Output is correct
52 Correct 378 ms 86592 KB Output is correct
53 Correct 370 ms 86348 KB Output is correct
54 Correct 370 ms 85948 KB Output is correct
55 Correct 376 ms 87636 KB Output is correct