답안 #121588

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
121588 2019-06-26T19:50:25 Z duality Bitaro, who Leaps through Time (JOI19_timeleap) C++11
4 / 100
3000 ms 26428 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];
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]--;
    }

    for (i = 0; i < N-1; i++) l[i] = L[i]-i,r[i] = R[i]-i-1;
    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;
        else if ((T[i] == 2) && (A[i] <= C[i])) {
            int t = B[i]-A[i];
            LLI sum = 0;
            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];
            }
            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 < N-1; i++) l[i] = L[i]-i,r[i] = R[i]-i-1;
    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;
        else if ((T[i] == 2) && (A[i] <= C[i])) {
            int t = B[i]-A[i];
            LLI sum = 0;
            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];
            }
            if (t > D[i]-C[i]) sum += t-(D[i]-C[i]);
            ans[i] = sum;
        }
    }

    for (i = 0; i < Q; i++) {
        if (ans[i] != -1) printf("%lld\n",ans[i]);
    }

    return 0;
}

Compilation message

timeleap.cpp: In function 'int main()':
timeleap.cpp:65: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:66: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:68:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&T[i]);
         ~~~~~^~~~~~~~~~~~
timeleap.cpp:69: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:70:65: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         else scanf("%d %d %d %d",&A[i],&B[i],&C[i],&D[i]),A[i]--,C[i]--;
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
# 결과 실행 시간 메모리 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 4 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 4 ms 512 KB Output is correct
16 Correct 4 ms 512 KB Output is correct
17 Correct 4 ms 640 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 4 ms 640 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 4 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 3 ms 512 KB Output is correct
29 Correct 4 ms 512 KB Output is correct
30 Correct 4 ms 512 KB Output is correct
31 Correct 4 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 640 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 4 ms 384 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 Execution timed out 3035 ms 26428 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 4 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 4 ms 512 KB Output is correct
16 Correct 4 ms 512 KB Output is correct
17 Correct 4 ms 640 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 4 ms 640 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 4 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 3 ms 512 KB Output is correct
29 Correct 4 ms 512 KB Output is correct
30 Correct 4 ms 512 KB Output is correct
31 Correct 4 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 640 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 4 ms 384 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Execution timed out 3035 ms 26428 KB Time limit exceeded
43 Halted 0 ms 0 KB -