답안 #709785

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
709785 2023-03-14T12:21:11 Z groshi Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
3000 ms 185776 KB
#include<iostream>
#include<vector>
using namespace std;
const int T = 1<<20;
vector<vector<int> > drzewo;
int wynik[2*T];
int maxx=0;
int wynikk=0;
int pot=1;
void dodaj(int x)
{
    wynikk=max(wynikk,wynik[x]);
    if(drzewo[x].size()==0)
        return;
    int mam=drzewo[x].back();
    if(maxx==0)
    {
        maxx=mam;
        return;
    }
    int gdzie=lower_bound(drzewo[x].begin(),drzewo[x].end(),maxx)-drzewo[x].begin();
    if(gdzie>=1 && gdzie<=drzewo[x].size())
        wynikk=max(wynikk,maxx+drzewo[x][gdzie-1]);
    maxx=max(maxx,mam);
}
void zapp(int x,int l,int r,int a,int b)
{
    if(l>b || r<a)
        return;
    if(a<=l && r<=b)
    {
        dodaj(x);
        return;
    }
    int mid=(l+r)/2;
    zapp(x*2,l,mid,a,b);
    zapp(x*2+1,mid+1,r,a,b);
}
int32_t main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int n,zap,x;
    cin>>n>>zap;
    while(pot<=n)
        pot*=2;
    pot--;
    drzewo.resize(2*pot+2);
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        drzewo[i+pot].push_back(x);
    }
    for(int i=pot;i>=1;i--)
    {
        ///merguje i*2 z i*2+1
        wynik[i]=max(wynik[i*2],wynik[i*2+1]);
        if(drzewo[i*2].size()>0)
        {
            int jest=drzewo[i*2].back();
            int gdzie=lower_bound(drzewo[i*2+1].begin(),drzewo[i*2+1].end(),jest)-drzewo[i*2+1].begin();
            if(gdzie>=1 && gdzie<=drzewo[i*2+1].size())
                wynik[i]=max(wynik[i],jest+drzewo[i*2+1][gdzie-1]);
        }
        int l=0,r=0;
        while(l<drzewo[i*2].size() || r<drzewo[i*2+1].size())
        {
            if(l==drzewo[i*2].size())
            {
                drzewo[i].push_back(drzewo[i*2+1][r]);
                r++;
                continue;
            }
            if(r==drzewo[i*2+1].size())
            {
                drzewo[i].push_back(drzewo[i*2][l]);
                l++;
                continue;
            }
            if(drzewo[i*2][l]<=drzewo[i*2+1][r])
            {
                drzewo[i].push_back(drzewo[i*2][l]);
                l++;
            }
            else{
                drzewo[i].push_back(drzewo[i*2+1][r]);
                r++;
            }
        }
    }
    while(zap--)
    {
        int x,y,z;
        cin>>x>>y>>z;
        maxx=0;
        wynikk=0;
        zapp(1,pot+1,pot*2+1,x+pot,y+pot);
        if(wynikk>z)
            cout<<"0\n";
        else cout<<"1\n";
    }
    return 0;
}

Compilation message

sortbooks.cpp: In function 'void dodaj(int)':
sortbooks.cpp:22:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     if(gdzie>=1 && gdzie<=drzewo[x].size())
      |                    ~~~~~^~~~~~~~~~~~~~~~~~
sortbooks.cpp: In function 'int32_t main()':
sortbooks.cpp:63:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |             if(gdzie>=1 && gdzie<=drzewo[i*2+1].size())
      |                            ~~~~~^~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:67:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         while(l<drzewo[i*2].size() || r<drzewo[i*2+1].size())
      |               ~^~~~~~~~~~~~~~~~~~~
sortbooks.cpp:67:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         while(l<drzewo[i*2].size() || r<drzewo[i*2+1].size())
      |                                       ~^~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:69:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |             if(l==drzewo[i*2].size())
      |                ~^~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:75:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |             if(r==drzewo[i*2+1].size())
      |                ~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 5 ms 1392 KB Output is correct
13 Correct 5 ms 1292 KB Output is correct
14 Correct 9 ms 1436 KB Output is correct
15 Correct 9 ms 1376 KB Output is correct
16 Correct 6 ms 1364 KB Output is correct
17 Correct 5 ms 1364 KB Output is correct
18 Correct 5 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3027 ms 185776 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 196 ms 19512 KB Output is correct
2 Correct 170 ms 19808 KB Output is correct
3 Correct 201 ms 19780 KB Output is correct
4 Correct 152 ms 19744 KB Output is correct
5 Correct 211 ms 19780 KB Output is correct
6 Correct 113 ms 19840 KB Output is correct
7 Correct 112 ms 19832 KB Output is correct
8 Correct 146 ms 19776 KB Output is correct
9 Correct 43 ms 1228 KB Output is correct
10 Correct 172 ms 19868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 5 ms 1392 KB Output is correct
13 Correct 5 ms 1292 KB Output is correct
14 Correct 9 ms 1436 KB Output is correct
15 Correct 9 ms 1376 KB Output is correct
16 Correct 6 ms 1364 KB Output is correct
17 Correct 5 ms 1364 KB Output is correct
18 Correct 5 ms 1364 KB Output is correct
19 Correct 450 ms 39196 KB Output is correct
20 Correct 462 ms 39240 KB Output is correct
21 Correct 333 ms 39104 KB Output is correct
22 Correct 333 ms 39300 KB Output is correct
23 Correct 350 ms 39384 KB Output is correct
24 Correct 289 ms 39096 KB Output is correct
25 Correct 271 ms 39116 KB Output is correct
26 Correct 376 ms 39188 KB Output is correct
27 Correct 353 ms 39172 KB Output is correct
28 Correct 398 ms 39200 KB Output is correct
29 Correct 398 ms 39296 KB Output is correct
30 Correct 378 ms 39088 KB Output is correct
31 Correct 433 ms 39148 KB Output is correct
32 Correct 384 ms 39212 KB Output is correct
33 Correct 373 ms 39180 KB Output is correct
34 Correct 263 ms 39168 KB Output is correct
35 Correct 276 ms 39168 KB Output is correct
36 Correct 244 ms 39192 KB Output is correct
37 Correct 237 ms 39212 KB Output is correct
38 Correct 266 ms 39132 KB Output is correct
39 Correct 337 ms 39120 KB Output is correct
40 Correct 227 ms 30792 KB Output is correct
41 Correct 302 ms 39132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 5 ms 1392 KB Output is correct
13 Correct 5 ms 1292 KB Output is correct
14 Correct 9 ms 1436 KB Output is correct
15 Correct 9 ms 1376 KB Output is correct
16 Correct 6 ms 1364 KB Output is correct
17 Correct 5 ms 1364 KB Output is correct
18 Correct 5 ms 1364 KB Output is correct
19 Execution timed out 3027 ms 185776 KB Time limit exceeded
20 Halted 0 ms 0 KB -