답안 #119141

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
119141 2019-06-20T13:14:02 Z songc Bitaro, who Leaps through Time (JOI19_timeleap) C++14
100 / 100
1027 ms 86416 KB
#include <bits/stdc++.h>
#define INF 1234567890123456ll
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

int N, Q;

struct Node{
    LL lr, rl, ll, rr;

    Node operator+(const Node &r)const{
        Node ret;
        ret.lr = max(lr, r.lr);
        ret.lr = max(ret.lr, lr + r.lr);
        ret.lr = max(ret.lr, ll + r.rr);

        ret.rl = max(rl, r.rl);
        ret.rl = max(ret.rl, rl + r.rl);
        ret.rl = max(ret.rl, rr + r.ll);

        ret.ll = max(ll, r.ll);
        ret.ll = max(ret.ll, lr + r.ll);
        ret.ll = max(ret.ll, ll + r.rl);

        ret.rr = max(rr, r.rr);
        ret.rr = max(ret.rr, rr + r.lr);
        ret.rr = max(ret.rr, rl + r.rr);
        return ret;
    }
} T[1202020], rT[1202020];

void update(int id, int s, int e, int t, Node x){
    if (e < t || t < s) return;
    if (s == e){
        T[id] = x;
        return;
    }
    int mid = (s+e)/2;
    update(id*2, s, mid, t, x);
    update(id*2+1, mid+1, e, t, x);
    T[id] = T[id*2] + T[id*2+1];
}

Node query(int id, int s, int e, int ts, int te){
    if (e < ts || te < s) return (Node){-INF,-INF,-INF,-INF};
    if (ts <= s && e <= te) return T[id];
    int mid = (s+e)/2;
    return query(id*2, s, mid, ts, te) + query(id*2+1, mid+1, e, ts, te);
}

void rupdate(int id, int s, int e, int t, Node x){
    if (e < t || t < s) return;
    if (s == e){
        rT[id] = x;
        return;
    }
    int mid = (s+e)/2;
    rupdate(id*2, s, mid, t, x);
    rupdate(id*2+1, mid+1, e, t, x);
    rT[id] = rT[id*2] + rT[id*2+1];
}

Node rquery(int id, int s, int e, int ts, int te){
    if (e < ts || te < s) return (Node){-INF,-INF,-INF,-INF};
    if (ts <= s && e <= te) return rT[id];
    int mid = (s+e)/2;
    return rquery(id*2, s, mid, ts, te) + rquery(id*2+1, mid+1, e, ts, te);
}

int main(){
    LL a, b, c, d;
    scanf("%d %d", &N, &Q);
    for (int i=1; i<N; i++){
        scanf("%lld %lld", &a, &b);
        update(1, 1, N, i, (Node){-INF, -INF, a-i, -b+1+i});
        rupdate(1, 1, N, N-i, (Node){-INF, -INF, a-N+i, -b+1+N-i});
    }
    while (Q--){
        scanf("%lld", &a);
        if (a == 1){
            scanf("%lld %lld %lld", &a, &b, &c);
            update(1, 1, N, a, (Node){-INF, -INF, b-a, -c+1+a});
            rupdate(1, 1, N, N-a, (Node){-INF, -INF, b-N+a, -c+1+N-a});
        }
        else{
            scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
            if (a <= c){
                Node ret = query(1, 1, N, a, c-1);
                printf("%lld\n", max(((Node){-INF,-INF,b-a,-b+a}+ret+(Node){-INF,-INF,d-c,-d+c}).lr, 0ll));
            }
            else{
                Node ret = rquery(1, 1, N, N+1-a, N-c);
                printf("%lld\n", max(((Node){-INF,-INF,b-N-1+a,-b+N+1-a}+ret+(Node){-INF,-INF,d-N-1+c,-d+N+1-c}).lr, 0ll));
            }
        }
    }
    return 0;
}

Compilation message

timeleap.cpp: In function 'int main()':
timeleap.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &Q);
     ~~~~~^~~~~~~~~~~~~~~~~
timeleap.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
timeleap.cpp:80:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &a);
         ~~~~~^~~~~~~~~~~~
timeleap.cpp:82:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld %lld %lld", &a, &b, &c);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
timeleap.cpp:87:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 4 ms 512 KB Output is correct
12 Correct 4 ms 512 KB Output is correct
13 Correct 4 ms 512 KB Output is correct
14 Correct 4 ms 512 KB Output is correct
15 Correct 4 ms 512 KB Output is correct
16 Correct 4 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 4 ms 512 KB Output is correct
19 Correct 4 ms 512 KB Output is correct
20 Correct 4 ms 512 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 484 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 4 ms 512 KB Output is correct
28 Correct 4 ms 512 KB Output is correct
29 Correct 4 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 4 ms 512 KB Output is correct
33 Correct 4 ms 512 KB Output is correct
34 Correct 4 ms 512 KB Output is correct
35 Correct 3 ms 512 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 4 ms 512 KB Output is correct
38 Correct 4 ms 512 KB Output is correct
39 Correct 4 ms 512 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 871 ms 85784 KB Output is correct
2 Correct 843 ms 52600 KB Output is correct
3 Correct 852 ms 52616 KB Output is correct
4 Correct 874 ms 52492 KB Output is correct
5 Correct 905 ms 85980 KB Output is correct
6 Correct 898 ms 85624 KB Output is correct
7 Correct 898 ms 85752 KB Output is correct
8 Correct 929 ms 86416 KB Output is correct
9 Correct 868 ms 52728 KB Output is correct
10 Correct 895 ms 85972 KB Output is correct
11 Correct 863 ms 85828 KB Output is correct
12 Correct 871 ms 86264 KB Output is correct
13 Correct 894 ms 86228 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 4 ms 512 KB Output is correct
12 Correct 4 ms 512 KB Output is correct
13 Correct 4 ms 512 KB Output is correct
14 Correct 4 ms 512 KB Output is correct
15 Correct 4 ms 512 KB Output is correct
16 Correct 4 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 4 ms 512 KB Output is correct
19 Correct 4 ms 512 KB Output is correct
20 Correct 4 ms 512 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 484 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 4 ms 512 KB Output is correct
28 Correct 4 ms 512 KB Output is correct
29 Correct 4 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 4 ms 512 KB Output is correct
33 Correct 4 ms 512 KB Output is correct
34 Correct 4 ms 512 KB Output is correct
35 Correct 3 ms 512 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 4 ms 512 KB Output is correct
38 Correct 4 ms 512 KB Output is correct
39 Correct 4 ms 512 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 871 ms 85784 KB Output is correct
43 Correct 843 ms 52600 KB Output is correct
44 Correct 852 ms 52616 KB Output is correct
45 Correct 874 ms 52492 KB Output is correct
46 Correct 905 ms 85980 KB Output is correct
47 Correct 898 ms 85624 KB Output is correct
48 Correct 898 ms 85752 KB Output is correct
49 Correct 929 ms 86416 KB Output is correct
50 Correct 868 ms 52728 KB Output is correct
51 Correct 895 ms 85972 KB Output is correct
52 Correct 863 ms 85828 KB Output is correct
53 Correct 871 ms 86264 KB Output is correct
54 Correct 894 ms 86228 KB Output is correct
55 Correct 2 ms 256 KB Output is correct
56 Correct 914 ms 82760 KB Output is correct
57 Correct 864 ms 49528 KB Output is correct
58 Correct 934 ms 82848 KB Output is correct
59 Correct 930 ms 83020 KB Output is correct
60 Correct 897 ms 49784 KB Output is correct
61 Correct 954 ms 83188 KB Output is correct
62 Correct 946 ms 83068 KB Output is correct
63 Correct 960 ms 83200 KB Output is correct
64 Correct 926 ms 83064 KB Output is correct
65 Correct 1027 ms 82808 KB Output is correct
66 Correct 908 ms 82936 KB Output is correct
67 Correct 929 ms 83208 KB Output is correct
68 Correct 861 ms 68496 KB Output is correct
69 Correct 886 ms 83156 KB Output is correct
70 Correct 815 ms 49636 KB Output is correct
71 Correct 827 ms 49016 KB Output is correct
72 Correct 820 ms 60152 KB Output is correct
73 Correct 898 ms 82680 KB Output is correct
74 Correct 889 ms 82492 KB Output is correct
75 Correct 902 ms 82696 KB Output is correct
76 Correct 956 ms 83300 KB Output is correct
77 Correct 3 ms 384 KB Output is correct