Submission #121628

# Submission time Handle Problem Language Result Execution time Memory
121628 2019-06-26T21:03:26 Z duality Bitaro, who Leaps through Time (JOI19_timeleap) C++11
34 / 100
2029 ms 17992 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int L[300000],R[300000];
int T[300000],A[300000],B[300000],C[300000],D[300000];
int l[300000],r[300000];
LLI ans[300000];
struct func {
    LLI b,x1,x2;
    LLI b2,x3;
    int init() { b = x1 = 0,x2 = 1e12; b2 = 0,x3 = 1e12; }
    int apply(int l,int r) {
        if (x1 == x2) {
            if (b < l) b = l;
            else if (b > r) b2 += b-r,b = r;
        }
        else {
            if (l > b+x2-x1) x1 = x2 = 0,b = l;
            else if (l > b) x1 += l-b,b = l;
            if (r < b) {
                b2 += b-r,x3 = x1;
                x1 = x2 = 0,b = r;
            }
            else if (r < b+x2-x1) x2 = x3 = x2-(b+x2-x1-r);
        }
        return 0;
    }
    plli eval(int x) {
        LLI p,q;
        if (x < x1) p = b;
        else if (x < x2) p = b+x-x1;
        else p = b+x2-x1;
        if (x < x3) q = b2;
        else q = b2+x-x3;
        return mp(p,q);
    }
};
func f[600];
int main() {
    int i,j;
    int N,Q;
    scanf("%d %d",&N,&Q);
    for (i = 0; i < N-1; i++) scanf("%d %d",&L[i],&R[i]);
    for (i = 0; i < Q; i++) {
        scanf("%d",&T[i]);
        if (T[i] == 1) scanf("%d %d %d",&A[i],&B[i],&C[i]),A[i]--,ans[i] = -1;
        else {
            scanf("%d %d %d %d",&A[i],&B[i],&C[i],&D[i]),A[i]--,C[i]--;
            if (A[i] == C[i]) ans[i] = max(B[i]-D[i],0);
        }
    }

    int rr;
    int bs = sqrt(N)+EPS;
    for (rr = 0; rr < 2; rr++) {
        for (i = 0; i < N-1; i++) l[i] = L[i]-i,r[i] = R[i]-i-1;
        for (i = 0; i < N/bs; i++) f[i].init();
        for (i = 0; i < N-1; i++) f[i/bs].apply(l[i],r[i]);
        for (i = 0; i < Q; i++) {
            if (T[i] == 1) {
                l[A[i]] = B[i]-A[i],r[A[i]] = C[i]-A[i]-1;
                int b = A[i]/bs;
                f[b].init();
                for (j = b*bs; j < min((b+1)*bs,N-1); j++) f[b].apply(l[j],r[j]);
            }
            else if ((T[i] == 2) && (A[i] < C[i])) {
                LLI t = B[i]-A[i],sum = 0;
                if (A[i]/bs == (C[i]-1)/bs) {
                    for (j = A[i]; j < C[i]; j++) {
                        if (t < l[j]) t = l[j];
                        else if (t > r[j]) sum += t-r[j],t = r[j];
                    }
                }
                else {
                    for (j = A[i]; j < (A[i]/bs+1)*bs; j++) {
                        if (t < l[j]) t = l[j];
                        else if (t > r[j]) sum += t-r[j],t = r[j];
                    }
                    for (j = A[i]/bs+1; j < (C[i]-1)/bs; j++) {
                        plli p = f[j].eval(t);
                        sum += p.second,t = p.first;
                    }
                    for (j = ((C[i]-1)/bs)*bs; j < C[i]; j++) {
                        if (t < l[j]) t = l[j];
                        else if (t > r[j]) sum += t-r[j],t = r[j];
                    }
                }
                if (t > (D[i]-C[i])) sum += t-(D[i]-C[i]);
                ans[i] = sum;
            }
        }
        reverse(L,L+N-1),reverse(R,R+N-1);
        for (i = 0; i < Q; i++) {
            if (T[i] == 1) A[i] = N-2-A[i];
            else if (T[i] == 2) A[i] = N-1-A[i],C[i] = N-1-C[i];
        }
    }
    for (i = 0; i < Q; i++) {
        if (ans[i] != -1) printf("%lld\n",ans[i]);
    }

    return 0;
}

Compilation message

timeleap.cpp: In member function 'int func::init()':
timeleap.cpp:65:58: warning: no return statement in function returning non-void [-Wreturn-type]
     int init() { b = x1 = 0,x2 = 1e12; b2 = 0,x3 = 1e12; }
                                                          ^
timeleap.cpp: In function 'int main()':
timeleap.cpp:96: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:97:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (i = 0; i < N-1; i++) scanf("%d %d",&L[i],&R[i]);
                               ~~~~~^~~~~~~~~~~~~~~~~~~~~
timeleap.cpp:99:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&T[i]);
         ~~~~~^~~~~~~~~~~~
timeleap.cpp:100:66: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         if (T[i] == 1) scanf("%d %d %d",&A[i],&B[i],&C[i]),A[i]--,ans[i] = -1;
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
timeleap.cpp:102:64: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d %d %d",&A[i],&B[i],&C[i],&D[i]),A[i]--,C[i]--;
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
# Verdict Execution time Memory 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 384 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 384 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 4 ms 548 KB Output is correct
20 Correct 3 ms 432 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 4 ms 512 KB Output is correct
29 Correct 3 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 3 ms 512 KB Output is correct
33 Correct 3 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 3 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 3 ms 512 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1393 ms 17348 KB Output is correct
2 Correct 1367 ms 17420 KB Output is correct
3 Correct 1364 ms 17352 KB Output is correct
4 Correct 1458 ms 17160 KB Output is correct
5 Correct 1374 ms 17508 KB Output is correct
6 Correct 1364 ms 17528 KB Output is correct
7 Correct 1131 ms 17760 KB Output is correct
8 Correct 1268 ms 17872 KB Output is correct
9 Correct 1121 ms 17540 KB Output is correct
10 Correct 1404 ms 17660 KB Output is correct
11 Correct 1387 ms 17496 KB Output is correct
12 Correct 1441 ms 17912 KB Output is correct
13 Correct 1470 ms 17992 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory 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 384 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 384 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 4 ms 548 KB Output is correct
20 Correct 3 ms 432 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 4 ms 512 KB Output is correct
29 Correct 3 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 3 ms 512 KB Output is correct
33 Correct 3 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 3 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 3 ms 512 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 1393 ms 17348 KB Output is correct
43 Correct 1367 ms 17420 KB Output is correct
44 Correct 1364 ms 17352 KB Output is correct
45 Correct 1458 ms 17160 KB Output is correct
46 Correct 1374 ms 17508 KB Output is correct
47 Correct 1364 ms 17528 KB Output is correct
48 Correct 1131 ms 17760 KB Output is correct
49 Correct 1268 ms 17872 KB Output is correct
50 Correct 1121 ms 17540 KB Output is correct
51 Correct 1404 ms 17660 KB Output is correct
52 Correct 1387 ms 17496 KB Output is correct
53 Correct 1441 ms 17912 KB Output is correct
54 Correct 1470 ms 17992 KB Output is correct
55 Correct 2 ms 384 KB Output is correct
56 Correct 1921 ms 15388 KB Output is correct
57 Correct 1864 ms 15116 KB Output is correct
58 Correct 1955 ms 15596 KB Output is correct
59 Correct 1953 ms 15608 KB Output is correct
60 Correct 1925 ms 15352 KB Output is correct
61 Correct 1977 ms 15796 KB Output is correct
62 Correct 1979 ms 15776 KB Output is correct
63 Correct 1976 ms 15688 KB Output is correct
64 Correct 2029 ms 15716 KB Output is correct
65 Correct 1939 ms 15564 KB Output is correct
66 Correct 1558 ms 15540 KB Output is correct
67 Correct 1633 ms 15608 KB Output is correct
68 Incorrect 1523 ms 15184 KB Output isn't correct
69 Halted 0 ms 0 KB -