Submission #925789

# Submission time Handle Problem Language Result Execution time Memory
925789 2024-02-12T08:51:15 Z andrei_boaca Team Contest (JOI22_team) C++17
100 / 100
643 ms 35012 KB
#include <bits/stdc++.h>

using namespace std;
typedef pair<int,int> pii;
const int INF=1e9;
int lim=500;
int n;
struct point
{
    int x,y,z;
} v[150005];
bool byx(point a,point b)
{
    return a.x<b.x;
}
bool byy(pii a,pii b)
{
    if(a.first!=b.first)
        return a.first>b.first;
    return a.second<b.second;
}
bool byz(pii a,pii b)
{
    if(a.second!=b.second)
        return a.second>b.second;
    return a.first<b.first;
}
vector<pii> enable[150005];
map<pii,int> pozmin;
map<int,int> nrm;
int nrz;
int arb[4*150005];
void build(int nod,int st,int dr)
{
    arb[nod]=INF;
    if(st==dr)
        return;
    int mij=(st+dr)/2;
    build(nod*2,st,mij);
    build(nod*2+1,mij+1,dr);
}
void update(int nod,int st,int dr,int poz,int val)
{
    if(st==dr)
    {
        arb[nod]=min(arb[nod],val);
        return;
    }
    int mij=(st+dr)/2;
    if(poz<=mij)
        update(nod*2,st,mij,poz,val);
    else
        update(nod*2+1,mij+1,dr,poz,val);
    arb[nod]=min(arb[nod*2],arb[nod*2+1]);
}
int query(int nod,int st,int dr,int a,int b)
{
    if(st>=a&&dr<=b)
        return arb[nod];
    int rez=INF;
    int mij=(st+dr)/2;
    if(a<=mij)
        rez=min(rez,query(nod*2,st,mij,a,b));
    if(b>mij)
        rez=min(rez,query(nod*2+1,mij+1,dr,a,b));
    return rez;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int maxim=0;
    cin>>n;
    vector<int> myz;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i].x>>v[i].y>>v[i].z;
        maxim=max(maxim,v[i].x);
        maxim=max(maxim,v[i].y);
        maxim=max(maxim,v[i].z);
        myz.push_back(v[i].z);
    }
    sort(myz.begin(),myz.end());
    myz.erase(unique(myz.begin(),myz.end()),myz.end());
    for(int i=0;i<myz.size();i++)
        nrm[myz[i]]=i+1;
    nrz=myz.size();
    int ans=-1;
    sort(v+1,v+n+1,byx);
    vector<pii> vals;
    for(int i=1;i<=n;i++)
    {
        pii x={v[i].y,v[i].z};
        if(pozmin.count(x)==0)
        {
            pozmin[x]=i;
            vals.push_back(x);
        }
    }
    sort(vals.begin(),vals.end(),byz);
    build(1,1,n);
    for(int i=0;i<vals.size();i++)
    {
        int j=i;
        vector<pii> a;
        while(j<vals.size()&&vals[j].second==vals[i].second)
        {
            a.push_back(vals[j]);
            j++;
        }
        for(pii p:a)
        {
            int y=p.first;
            int st=1;
            int dr=n;
            int poz=INF;
            while(st<=dr)
            {
                int mij=(st+dr)/2;
                if(query(1,1,n,1,mij)<y)
                {
                    poz=mij;
                    dr=mij-1;
                }
                else
                    st=mij+1;
            }
            poz=max(poz,pozmin[p]);
            if(poz<=n)
                enable[poz].push_back(p);
        }
        for(pii p:a)
        {
            int poz=pozmin[p];
            update(1,1,n,poz,p.first);
        }
        i=j-1;
    }
    build(1,1,nrz);
    pii ymax={-INF,INF};
    for(int i=1;i<=n;i++)
    {
        vector<point> a;
        int j=i;
        while(j<=n&&v[j].x==v[i].x)
        {
            a.push_back(v[j]);
            j++;
        }
        for(point p:a)
        {
            if(ymax.first<=p.y)
                continue;
            int poz=nrm[ymax.second];
            int st=poz+1;
            int dr=nrz;
            int best=poz;
            while(st<=dr)
            {
                int mij=(st+dr)/2;
                if(query(1,1,nrz,mij,nrz)<ymax.first)
                {
                    best=mij;
                    st=mij+1;
                }
                else
                    dr=mij-1;
            }
            int z=myz[best-1];
            if(z>p.z)
                ans=max(ans,p.x+ymax.first+z);
        }
        j--;
        for(int k=i;k<=j;k++)
        {
            int poz=nrm[v[k].z];
            update(1,1,nrz,poz,v[k].y);
            for(pii p:enable[k])
            {
                if(p.first>ymax.first||(p.first==ymax.first&&p.second<ymax.second))
                    ymax=p;
            }
        }
        i=j;
    }
    cout<<ans;
    return 0;
}

Compilation message

team.cpp: In function 'int main()':
team.cpp:85:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |     for(int i=0;i<myz.size();i++)
      |                 ~^~~~~~~~~~~
team.cpp:102:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |     for(int i=0;i<vals.size();i++)
      |                 ~^~~~~~~~~~~~
team.cpp:106:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |         while(j<vals.size()&&vals[j].second==vals[i].second)
      |               ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4536 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4628 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 2 ms 4440 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4536 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4628 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 2 ms 4440 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4440 KB Output is correct
26 Correct 12 ms 5208 KB Output is correct
27 Correct 9 ms 4956 KB Output is correct
28 Correct 9 ms 5072 KB Output is correct
29 Correct 8 ms 4952 KB Output is correct
30 Correct 6 ms 4700 KB Output is correct
31 Correct 8 ms 4956 KB Output is correct
32 Correct 6 ms 4896 KB Output is correct
33 Correct 4 ms 4700 KB Output is correct
34 Correct 6 ms 4956 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 2 ms 4444 KB Output is correct
37 Correct 4 ms 4700 KB Output is correct
38 Correct 5 ms 4700 KB Output is correct
39 Correct 2 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 38 ms 9168 KB Output is correct
12 Correct 24 ms 8924 KB Output is correct
13 Correct 27 ms 9660 KB Output is correct
14 Correct 35 ms 9744 KB Output is correct
15 Correct 31 ms 10784 KB Output is correct
16 Correct 27 ms 13264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 38 ms 9168 KB Output is correct
12 Correct 24 ms 8924 KB Output is correct
13 Correct 27 ms 9660 KB Output is correct
14 Correct 35 ms 9744 KB Output is correct
15 Correct 31 ms 10784 KB Output is correct
16 Correct 27 ms 13264 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 2 ms 4444 KB Output is correct
22 Correct 56 ms 8652 KB Output is correct
23 Correct 50 ms 8860 KB Output is correct
24 Correct 35 ms 8408 KB Output is correct
25 Correct 46 ms 9160 KB Output is correct
26 Correct 32 ms 10968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 38 ms 9168 KB Output is correct
12 Correct 24 ms 8924 KB Output is correct
13 Correct 27 ms 9660 KB Output is correct
14 Correct 35 ms 9744 KB Output is correct
15 Correct 31 ms 10784 KB Output is correct
16 Correct 27 ms 13264 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 2 ms 4444 KB Output is correct
22 Correct 56 ms 8652 KB Output is correct
23 Correct 50 ms 8860 KB Output is correct
24 Correct 35 ms 8408 KB Output is correct
25 Correct 46 ms 9160 KB Output is correct
26 Correct 32 ms 10968 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 1 ms 4440 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 6 ms 4700 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 2 ms 4444 KB Output is correct
34 Correct 251 ms 15692 KB Output is correct
35 Correct 183 ms 13516 KB Output is correct
36 Correct 186 ms 15012 KB Output is correct
37 Correct 148 ms 14224 KB Output is correct
38 Correct 51 ms 12344 KB Output is correct
39 Correct 176 ms 19920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 38 ms 9168 KB Output is correct
12 Correct 24 ms 8924 KB Output is correct
13 Correct 27 ms 9660 KB Output is correct
14 Correct 35 ms 9744 KB Output is correct
15 Correct 31 ms 10784 KB Output is correct
16 Correct 27 ms 13264 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 2 ms 4444 KB Output is correct
22 Correct 56 ms 8652 KB Output is correct
23 Correct 50 ms 8860 KB Output is correct
24 Correct 35 ms 8408 KB Output is correct
25 Correct 46 ms 9160 KB Output is correct
26 Correct 32 ms 10968 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 1 ms 4440 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 6 ms 4700 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 2 ms 4444 KB Output is correct
34 Correct 251 ms 15692 KB Output is correct
35 Correct 183 ms 13516 KB Output is correct
36 Correct 186 ms 15012 KB Output is correct
37 Correct 148 ms 14224 KB Output is correct
38 Correct 51 ms 12344 KB Output is correct
39 Correct 176 ms 19920 KB Output is correct
40 Correct 7 ms 4956 KB Output is correct
41 Correct 8 ms 4952 KB Output is correct
42 Correct 5 ms 4700 KB Output is correct
43 Correct 5 ms 4848 KB Output is correct
44 Correct 495 ms 26080 KB Output is correct
45 Correct 345 ms 21224 KB Output is correct
46 Correct 386 ms 22728 KB Output is correct
47 Correct 309 ms 20764 KB Output is correct
48 Correct 64 ms 13564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4536 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4628 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 2 ms 4440 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4440 KB Output is correct
26 Correct 12 ms 5208 KB Output is correct
27 Correct 9 ms 4956 KB Output is correct
28 Correct 9 ms 5072 KB Output is correct
29 Correct 8 ms 4952 KB Output is correct
30 Correct 6 ms 4700 KB Output is correct
31 Correct 8 ms 4956 KB Output is correct
32 Correct 6 ms 4896 KB Output is correct
33 Correct 4 ms 4700 KB Output is correct
34 Correct 6 ms 4956 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 2 ms 4444 KB Output is correct
37 Correct 4 ms 4700 KB Output is correct
38 Correct 5 ms 4700 KB Output is correct
39 Correct 2 ms 4700 KB Output is correct
40 Correct 2 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 38 ms 9168 KB Output is correct
51 Correct 24 ms 8924 KB Output is correct
52 Correct 27 ms 9660 KB Output is correct
53 Correct 35 ms 9744 KB Output is correct
54 Correct 31 ms 10784 KB Output is correct
55 Correct 27 ms 13264 KB Output is correct
56 Correct 1 ms 4444 KB Output is correct
57 Correct 1 ms 4444 KB Output is correct
58 Correct 1 ms 4440 KB Output is correct
59 Correct 1 ms 4444 KB Output is correct
60 Correct 2 ms 4444 KB Output is correct
61 Correct 56 ms 8652 KB Output is correct
62 Correct 50 ms 8860 KB Output is correct
63 Correct 35 ms 8408 KB Output is correct
64 Correct 46 ms 9160 KB Output is correct
65 Correct 32 ms 10968 KB Output is correct
66 Correct 1 ms 4440 KB Output is correct
67 Correct 1 ms 4440 KB Output is correct
68 Correct 1 ms 4440 KB Output is correct
69 Correct 1 ms 4444 KB Output is correct
70 Correct 6 ms 4700 KB Output is correct
71 Correct 2 ms 4444 KB Output is correct
72 Correct 2 ms 4444 KB Output is correct
73 Correct 251 ms 15692 KB Output is correct
74 Correct 183 ms 13516 KB Output is correct
75 Correct 186 ms 15012 KB Output is correct
76 Correct 148 ms 14224 KB Output is correct
77 Correct 51 ms 12344 KB Output is correct
78 Correct 176 ms 19920 KB Output is correct
79 Correct 7 ms 4956 KB Output is correct
80 Correct 8 ms 4952 KB Output is correct
81 Correct 5 ms 4700 KB Output is correct
82 Correct 5 ms 4848 KB Output is correct
83 Correct 495 ms 26080 KB Output is correct
84 Correct 345 ms 21224 KB Output is correct
85 Correct 386 ms 22728 KB Output is correct
86 Correct 309 ms 20764 KB Output is correct
87 Correct 64 ms 13564 KB Output is correct
88 Correct 643 ms 35012 KB Output is correct
89 Correct 591 ms 29896 KB Output is correct
90 Correct 624 ms 31740 KB Output is correct
91 Correct 452 ms 28104 KB Output is correct
92 Correct 532 ms 26696 KB Output is correct
93 Correct 547 ms 29128 KB Output is correct
94 Correct 462 ms 26052 KB Output is correct
95 Correct 207 ms 22820 KB Output is correct
96 Correct 311 ms 30156 KB Output is correct
97 Correct 42 ms 16328 KB Output is correct
98 Correct 193 ms 20524 KB Output is correct
99 Correct 239 ms 20392 KB Output is correct