답안 #371224

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
371224 2021-02-26T06:51:05 Z daniel920712 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2063 ms 121892 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <utility>
#include <vector>
#include <algorithm>
#include <deque>

using namespace std;
struct A
{
    int l,r;
    int nxl,nxr;
    int big;
}Node[2000005];
vector < pair < pair < int , int > , int > > where[2000005];
deque < int > how;
int all[2000005];
int last[2000005];
int ans[2000005];
int now=1;

void build(int l,int r,int here)
{
    int i;
    Node[here].l=l;
    Node[here].r=r;
    if(l==r)
    {
        Node[here].big=0;
        return;
    }
    Node[here].nxl=now++;
    Node[here].nxr=now++;
    build(l,(l+r)/2,Node[here].nxl);
    build((l+r)/2+1,r,Node[here].nxr);
    Node[here].big=0;
}



int Find(int l,int r,int here)
{
    pair < int , int > t,a,b;
    int c;
    if(Node[here].l==l&&Node[here].r==r) return Node[here].big;
    if(r<=(Node[here].l+Node[here].r)/2) return Find(l,r,Node[here].nxl);
    else if(l>(Node[here].l+Node[here].r)/2) return Find(l,r,Node[here].nxr);
    else return max(Find(l,(Node[here].l+Node[here].r)/2,Node[here].nxl),Find((Node[here].l+Node[here].r)/2+1,Node[here].r,Node[here].nxr));
}
void cha(int where,int con,int here)
{
    pair < int , int > t,a,b;
    int c;
    if(Node[here].l==where&&Node[here].r==where)
    {
        Node[here].big=con;
        return;
    }
    if(where<=(Node[here].l+Node[here].r)/2) cha(where,con,Node[here].nxl);
    else cha(where,con,Node[here].nxr);

    Node[here].big=max(Node[Node[here].nxl].big,Node[Node[here].nxr].big);

}
int main()
{
    int N,M,x,y,z,t,i,j,big;
    scanf("%d %d",&N,&M);
    build(0,N,0);
    for(i=1;i<=N;i++) scanf("%d",&all[i]);
    for(i=0;i<M;i++)
    {
        scanf("%d %d %d",&x,&y,&z);
        where[y].push_back(make_pair(make_pair(x,z),i));
    }

    for(i=1;i<=N;i++)
    {
        while(!how.empty()&&all[i]>=all[how.back()]) how.pop_back();
        if(!how.empty()) cha(how.back(),all[how.back()]+all[i],0);
        how.push_back(i);
        for(auto j:where[i]) ans[j.second]=Find(j.first.first,i,0)<=j.first.second;
    }
    for(i=0;i<M;i++)
    {
        printf("%d\n",ans[i]);
    }


   return 0;
}

Compilation message

sortbooks.cpp: In function 'void build(int, int, int)':
sortbooks.cpp:25:9: warning: unused variable 'i' [-Wunused-variable]
   25 |     int i;
      |         ^
sortbooks.cpp: In function 'int Find(int, int, int)':
sortbooks.cpp:45:9: warning: unused variable 'c' [-Wunused-variable]
   45 |     int c;
      |         ^
sortbooks.cpp: In function 'void cha(int, int, int)':
sortbooks.cpp:54:9: warning: unused variable 'c' [-Wunused-variable]
   54 |     int c;
      |         ^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:68:19: warning: unused variable 't' [-Wunused-variable]
   68 |     int N,M,x,y,z,t,i,j,big;
      |                   ^
sortbooks.cpp:68:23: warning: unused variable 'j' [-Wunused-variable]
   68 |     int N,M,x,y,z,t,i,j,big;
      |                       ^
sortbooks.cpp:68:25: warning: unused variable 'big' [-Wunused-variable]
   68 |     int N,M,x,y,z,t,i,j,big;
      |                         ^~~
sortbooks.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   69 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
sortbooks.cpp:71:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   71 |     for(i=1;i<=N;i++) scanf("%d",&all[i]);
      |                       ~~~~~^~~~~~~~~~~~~~
sortbooks.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   74 |         scanf("%d %d %d",&x,&y,&z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 47340 KB Output is correct
2 Correct 36 ms 47340 KB Output is correct
3 Correct 31 ms 47340 KB Output is correct
4 Correct 31 ms 47340 KB Output is correct
5 Correct 31 ms 47256 KB Output is correct
6 Correct 32 ms 47340 KB Output is correct
7 Correct 31 ms 47340 KB Output is correct
8 Correct 31 ms 47340 KB Output is correct
9 Correct 36 ms 47340 KB Output is correct
10 Correct 32 ms 47340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 47340 KB Output is correct
2 Correct 36 ms 47340 KB Output is correct
3 Correct 31 ms 47340 KB Output is correct
4 Correct 31 ms 47340 KB Output is correct
5 Correct 31 ms 47256 KB Output is correct
6 Correct 32 ms 47340 KB Output is correct
7 Correct 31 ms 47340 KB Output is correct
8 Correct 31 ms 47340 KB Output is correct
9 Correct 36 ms 47340 KB Output is correct
10 Correct 32 ms 47340 KB Output is correct
11 Correct 33 ms 47468 KB Output is correct
12 Correct 35 ms 47724 KB Output is correct
13 Correct 40 ms 47744 KB Output is correct
14 Correct 41 ms 47724 KB Output is correct
15 Correct 38 ms 47596 KB Output is correct
16 Correct 34 ms 47596 KB Output is correct
17 Correct 35 ms 47596 KB Output is correct
18 Correct 35 ms 47596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2025 ms 118064 KB Output is correct
2 Correct 2063 ms 121076 KB Output is correct
3 Correct 2050 ms 121172 KB Output is correct
4 Correct 2060 ms 120944 KB Output is correct
5 Correct 1683 ms 120920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 173 ms 54380 KB Output is correct
2 Correct 158 ms 54124 KB Output is correct
3 Correct 128 ms 54380 KB Output is correct
4 Correct 127 ms 54380 KB Output is correct
5 Correct 137 ms 54380 KB Output is correct
6 Correct 106 ms 53996 KB Output is correct
7 Correct 107 ms 53868 KB Output is correct
8 Correct 129 ms 54180 KB Output is correct
9 Correct 83 ms 49444 KB Output is correct
10 Correct 131 ms 54180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 47340 KB Output is correct
2 Correct 36 ms 47340 KB Output is correct
3 Correct 31 ms 47340 KB Output is correct
4 Correct 31 ms 47340 KB Output is correct
5 Correct 31 ms 47256 KB Output is correct
6 Correct 32 ms 47340 KB Output is correct
7 Correct 31 ms 47340 KB Output is correct
8 Correct 31 ms 47340 KB Output is correct
9 Correct 36 ms 47340 KB Output is correct
10 Correct 32 ms 47340 KB Output is correct
11 Correct 33 ms 47468 KB Output is correct
12 Correct 35 ms 47724 KB Output is correct
13 Correct 40 ms 47744 KB Output is correct
14 Correct 41 ms 47724 KB Output is correct
15 Correct 38 ms 47596 KB Output is correct
16 Correct 34 ms 47596 KB Output is correct
17 Correct 35 ms 47596 KB Output is correct
18 Correct 35 ms 47596 KB Output is correct
19 Correct 332 ms 61548 KB Output is correct
20 Correct 378 ms 61384 KB Output is correct
21 Correct 280 ms 60960 KB Output is correct
22 Correct 271 ms 60908 KB Output is correct
23 Correct 268 ms 60908 KB Output is correct
24 Correct 216 ms 60780 KB Output is correct
25 Correct 207 ms 60780 KB Output is correct
26 Correct 252 ms 61036 KB Output is correct
27 Correct 235 ms 61036 KB Output is correct
28 Correct 250 ms 61164 KB Output is correct
29 Correct 277 ms 61412 KB Output is correct
30 Correct 277 ms 61420 KB Output is correct
31 Correct 302 ms 61420 KB Output is correct
32 Correct 278 ms 61292 KB Output is correct
33 Correct 296 ms 61320 KB Output is correct
34 Correct 201 ms 60524 KB Output is correct
35 Correct 204 ms 60524 KB Output is correct
36 Correct 193 ms 60524 KB Output is correct
37 Correct 222 ms 60524 KB Output is correct
38 Correct 199 ms 60524 KB Output is correct
39 Correct 252 ms 60964 KB Output is correct
40 Correct 221 ms 57760 KB Output is correct
41 Correct 263 ms 60984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 47340 KB Output is correct
2 Correct 36 ms 47340 KB Output is correct
3 Correct 31 ms 47340 KB Output is correct
4 Correct 31 ms 47340 KB Output is correct
5 Correct 31 ms 47256 KB Output is correct
6 Correct 32 ms 47340 KB Output is correct
7 Correct 31 ms 47340 KB Output is correct
8 Correct 31 ms 47340 KB Output is correct
9 Correct 36 ms 47340 KB Output is correct
10 Correct 32 ms 47340 KB Output is correct
11 Correct 33 ms 47468 KB Output is correct
12 Correct 35 ms 47724 KB Output is correct
13 Correct 40 ms 47744 KB Output is correct
14 Correct 41 ms 47724 KB Output is correct
15 Correct 38 ms 47596 KB Output is correct
16 Correct 34 ms 47596 KB Output is correct
17 Correct 35 ms 47596 KB Output is correct
18 Correct 35 ms 47596 KB Output is correct
19 Correct 2025 ms 118064 KB Output is correct
20 Correct 2063 ms 121076 KB Output is correct
21 Correct 2050 ms 121172 KB Output is correct
22 Correct 2060 ms 120944 KB Output is correct
23 Correct 1683 ms 120920 KB Output is correct
24 Correct 173 ms 54380 KB Output is correct
25 Correct 158 ms 54124 KB Output is correct
26 Correct 128 ms 54380 KB Output is correct
27 Correct 127 ms 54380 KB Output is correct
28 Correct 137 ms 54380 KB Output is correct
29 Correct 106 ms 53996 KB Output is correct
30 Correct 107 ms 53868 KB Output is correct
31 Correct 129 ms 54180 KB Output is correct
32 Correct 83 ms 49444 KB Output is correct
33 Correct 131 ms 54180 KB Output is correct
34 Correct 332 ms 61548 KB Output is correct
35 Correct 378 ms 61384 KB Output is correct
36 Correct 280 ms 60960 KB Output is correct
37 Correct 271 ms 60908 KB Output is correct
38 Correct 268 ms 60908 KB Output is correct
39 Correct 216 ms 60780 KB Output is correct
40 Correct 207 ms 60780 KB Output is correct
41 Correct 252 ms 61036 KB Output is correct
42 Correct 235 ms 61036 KB Output is correct
43 Correct 250 ms 61164 KB Output is correct
44 Correct 277 ms 61412 KB Output is correct
45 Correct 277 ms 61420 KB Output is correct
46 Correct 302 ms 61420 KB Output is correct
47 Correct 278 ms 61292 KB Output is correct
48 Correct 296 ms 61320 KB Output is correct
49 Correct 201 ms 60524 KB Output is correct
50 Correct 204 ms 60524 KB Output is correct
51 Correct 193 ms 60524 KB Output is correct
52 Correct 222 ms 60524 KB Output is correct
53 Correct 199 ms 60524 KB Output is correct
54 Correct 252 ms 60964 KB Output is correct
55 Correct 221 ms 57760 KB Output is correct
56 Correct 263 ms 60984 KB Output is correct
57 Correct 1957 ms 119072 KB Output is correct
58 Correct 1956 ms 121892 KB Output is correct
59 Correct 1832 ms 120428 KB Output is correct
60 Correct 1846 ms 120484 KB Output is correct
61 Correct 1837 ms 120432 KB Output is correct
62 Correct 1842 ms 120396 KB Output is correct
63 Correct 999 ms 119060 KB Output is correct
64 Correct 1014 ms 118892 KB Output is correct
65 Correct 1532 ms 120428 KB Output is correct
66 Correct 1575 ms 120300 KB Output is correct
67 Correct 1546 ms 120524 KB Output is correct
68 Correct 1657 ms 121884 KB Output is correct
69 Correct 1690 ms 121888 KB Output is correct
70 Correct 1634 ms 121504 KB Output is correct
71 Correct 1703 ms 121632 KB Output is correct
72 Correct 1664 ms 121564 KB Output is correct
73 Correct 945 ms 115956 KB Output is correct
74 Correct 922 ms 116260 KB Output is correct
75 Correct 926 ms 116240 KB Output is correct
76 Correct 950 ms 116104 KB Output is correct
77 Correct 929 ms 115952 KB Output is correct
78 Correct 1476 ms 119344 KB Output is correct
79 Correct 1136 ms 96108 KB Output is correct
80 Correct 1573 ms 118776 KB Output is correct