Submission #224056

# Submission time Handle Problem Language Result Execution time Memory
224056 2020-04-17T06:45:39 Z cheeheng Fire (JOI20_ho_t5) C++14
8 / 100
1000 ms 17912 KB
#include <bits/stdc++.h>
using namespace std;

long long S[200005];

long long val[(1<<20)+5];
long long lazyadd[(1<<20)+5];

int N;

inline int left1(int x){
    return (x<<1)+1;
}

inline int right1(int x){
    return (x<<1)+2;
}

void init(int i = 0, int s = 1, int e = N){
    int m = (s+e)>>1;
    lazyadd[i] = 0;
    if(s == e){
        val[i] = S[s];
    }else{
        int l = left1(i);
        int r = right1(i);
        init(l, s, m);
        init(r, m+1, e);
        val[i] = max(val[l], val[r]);
    }
}

long long rmq(int x, int y, int i = 0, int s = 1, int e = N){
    int m = (s+e)>>1;
    if(x <= s && e <= y){
        return val[i];
    }

    int l = left1(i);
    int r = right1(i);
    if(x > m){
        return rmq(x, y, r, m+1, e);
    }else if(y <= m){
        return rmq(x, y, l, s, m);
    }else{
        return max(rmq(x, y, r, m+1, e), rmq(x, y, l, s, m));
    }
}

int main(){
    int Q;
    scanf("%d%d", &N, &Q);

    for(int i = 1; i <= N; i ++){
        scanf("%d", &S[i]);
    }

    init();

    for(int i = 1; i <= Q; i ++){
        int t, l, r;
        scanf("%d%d%d", &t, &l, &r);

        long long ans = 0;
        for(int j = l; j <= r; j ++){
            //printf("%d ", rmq(max(j-t, 1), j));
            ans += rmq(max(j-t, 1), j);
        }
        //printf("\n");
        printf("%lld\n", ans);
    }
}

Compilation message

ho_t5.cpp: In function 'int main()':
ho_t5.cpp:55:26: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
         scanf("%d", &S[i]);
                     ~~~~~^
ho_t5.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &Q);
     ~~~~~^~~~~~~~~~~~~~~~
ho_t5.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &S[i]);
         ~~~~~^~~~~~~~~~~~~
ho_t5.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &t, &l, &r);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Execution timed out 1093 ms 12152 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 214 ms 17784 KB Output is correct
3 Correct 204 ms 17528 KB Output is correct
4 Correct 209 ms 17784 KB Output is correct
5 Correct 208 ms 17528 KB Output is correct
6 Correct 223 ms 17656 KB Output is correct
7 Correct 206 ms 17528 KB Output is correct
8 Correct 209 ms 17656 KB Output is correct
9 Correct 207 ms 17656 KB Output is correct
10 Correct 203 ms 17400 KB Output is correct
11 Correct 211 ms 17760 KB Output is correct
12 Correct 204 ms 17528 KB Output is correct
13 Correct 225 ms 17912 KB Output is correct
14 Correct 207 ms 17528 KB Output is correct
15 Correct 211 ms 17656 KB Output is correct
16 Correct 208 ms 17656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1098 ms 10616 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Execution timed out 1090 ms 12152 KB Time limit exceeded
34 Halted 0 ms 0 KB -