Submission #1117126

# Submission time Handle Problem Language Result Execution time Memory
1117126 2024-11-22T20:50:56 Z Jovica Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2891 ms 86220 KB
#include <bits/stdc++.h>

using namespace std;
int pogolem[1000000];
int niza[1000000];
int drvo[2500000];

int p;
int update(int l,int r,int poz,int k)
{
    if (p<l || r<p) return drvo[poz];
    if (l==r)
    {
        drvo[poz] = max(drvo[poz],k);
        return drvo[poz];
    }
    int mid = (l+r)/2;
    drvo[poz] = max(update(l,mid,poz*2,k),update(mid+1,r,poz*2+1,k));
    return drvo[poz];
}

int najdi(int l,int r,int poz,int levo,int desno)
{
    if (levo<=l && r<=desno) return drvo[poz];
    if (r<levo || desno<l) return 0;
    int mid = (l+r)/2;
    return max(najdi(l,mid,poz*2,levo,desno),najdi(mid+1,r,poz*2+1,levo,desno));
}

int main()
{
    int n,q;
    cin>>n>>q;
    int ns = 1;
    while (ns<n) ns*=2;

    stack<int> s;
    for (int i=1;i<=n;i++)
    {
        int a;
        cin>>a;
        niza[i] = a;

        while(s.size() && niza[s.top()]<=a) s.pop();

        if (s.size()) pogolem[i] = s.top();
        else pogolem[i] = -1;
        s.push(i);
    }

    /*
    cout<<"pogolem: ";
    for (int i=0;i<n;i++)
        cout<<pogolem[i]<<" ";
    cout<<endl;
    */

    vector<tuple<int,int,int,int> > pras;
    for (int i=0;i<q;i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        pras.push_back({b,a,c,i});
    }
    sort(pras.begin(),pras.end());
    int t = 0;

    vector<pair<int,int> > odg;
    for (int i=1;i<=n;i++)
    {
        if (pogolem[i]!=-1)
        {
            p = pogolem[i];
            update(1,ns,1,niza[i]+niza[p]);
        }

        while(t<pras.size() && get<0>(pras[t])==i)
        {
            int x = najdi(1,ns,1, get<1>(pras[t]),get<0>(pras[t]));
            if (x<=get<2>(pras[t])) odg.push_back({get<3>(pras[t]),1});
            else odg.push_back({get<3>(pras[t]),0});
            //cout<<"l = "<<get<1>(pras[t])<<" r = "<<get<0>(pras[t])<< " x = "<<x<<endl;
            t++;

        }
    }

    sort(odg.begin(),odg.end());
    for (auto a : odg)
        cout<<a.second<<endl;

    return 0;
}
/*
5 15
2 7 6 8 1
1 1 1
1 2 1
1 3 1
1 4 1
1 5 1
2 2 2
2 3 2
2 4 2
2 5 2
3 3 3
3 4 3
3 5 3
4 4 4
4 5 4
5 5 5
*/

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:77:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         while(t<pras.size() && get<0>(pras[t])==i)
      |               ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 3 ms 4600 KB Output is correct
4 Correct 2 ms 4432 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 2 ms 4432 KB Output is correct
7 Correct 2 ms 4432 KB Output is correct
8 Correct 2 ms 4432 KB Output is correct
9 Correct 2 ms 4432 KB Output is correct
10 Correct 3 ms 4684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 3 ms 4600 KB Output is correct
4 Correct 2 ms 4432 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 2 ms 4432 KB Output is correct
7 Correct 2 ms 4432 KB Output is correct
8 Correct 2 ms 4432 KB Output is correct
9 Correct 2 ms 4432 KB Output is correct
10 Correct 3 ms 4684 KB Output is correct
11 Correct 8 ms 4852 KB Output is correct
12 Correct 8 ms 4688 KB Output is correct
13 Correct 10 ms 4688 KB Output is correct
14 Correct 14 ms 4944 KB Output is correct
15 Correct 14 ms 4956 KB Output is correct
16 Correct 14 ms 4688 KB Output is correct
17 Correct 14 ms 4688 KB Output is correct
18 Correct 13 ms 4688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2803 ms 70464 KB Output is correct
2 Correct 2873 ms 84940 KB Output is correct
3 Correct 2891 ms 84580 KB Output is correct
4 Correct 2785 ms 84740 KB Output is correct
5 Correct 2566 ms 76936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 240 ms 10424 KB Output is correct
2 Correct 243 ms 11216 KB Output is correct
3 Correct 245 ms 10424 KB Output is correct
4 Correct 229 ms 10424 KB Output is correct
5 Correct 233 ms 10524 KB Output is correct
6 Correct 243 ms 10448 KB Output is correct
7 Correct 240 ms 10424 KB Output is correct
8 Correct 227 ms 10168 KB Output is correct
9 Correct 216 ms 9772 KB Output is correct
10 Correct 225 ms 10120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 3 ms 4600 KB Output is correct
4 Correct 2 ms 4432 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 2 ms 4432 KB Output is correct
7 Correct 2 ms 4432 KB Output is correct
8 Correct 2 ms 4432 KB Output is correct
9 Correct 2 ms 4432 KB Output is correct
10 Correct 3 ms 4684 KB Output is correct
11 Correct 8 ms 4852 KB Output is correct
12 Correct 8 ms 4688 KB Output is correct
13 Correct 10 ms 4688 KB Output is correct
14 Correct 14 ms 4944 KB Output is correct
15 Correct 14 ms 4956 KB Output is correct
16 Correct 14 ms 4688 KB Output is correct
17 Correct 14 ms 4688 KB Output is correct
18 Correct 13 ms 4688 KB Output is correct
19 Correct 552 ms 22836 KB Output is correct
20 Correct 545 ms 22836 KB Output is correct
21 Correct 591 ms 22540 KB Output is correct
22 Correct 603 ms 22704 KB Output is correct
23 Correct 543 ms 22576 KB Output is correct
24 Correct 524 ms 21424 KB Output is correct
25 Correct 512 ms 21044 KB Output is correct
26 Correct 510 ms 21168 KB Output is correct
27 Correct 563 ms 21096 KB Output is correct
28 Correct 517 ms 21068 KB Output is correct
29 Correct 500 ms 21168 KB Output is correct
30 Correct 513 ms 21780 KB Output is correct
31 Correct 534 ms 21116 KB Output is correct
32 Correct 529 ms 21284 KB Output is correct
33 Correct 513 ms 21264 KB Output is correct
34 Correct 505 ms 20912 KB Output is correct
35 Correct 506 ms 20920 KB Output is correct
36 Correct 513 ms 20760 KB Output is correct
37 Correct 507 ms 20756 KB Output is correct
38 Correct 526 ms 21556 KB Output is correct
39 Correct 495 ms 20420 KB Output is correct
40 Correct 473 ms 17072 KB Output is correct
41 Correct 474 ms 19504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 3 ms 4600 KB Output is correct
4 Correct 2 ms 4432 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 2 ms 4432 KB Output is correct
7 Correct 2 ms 4432 KB Output is correct
8 Correct 2 ms 4432 KB Output is correct
9 Correct 2 ms 4432 KB Output is correct
10 Correct 3 ms 4684 KB Output is correct
11 Correct 8 ms 4852 KB Output is correct
12 Correct 8 ms 4688 KB Output is correct
13 Correct 10 ms 4688 KB Output is correct
14 Correct 14 ms 4944 KB Output is correct
15 Correct 14 ms 4956 KB Output is correct
16 Correct 14 ms 4688 KB Output is correct
17 Correct 14 ms 4688 KB Output is correct
18 Correct 13 ms 4688 KB Output is correct
19 Correct 2803 ms 70464 KB Output is correct
20 Correct 2873 ms 84940 KB Output is correct
21 Correct 2891 ms 84580 KB Output is correct
22 Correct 2785 ms 84740 KB Output is correct
23 Correct 2566 ms 76936 KB Output is correct
24 Correct 240 ms 10424 KB Output is correct
25 Correct 243 ms 11216 KB Output is correct
26 Correct 245 ms 10424 KB Output is correct
27 Correct 229 ms 10424 KB Output is correct
28 Correct 233 ms 10524 KB Output is correct
29 Correct 243 ms 10448 KB Output is correct
30 Correct 240 ms 10424 KB Output is correct
31 Correct 227 ms 10168 KB Output is correct
32 Correct 216 ms 9772 KB Output is correct
33 Correct 225 ms 10120 KB Output is correct
34 Correct 552 ms 22836 KB Output is correct
35 Correct 545 ms 22836 KB Output is correct
36 Correct 591 ms 22540 KB Output is correct
37 Correct 603 ms 22704 KB Output is correct
38 Correct 543 ms 22576 KB Output is correct
39 Correct 524 ms 21424 KB Output is correct
40 Correct 512 ms 21044 KB Output is correct
41 Correct 510 ms 21168 KB Output is correct
42 Correct 563 ms 21096 KB Output is correct
43 Correct 517 ms 21068 KB Output is correct
44 Correct 500 ms 21168 KB Output is correct
45 Correct 513 ms 21780 KB Output is correct
46 Correct 534 ms 21116 KB Output is correct
47 Correct 529 ms 21284 KB Output is correct
48 Correct 513 ms 21264 KB Output is correct
49 Correct 505 ms 20912 KB Output is correct
50 Correct 506 ms 20920 KB Output is correct
51 Correct 513 ms 20760 KB Output is correct
52 Correct 507 ms 20756 KB Output is correct
53 Correct 526 ms 21556 KB Output is correct
54 Correct 495 ms 20420 KB Output is correct
55 Correct 473 ms 17072 KB Output is correct
56 Correct 474 ms 19504 KB Output is correct
57 Correct 2855 ms 85288 KB Output is correct
58 Correct 2822 ms 85488 KB Output is correct
59 Correct 2776 ms 85152 KB Output is correct
60 Correct 2829 ms 85160 KB Output is correct
61 Correct 2883 ms 86220 KB Output is correct
62 Correct 2820 ms 85380 KB Output is correct
63 Correct 2647 ms 75532 KB Output is correct
64 Correct 2589 ms 76148 KB Output is correct
65 Correct 2579 ms 77444 KB Output is correct
66 Correct 2654 ms 77504 KB Output is correct
67 Correct 2698 ms 77472 KB Output is correct
68 Correct 2719 ms 77416 KB Output is correct
69 Correct 2610 ms 77924 KB Output is correct
70 Correct 2712 ms 77660 KB Output is correct
71 Correct 2756 ms 77424 KB Output is correct
72 Correct 2741 ms 77760 KB Output is correct
73 Correct 2521 ms 76236 KB Output is correct
74 Correct 2648 ms 74408 KB Output is correct
75 Correct 2569 ms 80180 KB Output is correct
76 Correct 2664 ms 73440 KB Output is correct
77 Correct 2587 ms 73324 KB Output is correct
78 Correct 2527 ms 74168 KB Output is correct
79 Correct 2337 ms 65508 KB Output is correct
80 Correct 2545 ms 68756 KB Output is correct