Submission #957186

# Submission time Handle Problem Language Result Execution time Memory
957186 2024-04-03T06:52:07 Z Vladth11 Overtaking (IOI23_overtaking) C++17
100 / 100
3256 ms 1013904 KB
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#include "overtaking.h"

using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;

const int NMAX = 31000001;
const ll INF = 1e18;

const pii NEUTRU = {0, 0};

struct Node {
    /// max(x + a, b)
    int st, dr;
    ll maxi; /// basically asta e valoarea lui f(dr)
    pii lazy;
    ll eval(ll x) {
        return max(x + lazy.first, lazy.second);
    }
};

Node aint[NMAX];
int cnt;

pii combine(pii nou, pii a) {
    return {a.first + nou.first, max(a.second + nou.first, nou.second)};
}

void propaga(int node, ll st, ll dr) {
    if(node == -1 || aint[node].lazy == NEUTRU) return;
    if(st != dr) {
        if(aint[node].st == -1) {
            aint[node].st = cnt;
            aint[cnt++] = {-1, -1, (st + dr) >> 1, NEUTRU};
        }
        if(aint[node].dr == -1) {
            aint[node].dr = cnt;
            aint[cnt++] = {-1, -1, dr, NEUTRU};
        }
        aint[aint[node].st].lazy = combine(aint[node].lazy, aint[aint[node].st].lazy);
        aint[aint[node].dr].lazy = combine(aint[node].lazy, aint[aint[node].dr].lazy);
    }
    aint[node].maxi = aint[node].eval(aint[node].maxi);
    aint[node].lazy = NEUTRU;
}
void update(int node, ll st, ll dr, ll a, ll b, pii functie) {
    propaga(node, st, dr);
    if(a <= st && dr <= b) {
        aint[node].lazy = combine(functie, aint[node].lazy);
        return;
    }
    ll mid = (st + dr) >> 1;
    if(a <= mid) {
        if(aint[node].st == -1) {
            aint[node].st = cnt;
            aint[cnt++] = {-1, -1, mid, NEUTRU};
        }
        update(aint[node].st, st, mid, a, b, functie);
    }
    if(b > mid) {
        if(aint[node].dr == -1) {
            aint[node].dr = cnt;
            aint[cnt++] = {-1, -1, dr, NEUTRU};
        }
        update(aint[node].dr, mid + 1, dr, a, b, functie);
    }
    propaga(aint[node].dr, mid + 1, dr);
    if(aint[node].dr != -1)
        aint[node].maxi = aint[aint[node].dr].maxi;
    else
        aint[node].maxi = dr;
}

ll cb(int node, ll st, ll dr, ll val, pii acum) {
    acum = combine(acum, aint[node].lazy);
    if(st == dr) {
        return st;
    }
    ll mid = (st + dr) >> 1;
    ll maxist = max(acum.first + mid, acum.second);
    if(aint[node].st != -1) {
        pii atunci = combine(acum, aint[aint[node].st].lazy);
        maxist = max(atunci.first + aint[aint[node].st].maxi, atunci.second);
    }
    if(maxist > val) {
        if(aint[node].st == -1) {
          ll stanga = max(acum.second, acum.first + st);
          ll dreapta = max(acum.first + dr, acum.second);
          val++;
          if(val <= stanga) return st;
          if(val >= dreapta) return dr;
          return val - acum.first;
        }
        return cb(aint[node].st, st, mid, val, acum);
    }
    if(aint[node].dr == -1) {
             ll stanga = max(acum.second, acum.first + st);
          ll dreapta = max(acum.first + dr, acum.second);
          val++;
          if(val <= stanga) return st;
          if(val >= dreapta) return dr;
          return val - acum.first;
    }
    return cb(aint[node].dr, mid + 1, dr, val, acum);
}

ll query(int node, ll st, ll dr, ll nr, pii acum) {
  	acum = combine(acum, aint[node].lazy);
  	if(st == dr) {
      return max(acum.first + aint[node].maxi, acum.second);
    }
  	ll mid = (st + dr) >> 1;
    if(nr <= mid) {
    	if(aint[node].st == -1)
        	 return max(acum.first + nr, acum.second);
        return query(aint[node].st, st, mid, nr, acum);
    }
    if(aint[node].dr == -1)
    	return max(acum.first + nr, acum.second);
    return query(aint[node].dr, mid + 1, dr, nr, acum);
}

ll panaAcum[1001];

void init(int L, int N, std::vector<long long> T, std::vector<int> W, int X, int M, std::vector<int> S) {
    vector <int> indici;
    aint[cnt++] = {-1, -1, INF, NEUTRU};
    for(int i = 0; i < N; i++) {
        indici.push_back(i);
        panaAcum[i] = T[i];
    }
    sort(indici.begin(), indici.end(), [&W](const int &a, const int &b) {
        return W[a] > W[b];
    });
    while(indici.size() && W[indici.back()] <= X) {
        indici.pop_back();
    }
    for(int i = 1; i < M; i++) { /// de la 1
        //debug(i);
        sort(indici.begin(), indici.end(), [&W, &panaAcum](const int &a, const int &b) {
            return ((pii){panaAcum[a], W[a]} < (pii){panaAcum[b], W[b]});
        });
        ll maxim = 0;
        vector <ll> unde;
        for(int j = 0; j < indici.size(); j++) {
            unde.push_back(cb(0, 0, INF, panaAcum[indici[j]], NEUTRU));

        }
        update(0, 0, INF, 0, INF, {1LL * X * (S[i] - S[i - 1]), 0});
        for(int j = 0; j < indici.size(); j++) {
            panaAcum[indici[j]] += 1LL * W[indici[j]] * (S[i] - S[i - 1]);
            maxim = max(maxim, panaAcum[indici[j]]);
            panaAcum[indici[j]] = maxim;
            update(0, 0, INF, unde[j], INF, {0, maxim});

        }
    }
}

long long arrival_time(long long Y) {
    return query(0, 0, INF, Y, NEUTRU);
}

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:142:50: warning: capture of variable 'panaAcum' with non-automatic storage duration
  142 |         sort(indici.begin(), indici.end(), [&W, &panaAcum](const int &a, const int &b) {
      |                                                  ^~~~~~~~
overtaking.cpp:125:4: note: 'll panaAcum [1001]' declared here
  125 | ll panaAcum[1001];
      |    ^~~~~~~~
overtaking.cpp:147:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  147 |         for(int j = 0; j < indici.size(); j++) {
      |                        ~~^~~~~~~~~~~~~~~
overtaking.cpp:152:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  152 |         for(int j = 0; j < indici.size(); j++) {
      |                        ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 767 ms 971012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 402 ms 970844 KB Output is correct
2 Correct 304 ms 970840 KB Output is correct
3 Correct 312 ms 970836 KB Output is correct
4 Correct 290 ms 970840 KB Output is correct
5 Correct 279 ms 971056 KB Output is correct
6 Correct 334 ms 971040 KB Output is correct
7 Correct 422 ms 971084 KB Output is correct
8 Correct 337 ms 971088 KB Output is correct
9 Correct 335 ms 970940 KB Output is correct
10 Correct 298 ms 971088 KB Output is correct
11 Correct 293 ms 970928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 284 ms 970880 KB Output is correct
2 Correct 342 ms 970828 KB Output is correct
3 Correct 324 ms 970836 KB Output is correct
4 Correct 327 ms 971064 KB Output is correct
5 Correct 257 ms 970884 KB Output is correct
6 Correct 333 ms 971280 KB Output is correct
7 Correct 352 ms 971144 KB Output is correct
8 Correct 337 ms 970912 KB Output is correct
9 Correct 307 ms 971152 KB Output is correct
10 Correct 315 ms 970976 KB Output is correct
11 Correct 327 ms 970896 KB Output is correct
12 Correct 306 ms 971088 KB Output is correct
13 Correct 322 ms 971036 KB Output is correct
14 Correct 293 ms 970924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 767 ms 971012 KB Output is correct
2 Correct 402 ms 970844 KB Output is correct
3 Correct 304 ms 970840 KB Output is correct
4 Correct 312 ms 970836 KB Output is correct
5 Correct 290 ms 970840 KB Output is correct
6 Correct 284 ms 970880 KB Output is correct
7 Correct 342 ms 970828 KB Output is correct
8 Correct 324 ms 970836 KB Output is correct
9 Correct 349 ms 970844 KB Output is correct
10 Correct 324 ms 970884 KB Output is correct
11 Correct 331 ms 971288 KB Output is correct
12 Correct 310 ms 970872 KB Output is correct
13 Correct 314 ms 970852 KB Output is correct
14 Correct 317 ms 970892 KB Output is correct
15 Correct 338 ms 971064 KB Output is correct
16 Correct 310 ms 970900 KB Output is correct
17 Correct 308 ms 971016 KB Output is correct
18 Correct 323 ms 971064 KB Output is correct
19 Correct 333 ms 970844 KB Output is correct
20 Correct 339 ms 971048 KB Output is correct
21 Correct 318 ms 970836 KB Output is correct
22 Correct 307 ms 971232 KB Output is correct
23 Correct 293 ms 971064 KB Output is correct
24 Correct 369 ms 970836 KB Output is correct
25 Correct 310 ms 971056 KB Output is correct
26 Correct 314 ms 970960 KB Output is correct
27 Correct 313 ms 970844 KB Output is correct
28 Correct 306 ms 971072 KB Output is correct
29 Correct 314 ms 970860 KB Output is correct
30 Correct 280 ms 970836 KB Output is correct
31 Correct 348 ms 970836 KB Output is correct
32 Correct 342 ms 970832 KB Output is correct
33 Correct 360 ms 970940 KB Output is correct
34 Correct 267 ms 970988 KB Output is correct
35 Correct 346 ms 971048 KB Output is correct
36 Correct 348 ms 970836 KB Output is correct
37 Correct 344 ms 970836 KB Output is correct
38 Correct 259 ms 970960 KB Output is correct
39 Correct 309 ms 970968 KB Output is correct
40 Correct 320 ms 970932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 767 ms 971012 KB Output is correct
2 Correct 402 ms 970844 KB Output is correct
3 Correct 304 ms 970840 KB Output is correct
4 Correct 312 ms 970836 KB Output is correct
5 Correct 290 ms 970840 KB Output is correct
6 Correct 279 ms 971056 KB Output is correct
7 Correct 334 ms 971040 KB Output is correct
8 Correct 422 ms 971084 KB Output is correct
9 Correct 337 ms 971088 KB Output is correct
10 Correct 335 ms 970940 KB Output is correct
11 Correct 298 ms 971088 KB Output is correct
12 Correct 293 ms 970928 KB Output is correct
13 Correct 284 ms 970880 KB Output is correct
14 Correct 342 ms 970828 KB Output is correct
15 Correct 324 ms 970836 KB Output is correct
16 Correct 349 ms 970844 KB Output is correct
17 Correct 324 ms 970884 KB Output is correct
18 Correct 331 ms 971288 KB Output is correct
19 Correct 310 ms 970872 KB Output is correct
20 Correct 314 ms 970852 KB Output is correct
21 Correct 317 ms 970892 KB Output is correct
22 Correct 338 ms 971064 KB Output is correct
23 Correct 310 ms 970900 KB Output is correct
24 Correct 308 ms 971016 KB Output is correct
25 Correct 323 ms 971064 KB Output is correct
26 Correct 333 ms 970844 KB Output is correct
27 Correct 339 ms 971048 KB Output is correct
28 Correct 318 ms 970836 KB Output is correct
29 Correct 307 ms 971232 KB Output is correct
30 Correct 293 ms 971064 KB Output is correct
31 Correct 369 ms 970836 KB Output is correct
32 Correct 310 ms 971056 KB Output is correct
33 Correct 314 ms 970960 KB Output is correct
34 Correct 313 ms 970844 KB Output is correct
35 Correct 306 ms 971072 KB Output is correct
36 Correct 314 ms 970860 KB Output is correct
37 Correct 280 ms 970836 KB Output is correct
38 Correct 348 ms 970836 KB Output is correct
39 Correct 342 ms 970832 KB Output is correct
40 Correct 360 ms 970940 KB Output is correct
41 Correct 267 ms 970988 KB Output is correct
42 Correct 346 ms 971048 KB Output is correct
43 Correct 348 ms 970836 KB Output is correct
44 Correct 344 ms 970836 KB Output is correct
45 Correct 259 ms 970960 KB Output is correct
46 Correct 309 ms 970968 KB Output is correct
47 Correct 320 ms 970932 KB Output is correct
48 Correct 1651 ms 971136 KB Output is correct
49 Correct 1889 ms 971320 KB Output is correct
50 Correct 1995 ms 971220 KB Output is correct
51 Correct 1890 ms 971220 KB Output is correct
52 Correct 1812 ms 971148 KB Output is correct
53 Correct 1782 ms 971088 KB Output is correct
54 Correct 1792 ms 971220 KB Output is correct
55 Correct 1393 ms 971136 KB Output is correct
56 Correct 1615 ms 971220 KB Output is correct
57 Correct 1646 ms 971224 KB Output is correct
58 Correct 1602 ms 971220 KB Output is correct
59 Correct 1704 ms 971092 KB Output is correct
60 Correct 1618 ms 971268 KB Output is correct
61 Correct 1690 ms 971220 KB Output is correct
62 Correct 301 ms 971076 KB Output is correct
63 Correct 294 ms 971088 KB Output is correct
64 Correct 954 ms 971180 KB Output is correct
65 Correct 950 ms 971272 KB Output is correct
66 Correct 1946 ms 971276 KB Output is correct
67 Correct 1681 ms 971284 KB Output is correct
68 Correct 1700 ms 971244 KB Output is correct
69 Correct 1932 ms 971220 KB Output is correct
70 Correct 1988 ms 971220 KB Output is correct
71 Correct 1958 ms 971256 KB Output is correct
72 Correct 2240 ms 971244 KB Output is correct
73 Correct 1975 ms 971220 KB Output is correct
74 Correct 2143 ms 971220 KB Output is correct
75 Correct 257 ms 971048 KB Output is correct
76 Correct 272 ms 971248 KB Output is correct
77 Correct 263 ms 971292 KB Output is correct
78 Correct 1858 ms 971276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 767 ms 971012 KB Output is correct
2 Correct 402 ms 970844 KB Output is correct
3 Correct 304 ms 970840 KB Output is correct
4 Correct 312 ms 970836 KB Output is correct
5 Correct 290 ms 970840 KB Output is correct
6 Correct 279 ms 971056 KB Output is correct
7 Correct 334 ms 971040 KB Output is correct
8 Correct 422 ms 971084 KB Output is correct
9 Correct 337 ms 971088 KB Output is correct
10 Correct 335 ms 970940 KB Output is correct
11 Correct 298 ms 971088 KB Output is correct
12 Correct 293 ms 970928 KB Output is correct
13 Correct 284 ms 970880 KB Output is correct
14 Correct 342 ms 970828 KB Output is correct
15 Correct 324 ms 970836 KB Output is correct
16 Correct 327 ms 971064 KB Output is correct
17 Correct 257 ms 970884 KB Output is correct
18 Correct 333 ms 971280 KB Output is correct
19 Correct 352 ms 971144 KB Output is correct
20 Correct 337 ms 970912 KB Output is correct
21 Correct 307 ms 971152 KB Output is correct
22 Correct 315 ms 970976 KB Output is correct
23 Correct 327 ms 970896 KB Output is correct
24 Correct 306 ms 971088 KB Output is correct
25 Correct 322 ms 971036 KB Output is correct
26 Correct 293 ms 970924 KB Output is correct
27 Correct 349 ms 970844 KB Output is correct
28 Correct 324 ms 970884 KB Output is correct
29 Correct 331 ms 971288 KB Output is correct
30 Correct 310 ms 970872 KB Output is correct
31 Correct 314 ms 970852 KB Output is correct
32 Correct 317 ms 970892 KB Output is correct
33 Correct 338 ms 971064 KB Output is correct
34 Correct 310 ms 970900 KB Output is correct
35 Correct 308 ms 971016 KB Output is correct
36 Correct 323 ms 971064 KB Output is correct
37 Correct 333 ms 970844 KB Output is correct
38 Correct 339 ms 971048 KB Output is correct
39 Correct 318 ms 970836 KB Output is correct
40 Correct 307 ms 971232 KB Output is correct
41 Correct 293 ms 971064 KB Output is correct
42 Correct 369 ms 970836 KB Output is correct
43 Correct 310 ms 971056 KB Output is correct
44 Correct 314 ms 970960 KB Output is correct
45 Correct 313 ms 970844 KB Output is correct
46 Correct 306 ms 971072 KB Output is correct
47 Correct 314 ms 970860 KB Output is correct
48 Correct 280 ms 970836 KB Output is correct
49 Correct 348 ms 970836 KB Output is correct
50 Correct 342 ms 970832 KB Output is correct
51 Correct 360 ms 970940 KB Output is correct
52 Correct 267 ms 970988 KB Output is correct
53 Correct 346 ms 971048 KB Output is correct
54 Correct 348 ms 970836 KB Output is correct
55 Correct 344 ms 970836 KB Output is correct
56 Correct 259 ms 970960 KB Output is correct
57 Correct 309 ms 970968 KB Output is correct
58 Correct 320 ms 970932 KB Output is correct
59 Correct 1651 ms 971136 KB Output is correct
60 Correct 1889 ms 971320 KB Output is correct
61 Correct 1995 ms 971220 KB Output is correct
62 Correct 1890 ms 971220 KB Output is correct
63 Correct 1812 ms 971148 KB Output is correct
64 Correct 1782 ms 971088 KB Output is correct
65 Correct 1792 ms 971220 KB Output is correct
66 Correct 1393 ms 971136 KB Output is correct
67 Correct 1615 ms 971220 KB Output is correct
68 Correct 1646 ms 971224 KB Output is correct
69 Correct 1602 ms 971220 KB Output is correct
70 Correct 1704 ms 971092 KB Output is correct
71 Correct 1618 ms 971268 KB Output is correct
72 Correct 1690 ms 971220 KB Output is correct
73 Correct 301 ms 971076 KB Output is correct
74 Correct 294 ms 971088 KB Output is correct
75 Correct 954 ms 971180 KB Output is correct
76 Correct 950 ms 971272 KB Output is correct
77 Correct 1946 ms 971276 KB Output is correct
78 Correct 1681 ms 971284 KB Output is correct
79 Correct 1700 ms 971244 KB Output is correct
80 Correct 1932 ms 971220 KB Output is correct
81 Correct 1988 ms 971220 KB Output is correct
82 Correct 1958 ms 971256 KB Output is correct
83 Correct 2240 ms 971244 KB Output is correct
84 Correct 1975 ms 971220 KB Output is correct
85 Correct 2143 ms 971220 KB Output is correct
86 Correct 257 ms 971048 KB Output is correct
87 Correct 272 ms 971248 KB Output is correct
88 Correct 263 ms 971292 KB Output is correct
89 Correct 1858 ms 971276 KB Output is correct
90 Correct 1649 ms 974256 KB Output is correct
91 Correct 2128 ms 1005064 KB Output is correct
92 Correct 2226 ms 1004892 KB Output is correct
93 Correct 2140 ms 1006204 KB Output is correct
94 Correct 2140 ms 1005680 KB Output is correct
95 Correct 2124 ms 1006184 KB Output is correct
96 Correct 2135 ms 1006104 KB Output is correct
97 Correct 1456 ms 974328 KB Output is correct
98 Correct 1973 ms 1005904 KB Output is correct
99 Correct 2045 ms 1006820 KB Output is correct
100 Correct 2190 ms 1006064 KB Output is correct
101 Correct 1997 ms 1005736 KB Output is correct
102 Correct 1969 ms 1005828 KB Output is correct
103 Correct 2062 ms 1006164 KB Output is correct
104 Correct 1259 ms 1004116 KB Output is correct
105 Correct 1343 ms 1008428 KB Output is correct
106 Correct 2394 ms 1013012 KB Output is correct
107 Correct 2041 ms 1013892 KB Output is correct
108 Correct 2115 ms 1013904 KB Output is correct
109 Correct 2071 ms 1012948 KB Output is correct
110 Correct 2118 ms 1013840 KB Output is correct
111 Correct 2300 ms 1006036 KB Output is correct
112 Correct 2334 ms 1005788 KB Output is correct
113 Correct 2682 ms 1007380 KB Output is correct
114 Correct 3200 ms 1008560 KB Output is correct
115 Correct 2537 ms 1006408 KB Output is correct
116 Correct 2399 ms 1007228 KB Output is correct
117 Correct 443 ms 1010004 KB Output is correct
118 Correct 443 ms 1010004 KB Output is correct
119 Correct 443 ms 1008116 KB Output is correct
120 Correct 440 ms 1010000 KB Output is correct
121 Correct 442 ms 1011244 KB Output is correct
122 Correct 2189 ms 1000284 KB Output is correct
123 Correct 3256 ms 1008340 KB Output is correct
124 Correct 3236 ms 1008140 KB Output is correct
125 Correct 3224 ms 1003940 KB Output is correct