답안 #404323

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
404323 2021-05-14T07:49:39 Z Ruxandra985 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1746 ms 100488 KB
#include <bits/stdc++.h>
#define DIMN 1000010
using namespace std;

int v[DIMN] , bigger[DIMN] , st[DIMN] , sol[DIMN];
vector <pair <int , pair <int , int> > > q[DIMN];

int aint[4 * DIMN];


void update (int nod , int st , int dr , int poz , int sum){
    int mid = (st + dr)/2;

    if (st == dr){
        aint[nod] = max(aint[nod] , sum);
        return;
    }

    if (poz <= mid)
        update (2 * nod , st , mid , poz , sum);
    else update (2 * nod + 1 , mid + 1 , dr , poz , sum);

    aint[nod] = max(aint[2 * nod] , aint[2 * nod + 1]);

}

int query (int nod , int st , int dr , int l , int r){
    int mid = (st + dr) / 2 , maxi = -1;

    if (l <= st && dr <= r){
        return aint[nod];
    }

    if (l <= mid)
        maxi = max(maxi , query(2 * nod , st , mid , l , r));

    if (mid + 1 <= r)
        maxi = max(maxi , query (2 * nod + 1 , mid + 1 , dr , l , r));

    return maxi;
}

int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int n , qr , i , l , r , k , elem , j , idx;
    fscanf (fin,"%d%d",&n,&qr);
    elem = 0;
    for (i = 1 ; i <= n ; i++){
        fscanf (fin,"%d",&v[i]);
        while (elem && v[st[elem]] <= v[i])
            elem--;

        bigger[i] = st[elem];
        st[++elem] = i;

    }

    /// bigger[i] = primul > v[i] de la stanga lui i

    for (i = 1 ; i <= qr ; i++){
        fscanf (fin,"%d%d%d", &l , &r , &k);

        q[r].push_back(make_pair(l , make_pair(k , i)));

    }


    for (i = 1 ; i <= n ; i++){

        /// adaugi i ul pt evaluat
        if (bigger[i])
            update(1 , 1 , n , bigger[i] , v[i] + v[bigger[i]]);

        for (j = 0 ; j < q[i].size() ; j++){

            r = i;
            l = q[i][j].first;
            k = q[i][j].second.first;
            idx = q[i][j].second.second;

            /// query de la l in colo, suma maxima

            sol[idx] = (query(1 , 1 , n , l , r) <= k);

        }

    }


    for (i = 1 ; i <= qr ; i++){
        fprintf (fout,"%d\n",sol[i]);
    }

    return 0;
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:76:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for (j = 0 ; j < q[i].size() ; j++){
      |                      ~~^~~~~~~~~~~~~
sortbooks.cpp:48:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     fscanf (fin,"%d%d",&n,&qr);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
sortbooks.cpp:51:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         fscanf (fin,"%d",&v[i]);
      |         ~~~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:63:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         fscanf (fin,"%d%d%d", &l , &r , &k);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Correct 14 ms 23784 KB Output is correct
4 Correct 13 ms 23796 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 14 ms 23792 KB Output is correct
7 Correct 15 ms 23812 KB Output is correct
8 Correct 14 ms 23756 KB Output is correct
9 Correct 14 ms 23756 KB Output is correct
10 Correct 14 ms 23756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Correct 14 ms 23784 KB Output is correct
4 Correct 13 ms 23796 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 14 ms 23792 KB Output is correct
7 Correct 15 ms 23812 KB Output is correct
8 Correct 14 ms 23756 KB Output is correct
9 Correct 14 ms 23756 KB Output is correct
10 Correct 14 ms 23756 KB Output is correct
11 Correct 16 ms 24016 KB Output is correct
12 Correct 18 ms 24064 KB Output is correct
13 Correct 18 ms 24116 KB Output is correct
14 Correct 19 ms 24204 KB Output is correct
15 Correct 19 ms 24140 KB Output is correct
16 Correct 18 ms 24068 KB Output is correct
17 Correct 17 ms 24012 KB Output is correct
18 Correct 17 ms 24088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1707 ms 67536 KB Output is correct
2 Correct 1701 ms 100488 KB Output is correct
3 Correct 1746 ms 100344 KB Output is correct
4 Correct 1708 ms 100328 KB Output is correct
5 Correct 1389 ms 92108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 28296 KB Output is correct
2 Correct 122 ms 30016 KB Output is correct
3 Correct 118 ms 29156 KB Output is correct
4 Correct 110 ms 29252 KB Output is correct
5 Correct 111 ms 29260 KB Output is correct
6 Correct 103 ms 28680 KB Output is correct
7 Correct 98 ms 28624 KB Output is correct
8 Correct 107 ms 28848 KB Output is correct
9 Correct 59 ms 27244 KB Output is correct
10 Correct 102 ms 28852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Correct 14 ms 23784 KB Output is correct
4 Correct 13 ms 23796 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 14 ms 23792 KB Output is correct
7 Correct 15 ms 23812 KB Output is correct
8 Correct 14 ms 23756 KB Output is correct
9 Correct 14 ms 23756 KB Output is correct
10 Correct 14 ms 23756 KB Output is correct
11 Correct 16 ms 24016 KB Output is correct
12 Correct 18 ms 24064 KB Output is correct
13 Correct 18 ms 24116 KB Output is correct
14 Correct 19 ms 24204 KB Output is correct
15 Correct 19 ms 24140 KB Output is correct
16 Correct 18 ms 24068 KB Output is correct
17 Correct 17 ms 24012 KB Output is correct
18 Correct 17 ms 24088 KB Output is correct
19 Correct 293 ms 39524 KB Output is correct
20 Correct 298 ms 39348 KB Output is correct
21 Correct 257 ms 38728 KB Output is correct
22 Correct 259 ms 38668 KB Output is correct
23 Correct 254 ms 38728 KB Output is correct
24 Correct 212 ms 36552 KB Output is correct
25 Correct 210 ms 36676 KB Output is correct
26 Correct 226 ms 36944 KB Output is correct
27 Correct 228 ms 36932 KB Output is correct
28 Correct 235 ms 36932 KB Output is correct
29 Correct 240 ms 37328 KB Output is correct
30 Correct 241 ms 37300 KB Output is correct
31 Correct 244 ms 37372 KB Output is correct
32 Correct 256 ms 37316 KB Output is correct
33 Correct 244 ms 37392 KB Output is correct
34 Correct 198 ms 36136 KB Output is correct
35 Correct 248 ms 36092 KB Output is correct
36 Correct 201 ms 35908 KB Output is correct
37 Correct 196 ms 36000 KB Output is correct
38 Correct 198 ms 36060 KB Output is correct
39 Correct 230 ms 36324 KB Output is correct
40 Correct 176 ms 34040 KB Output is correct
41 Correct 219 ms 35144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Correct 14 ms 23784 KB Output is correct
4 Correct 13 ms 23796 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 14 ms 23792 KB Output is correct
7 Correct 15 ms 23812 KB Output is correct
8 Correct 14 ms 23756 KB Output is correct
9 Correct 14 ms 23756 KB Output is correct
10 Correct 14 ms 23756 KB Output is correct
11 Correct 16 ms 24016 KB Output is correct
12 Correct 18 ms 24064 KB Output is correct
13 Correct 18 ms 24116 KB Output is correct
14 Correct 19 ms 24204 KB Output is correct
15 Correct 19 ms 24140 KB Output is correct
16 Correct 18 ms 24068 KB Output is correct
17 Correct 17 ms 24012 KB Output is correct
18 Correct 17 ms 24088 KB Output is correct
19 Correct 1707 ms 67536 KB Output is correct
20 Correct 1701 ms 100488 KB Output is correct
21 Correct 1746 ms 100344 KB Output is correct
22 Correct 1708 ms 100328 KB Output is correct
23 Correct 1389 ms 92108 KB Output is correct
24 Correct 125 ms 28296 KB Output is correct
25 Correct 122 ms 30016 KB Output is correct
26 Correct 118 ms 29156 KB Output is correct
27 Correct 110 ms 29252 KB Output is correct
28 Correct 111 ms 29260 KB Output is correct
29 Correct 103 ms 28680 KB Output is correct
30 Correct 98 ms 28624 KB Output is correct
31 Correct 107 ms 28848 KB Output is correct
32 Correct 59 ms 27244 KB Output is correct
33 Correct 102 ms 28852 KB Output is correct
34 Correct 293 ms 39524 KB Output is correct
35 Correct 298 ms 39348 KB Output is correct
36 Correct 257 ms 38728 KB Output is correct
37 Correct 259 ms 38668 KB Output is correct
38 Correct 254 ms 38728 KB Output is correct
39 Correct 212 ms 36552 KB Output is correct
40 Correct 210 ms 36676 KB Output is correct
41 Correct 226 ms 36944 KB Output is correct
42 Correct 228 ms 36932 KB Output is correct
43 Correct 235 ms 36932 KB Output is correct
44 Correct 240 ms 37328 KB Output is correct
45 Correct 241 ms 37300 KB Output is correct
46 Correct 244 ms 37372 KB Output is correct
47 Correct 256 ms 37316 KB Output is correct
48 Correct 244 ms 37392 KB Output is correct
49 Correct 198 ms 36136 KB Output is correct
50 Correct 248 ms 36092 KB Output is correct
51 Correct 201 ms 35908 KB Output is correct
52 Correct 196 ms 36000 KB Output is correct
53 Correct 198 ms 36060 KB Output is correct
54 Correct 230 ms 36324 KB Output is correct
55 Correct 176 ms 34040 KB Output is correct
56 Correct 219 ms 35144 KB Output is correct
57 Correct 1736 ms 100484 KB Output is correct
58 Correct 1728 ms 100432 KB Output is correct
59 Correct 1612 ms 98920 KB Output is correct
60 Correct 1606 ms 98896 KB Output is correct
61 Correct 1596 ms 98888 KB Output is correct
62 Correct 1629 ms 98920 KB Output is correct
63 Correct 1046 ms 87512 KB Output is correct
64 Correct 1082 ms 87484 KB Output is correct
65 Correct 1356 ms 90588 KB Output is correct
66 Correct 1376 ms 90552 KB Output is correct
67 Correct 1370 ms 90644 KB Output is correct
68 Correct 1418 ms 92324 KB Output is correct
69 Correct 1387 ms 92268 KB Output is correct
70 Correct 1401 ms 91984 KB Output is correct
71 Correct 1400 ms 92192 KB Output is correct
72 Correct 1399 ms 92088 KB Output is correct
73 Correct 967 ms 83768 KB Output is correct
74 Correct 979 ms 84460 KB Output is correct
75 Correct 976 ms 83704 KB Output is correct
76 Correct 1006 ms 83672 KB Output is correct
77 Correct 996 ms 83440 KB Output is correct
78 Correct 1258 ms 87268 KB Output is correct
79 Correct 892 ms 73676 KB Output is correct
80 Correct 1250 ms 81584 KB Output is correct