Submission #841854

# Submission time Handle Problem Language Result Execution time Memory
841854 2023-09-02T07:40:17 Z lucaperju Overtaking (IOI23_overtaking) C++17
100 / 100
3328 ms 294992 KB
#include "overtaking.h"
#include <bits/stdc++.h>
using namespace std;
long long t[1003][1003],e[1003][1003];
long long ord[1003],cj;
bool cmp (int a, int b)
{
    if(t[a][cj-1] < t[b][cj-1])
        return true;
    if(t[a][cj-1] > t[b][cj-1])
        return false;
    return e[a][cj] < e[b][cj];
}
struct ura
{
    long long l,r,x;
};
vector<ura>vc;
bool cmp2 (ura a, ura b)
{
    if(a.x == b.x)
    {
        return a.r < b.r;
    }
    return a.x>b.x;
}
vector<long long>coords;
vector<long long>norms;
unordered_map<long long,int>invnorm;
long long aint[16000005];
long long realcoords[4000005];
void upd (int nod, int l, int r, int ul, int ur, long long val)
{
    if(ul<=l && r <= ur)
    {
        aint[nod] = max(aint[nod],val);
        return;
    }
    if(ur < l || r < ul)
        return;
    int mid = ((l+r)>>1);
    upd(nod<<1,l,mid,ul,ur,val);
    upd((nod<<1)|1,mid+1,r,ul,ur,val);
}
long long qry (int nod, int l, int r, int pz)
{
    if(pz < l || r < pz)
        return 0;
    if(l == r)
        return aint[nod];
    int mid = ((l+r)>>1);
    long long a = max(qry(nod<<1,l,mid,pz), qry((nod<<1)|1,mid+1,r,pz));
    return max(a, aint[nod]);
}
void build (int nod, int l, int r)
{
    if(l == r)
    {
        aint[nod] = realcoords[l];
        return;
    }
    int mid = ((l+r)>>1);
    build(nod<<1,l,mid);
    build((nod<<1)|1,mid+1,r);
}
long long xx,kk,ll;
long long idkk,okt;
void init(int L, int N, std::vector<long long> T, std::vector<int> W, int X, int M, std::vector<int> S)
{
    ll = L;
    xx = X;
    int i,j;
    for(i=0;i<N;++i)
        t[i][0] = T[i];
    for(i=0;i<N;++i)
        ord[i]=i;
    for(j = 1; j < M; ++j)
    {
        for(i = 0 ; i < N; ++i)
        {
            e[i][j] = t[i][j-1] + W[i] * 1LL * (S[j] - S[j-1]);
          //  cout<<i<<' '<<t[i][j-1]<<' '<<W[i]<<' '<<S[j]<<' '<<S[j-1]<<' '<<e[i][j]<<'\n';
        }
        cj = j;
        sort(ord,ord+N,cmp);
        long long mxc = 0;
        for(i = 0; i < N; ++i)
        {
            int vlc = ord[i];
           // cout<<vlc<<' ';
            mxc = max(mxc, e[vlc][j]);
            t[vlc][j] = mxc; 
        }
    }
    for(i = 0; i < N; ++i)
    {
        for(j = 1; j < M; ++j)
        {
            ura x;
            x.l = t[i][j-1] - S[j-1]*1LL*X + 1;
            x.r = t[i][j] - S[j]*1LL*X;
            x.x = j;
            if(x.l > x.r)
                continue;
            vc.push_back(x);
            coords.push_back(x.l);
            coords.push_back(x.r);
        }
       // cout<<'\n';
    }
    if(coords.empty())
    {
        okt = 1;
        return;
    }
    sort(coords.begin(),coords.end());
    long long k = 1;
    norms.push_back(1);
    invnorm[coords[0]] = 1;
    realcoords[1] = coords[0];
    for(int i = 1; i < coords.size(); ++i)
    {
        if(coords[i] != coords[i-1])
            k+=2;
   //     cout<<"coord: "<<coords[i]<<'\n';
        invnorm[coords[i]] = k;
        realcoords[k] = coords[i];
        norms.push_back(k);
    }
   // cout<<"\n\n";
    build(1,1,k);
    sort(vc.begin(),vc.end(),cmp2);
    for(int i = 0; i < vc.size();++i)
    {
        ura x = vc[i];
        int l = invnorm[x.l];
        int r = invnorm[x.r];
        long long val = qry(1,1,k,r);
      //  cout<<"upd "<<x.x<<' '<<l<<' '<<r<<' '<<val<<'\n';
        upd(1,1,k,l,r,val);
    }
    kk = k;
}

long long arrival_time(long long Y)
{
    if(okt)
    {
        return Y + ll * 1LL * xx;
    }
    int pas = (1<<21);
    int pz = -1;
    while(pas)
    {
        if(pz+pas < (int)coords.size() && coords[pz+pas]<=Y)
            pz += pas;
        pas>>=1;
    }
    if(pz == -1)
    {
        return Y + ll * 1LL * xx;
    }
    if(pz == (int)coords.size()-1 && Y >= coords[pz])
        return Y + ll * 1LL * xx;
    //cout<<"here "<<pz<<'\n';
    if(coords[pz] == Y)
    {
        //cout<<invnorm[3]<<"<-\n";
        //cout<<"idk "<<qry(1,1,kk,invnorm[coords[pz]])<<'\n';
        return max(Y,qry(1,1,kk,invnorm[coords[pz]])) + ll * 1LL * xx;
    }
    else
    {
        return max(Y,qry(1,1,kk,invnorm[coords[pz]] + 1)) + ll * 1LL * xx;
    }
}
/*
3 1 3 2 7
2
4
0 3
1 2 3 4 5 6 7
*/

Compilation message

overtaking.cpp: In function 'void init(int, int, std::vector<long long int>, std::vector<int>, int, int, std::vector<int>)':
overtaking.cpp:121:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |     for(int i = 1; i < coords.size(); ++i)
      |                    ~~^~~~~~~~~~~~~~~
overtaking.cpp:133:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ura>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  133 |     for(int i = 0; i < vc.size();++i)
      |                    ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 6488 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Correct 2 ms 6744 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6744 KB Output is correct
10 Correct 2 ms 7000 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6744 KB Output is correct
4 Correct 1 ms 6488 KB Output is correct
5 Correct 2 ms 10584 KB Output is correct
6 Correct 3 ms 16984 KB Output is correct
7 Correct 3 ms 17752 KB Output is correct
8 Correct 3 ms 17752 KB Output is correct
9 Correct 3 ms 17752 KB Output is correct
10 Correct 4 ms 17752 KB Output is correct
11 Correct 3 ms 17752 KB Output is correct
12 Correct 3 ms 17756 KB Output is correct
13 Correct 2 ms 15704 KB Output is correct
14 Correct 2 ms 15708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 6488 KB Output is correct
4 Correct 1 ms 6488 KB Output is correct
5 Correct 1 ms 4696 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6744 KB Output is correct
9 Correct 8 ms 10096 KB Output is correct
10 Correct 8 ms 10096 KB Output is correct
11 Correct 8 ms 10352 KB Output is correct
12 Correct 9 ms 10096 KB Output is correct
13 Correct 8 ms 10096 KB Output is correct
14 Correct 8 ms 10096 KB Output is correct
15 Correct 11 ms 10096 KB Output is correct
16 Correct 9 ms 10096 KB Output is correct
17 Correct 9 ms 10100 KB Output is correct
18 Correct 9 ms 10096 KB Output is correct
19 Correct 10 ms 10096 KB Output is correct
20 Correct 8 ms 10096 KB Output is correct
21 Correct 5 ms 7220 KB Output is correct
22 Correct 5 ms 7220 KB Output is correct
23 Correct 4 ms 6964 KB Output is correct
24 Correct 7 ms 9780 KB Output is correct
25 Correct 8 ms 9780 KB Output is correct
26 Correct 10 ms 9780 KB Output is correct
27 Correct 7 ms 9780 KB Output is correct
28 Correct 6 ms 9780 KB Output is correct
29 Correct 6 ms 9524 KB Output is correct
30 Correct 6 ms 9524 KB Output is correct
31 Correct 7 ms 9524 KB Output is correct
32 Correct 6 ms 7536 KB Output is correct
33 Correct 9 ms 10096 KB Output is correct
34 Correct 8 ms 10096 KB Output is correct
35 Correct 8 ms 10096 KB Output is correct
36 Correct 8 ms 10096 KB Output is correct
37 Correct 8 ms 10096 KB Output is correct
38 Correct 1 ms 4440 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 6 ms 7284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 6488 KB Output is correct
4 Correct 1 ms 6488 KB Output is correct
5 Correct 1 ms 4696 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Correct 1 ms 6488 KB Output is correct
8 Correct 2 ms 6744 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6744 KB Output is correct
11 Correct 2 ms 7000 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6744 KB Output is correct
16 Correct 8 ms 10096 KB Output is correct
17 Correct 8 ms 10096 KB Output is correct
18 Correct 8 ms 10352 KB Output is correct
19 Correct 9 ms 10096 KB Output is correct
20 Correct 8 ms 10096 KB Output is correct
21 Correct 8 ms 10096 KB Output is correct
22 Correct 11 ms 10096 KB Output is correct
23 Correct 9 ms 10096 KB Output is correct
24 Correct 9 ms 10100 KB Output is correct
25 Correct 9 ms 10096 KB Output is correct
26 Correct 10 ms 10096 KB Output is correct
27 Correct 8 ms 10096 KB Output is correct
28 Correct 5 ms 7220 KB Output is correct
29 Correct 5 ms 7220 KB Output is correct
30 Correct 4 ms 6964 KB Output is correct
31 Correct 7 ms 9780 KB Output is correct
32 Correct 8 ms 9780 KB Output is correct
33 Correct 10 ms 9780 KB Output is correct
34 Correct 7 ms 9780 KB Output is correct
35 Correct 6 ms 9780 KB Output is correct
36 Correct 6 ms 9524 KB Output is correct
37 Correct 6 ms 9524 KB Output is correct
38 Correct 7 ms 9524 KB Output is correct
39 Correct 6 ms 7536 KB Output is correct
40 Correct 9 ms 10096 KB Output is correct
41 Correct 8 ms 10096 KB Output is correct
42 Correct 8 ms 10096 KB Output is correct
43 Correct 8 ms 10096 KB Output is correct
44 Correct 8 ms 10096 KB Output is correct
45 Correct 1 ms 4440 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 6 ms 7284 KB Output is correct
48 Correct 1695 ms 247820 KB Output is correct
49 Correct 1956 ms 252988 KB Output is correct
50 Correct 1970 ms 253640 KB Output is correct
51 Correct 1930 ms 252328 KB Output is correct
52 Correct 1970 ms 252308 KB Output is correct
53 Correct 2008 ms 252952 KB Output is correct
54 Correct 1949 ms 252720 KB Output is correct
55 Correct 1417 ms 206540 KB Output is correct
56 Correct 1900 ms 251956 KB Output is correct
57 Correct 1841 ms 247272 KB Output is correct
58 Correct 1906 ms 252664 KB Output is correct
59 Correct 1875 ms 252284 KB Output is correct
60 Correct 1886 ms 252184 KB Output is correct
61 Correct 1954 ms 252864 KB Output is correct
62 Correct 3 ms 6744 KB Output is correct
63 Correct 5 ms 18008 KB Output is correct
64 Correct 825 ms 127304 KB Output is correct
65 Correct 918 ms 133292 KB Output is correct
66 Correct 542 ms 90264 KB Output is correct
67 Correct 2061 ms 247580 KB Output is correct
68 Correct 1968 ms 248468 KB Output is correct
69 Correct 907 ms 157540 KB Output is correct
70 Correct 1039 ms 239328 KB Output is correct
71 Correct 1656 ms 249648 KB Output is correct
72 Correct 1734 ms 254316 KB Output is correct
73 Correct 1735 ms 250736 KB Output is correct
74 Correct 1703 ms 251192 KB Output is correct
75 Correct 38 ms 16724 KB Output is correct
76 Correct 39 ms 16720 KB Output is correct
77 Correct 38 ms 16720 KB Output is correct
78 Correct 774 ms 120720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 6488 KB Output is correct
4 Correct 1 ms 6488 KB Output is correct
5 Correct 1 ms 4696 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Correct 1 ms 6488 KB Output is correct
8 Correct 2 ms 6744 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6744 KB Output is correct
11 Correct 2 ms 7000 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6744 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 2 ms 10584 KB Output is correct
18 Correct 3 ms 16984 KB Output is correct
19 Correct 3 ms 17752 KB Output is correct
20 Correct 3 ms 17752 KB Output is correct
21 Correct 3 ms 17752 KB Output is correct
22 Correct 4 ms 17752 KB Output is correct
23 Correct 3 ms 17752 KB Output is correct
24 Correct 3 ms 17756 KB Output is correct
25 Correct 2 ms 15704 KB Output is correct
26 Correct 2 ms 15708 KB Output is correct
27 Correct 8 ms 10096 KB Output is correct
28 Correct 8 ms 10096 KB Output is correct
29 Correct 8 ms 10352 KB Output is correct
30 Correct 9 ms 10096 KB Output is correct
31 Correct 8 ms 10096 KB Output is correct
32 Correct 8 ms 10096 KB Output is correct
33 Correct 11 ms 10096 KB Output is correct
34 Correct 9 ms 10096 KB Output is correct
35 Correct 9 ms 10100 KB Output is correct
36 Correct 9 ms 10096 KB Output is correct
37 Correct 10 ms 10096 KB Output is correct
38 Correct 8 ms 10096 KB Output is correct
39 Correct 5 ms 7220 KB Output is correct
40 Correct 5 ms 7220 KB Output is correct
41 Correct 4 ms 6964 KB Output is correct
42 Correct 7 ms 9780 KB Output is correct
43 Correct 8 ms 9780 KB Output is correct
44 Correct 10 ms 9780 KB Output is correct
45 Correct 7 ms 9780 KB Output is correct
46 Correct 6 ms 9780 KB Output is correct
47 Correct 6 ms 9524 KB Output is correct
48 Correct 6 ms 9524 KB Output is correct
49 Correct 7 ms 9524 KB Output is correct
50 Correct 6 ms 7536 KB Output is correct
51 Correct 9 ms 10096 KB Output is correct
52 Correct 8 ms 10096 KB Output is correct
53 Correct 8 ms 10096 KB Output is correct
54 Correct 8 ms 10096 KB Output is correct
55 Correct 8 ms 10096 KB Output is correct
56 Correct 1 ms 4440 KB Output is correct
57 Correct 1 ms 4444 KB Output is correct
58 Correct 6 ms 7284 KB Output is correct
59 Correct 1695 ms 247820 KB Output is correct
60 Correct 1956 ms 252988 KB Output is correct
61 Correct 1970 ms 253640 KB Output is correct
62 Correct 1930 ms 252328 KB Output is correct
63 Correct 1970 ms 252308 KB Output is correct
64 Correct 2008 ms 252952 KB Output is correct
65 Correct 1949 ms 252720 KB Output is correct
66 Correct 1417 ms 206540 KB Output is correct
67 Correct 1900 ms 251956 KB Output is correct
68 Correct 1841 ms 247272 KB Output is correct
69 Correct 1906 ms 252664 KB Output is correct
70 Correct 1875 ms 252284 KB Output is correct
71 Correct 1886 ms 252184 KB Output is correct
72 Correct 1954 ms 252864 KB Output is correct
73 Correct 3 ms 6744 KB Output is correct
74 Correct 5 ms 18008 KB Output is correct
75 Correct 825 ms 127304 KB Output is correct
76 Correct 918 ms 133292 KB Output is correct
77 Correct 542 ms 90264 KB Output is correct
78 Correct 2061 ms 247580 KB Output is correct
79 Correct 1968 ms 248468 KB Output is correct
80 Correct 907 ms 157540 KB Output is correct
81 Correct 1039 ms 239328 KB Output is correct
82 Correct 1656 ms 249648 KB Output is correct
83 Correct 1734 ms 254316 KB Output is correct
84 Correct 1735 ms 250736 KB Output is correct
85 Correct 1703 ms 251192 KB Output is correct
86 Correct 38 ms 16724 KB Output is correct
87 Correct 39 ms 16720 KB Output is correct
88 Correct 38 ms 16720 KB Output is correct
89 Correct 774 ms 120720 KB Output is correct
90 Correct 1805 ms 251060 KB Output is correct
91 Correct 2723 ms 277756 KB Output is correct
92 Correct 2720 ms 278328 KB Output is correct
93 Correct 2668 ms 277808 KB Output is correct
94 Correct 2820 ms 278040 KB Output is correct
95 Correct 2750 ms 277384 KB Output is correct
96 Correct 2867 ms 277796 KB Output is correct
97 Correct 1704 ms 210792 KB Output is correct
98 Correct 3037 ms 278532 KB Output is correct
99 Correct 2686 ms 273128 KB Output is correct
100 Correct 3072 ms 277348 KB Output is correct
101 Correct 3041 ms 276868 KB Output is correct
102 Correct 2828 ms 279324 KB Output is correct
103 Correct 2741 ms 277456 KB Output is correct
104 Correct 1648 ms 151352 KB Output is correct
105 Correct 1869 ms 159936 KB Output is correct
106 Correct 1137 ms 111776 KB Output is correct
107 Correct 2694 ms 276548 KB Output is correct
108 Correct 2865 ms 277460 KB Output is correct
109 Correct 2776 ms 276892 KB Output is correct
110 Correct 2996 ms 279088 KB Output is correct
111 Correct 1478 ms 183892 KB Output is correct
112 Correct 1697 ms 265620 KB Output is correct
113 Correct 2660 ms 275792 KB Output is correct
114 Correct 3114 ms 284340 KB Output is correct
115 Correct 2525 ms 276452 KB Output is correct
116 Correct 2368 ms 276340 KB Output is correct
117 Correct 218 ms 44252 KB Output is correct
118 Correct 212 ms 44108 KB Output is correct
119 Correct 209 ms 43364 KB Output is correct
120 Correct 211 ms 44320 KB Output is correct
121 Correct 209 ms 45396 KB Output is correct
122 Correct 1547 ms 143008 KB Output is correct
123 Correct 3262 ms 285324 KB Output is correct
124 Correct 3270 ms 294036 KB Output is correct
125 Correct 3328 ms 294992 KB Output is correct