Submission #957182

# Submission time Handle Problem Language Result Execution time Memory
957182 2024-04-03T06:45:31 Z Vladth11 Overtaking (IOI23_overtaking) C++17
65 / 100
3500 ms 1013212 KB
#include <bits/stdc++.h>

#include "overtaking.h"

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

const ll 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].st, st, mid);
    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:143:50: warning: capture of variable 'panaAcum' with non-automatic storage duration
  143 |         sort(indici.begin(), indici.end(), [&W, &panaAcum](const int &a, const int &b) {
      |                                                  ^~~~~~~~
overtaking.cpp:126:4: note: 'll panaAcum [1001]' declared here
  126 | ll panaAcum[1001];
      |    ^~~~~~~~
overtaking.cpp:148:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  148 |         for(int j = 0; j < indici.size(); j++) {
      |                        ~~^~~~~~~~~~~~~~~
overtaking.cpp:153:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  153 |         for(int j = 0; j < indici.size(); j++) {
      |                        ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 301 ms 970868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 288 ms 970836 KB Output is correct
2 Correct 289 ms 971300 KB Output is correct
3 Correct 292 ms 970856 KB Output is correct
4 Correct 294 ms 971032 KB Output is correct
5 Correct 425 ms 970840 KB Output is correct
6 Correct 294 ms 971028 KB Output is correct
7 Correct 316 ms 971116 KB Output is correct
8 Correct 278 ms 971076 KB Output is correct
9 Correct 281 ms 971084 KB Output is correct
10 Correct 280 ms 970908 KB Output is correct
11 Correct 289 ms 971124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 276 ms 970832 KB Output is correct
2 Correct 280 ms 970988 KB Output is correct
3 Correct 280 ms 970932 KB Output is correct
4 Correct 276 ms 970976 KB Output is correct
5 Correct 284 ms 970932 KB Output is correct
6 Correct 277 ms 971088 KB Output is correct
7 Correct 281 ms 971088 KB Output is correct
8 Correct 279 ms 971092 KB Output is correct
9 Correct 280 ms 971120 KB Output is correct
10 Correct 280 ms 971088 KB Output is correct
11 Correct 277 ms 970892 KB Output is correct
12 Correct 284 ms 971372 KB Output is correct
13 Correct 275 ms 971124 KB Output is correct
14 Correct 281 ms 971092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 301 ms 970868 KB Output is correct
2 Correct 288 ms 970836 KB Output is correct
3 Correct 289 ms 971300 KB Output is correct
4 Correct 292 ms 970856 KB Output is correct
5 Correct 294 ms 971032 KB Output is correct
6 Correct 276 ms 970832 KB Output is correct
7 Correct 280 ms 970988 KB Output is correct
8 Correct 280 ms 970932 KB Output is correct
9 Correct 314 ms 970832 KB Output is correct
10 Correct 294 ms 970996 KB Output is correct
11 Correct 294 ms 971048 KB Output is correct
12 Correct 300 ms 971088 KB Output is correct
13 Correct 301 ms 970980 KB Output is correct
14 Correct 303 ms 970904 KB Output is correct
15 Correct 299 ms 970980 KB Output is correct
16 Correct 292 ms 970872 KB Output is correct
17 Correct 297 ms 971088 KB Output is correct
18 Correct 290 ms 971000 KB Output is correct
19 Correct 287 ms 970836 KB Output is correct
20 Correct 314 ms 970888 KB Output is correct
21 Correct 281 ms 970836 KB Output is correct
22 Correct 290 ms 971012 KB Output is correct
23 Correct 292 ms 970832 KB Output is correct
24 Correct 292 ms 970996 KB Output is correct
25 Correct 288 ms 970836 KB Output is correct
26 Correct 289 ms 970836 KB Output is correct
27 Correct 295 ms 971188 KB Output is correct
28 Correct 288 ms 970836 KB Output is correct
29 Correct 293 ms 971308 KB Output is correct
30 Correct 289 ms 971000 KB Output is correct
31 Correct 289 ms 970836 KB Output is correct
32 Correct 289 ms 970832 KB Output is correct
33 Correct 303 ms 970964 KB Output is correct
34 Correct 292 ms 971032 KB Output is correct
35 Correct 295 ms 970824 KB Output is correct
36 Correct 303 ms 971152 KB Output is correct
37 Correct 295 ms 970836 KB Output is correct
38 Correct 283 ms 971312 KB Output is correct
39 Correct 276 ms 970836 KB Output is correct
40 Correct 301 ms 970860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 301 ms 970868 KB Output is correct
2 Correct 288 ms 970836 KB Output is correct
3 Correct 289 ms 971300 KB Output is correct
4 Correct 292 ms 970856 KB Output is correct
5 Correct 294 ms 971032 KB Output is correct
6 Correct 425 ms 970840 KB Output is correct
7 Correct 294 ms 971028 KB Output is correct
8 Correct 316 ms 971116 KB Output is correct
9 Correct 278 ms 971076 KB Output is correct
10 Correct 281 ms 971084 KB Output is correct
11 Correct 280 ms 970908 KB Output is correct
12 Correct 289 ms 971124 KB Output is correct
13 Correct 276 ms 970832 KB Output is correct
14 Correct 280 ms 970988 KB Output is correct
15 Correct 280 ms 970932 KB Output is correct
16 Correct 314 ms 970832 KB Output is correct
17 Correct 294 ms 970996 KB Output is correct
18 Correct 294 ms 971048 KB Output is correct
19 Correct 300 ms 971088 KB Output is correct
20 Correct 301 ms 970980 KB Output is correct
21 Correct 303 ms 970904 KB Output is correct
22 Correct 299 ms 970980 KB Output is correct
23 Correct 292 ms 970872 KB Output is correct
24 Correct 297 ms 971088 KB Output is correct
25 Correct 290 ms 971000 KB Output is correct
26 Correct 287 ms 970836 KB Output is correct
27 Correct 314 ms 970888 KB Output is correct
28 Correct 281 ms 970836 KB Output is correct
29 Correct 290 ms 971012 KB Output is correct
30 Correct 292 ms 970832 KB Output is correct
31 Correct 292 ms 970996 KB Output is correct
32 Correct 288 ms 970836 KB Output is correct
33 Correct 289 ms 970836 KB Output is correct
34 Correct 295 ms 971188 KB Output is correct
35 Correct 288 ms 970836 KB Output is correct
36 Correct 293 ms 971308 KB Output is correct
37 Correct 289 ms 971000 KB Output is correct
38 Correct 289 ms 970836 KB Output is correct
39 Correct 289 ms 970832 KB Output is correct
40 Correct 303 ms 970964 KB Output is correct
41 Correct 292 ms 971032 KB Output is correct
42 Correct 295 ms 970824 KB Output is correct
43 Correct 303 ms 971152 KB Output is correct
44 Correct 295 ms 970836 KB Output is correct
45 Correct 283 ms 971312 KB Output is correct
46 Correct 276 ms 970836 KB Output is correct
47 Correct 301 ms 970860 KB Output is correct
48 Correct 2094 ms 971136 KB Output is correct
49 Correct 2068 ms 971216 KB Output is correct
50 Correct 2057 ms 971216 KB Output is correct
51 Correct 1930 ms 971220 KB Output is correct
52 Correct 1965 ms 971252 KB Output is correct
53 Correct 2025 ms 971216 KB Output is correct
54 Correct 1945 ms 971216 KB Output is correct
55 Correct 1491 ms 971136 KB Output is correct
56 Correct 1833 ms 971216 KB Output is correct
57 Correct 1847 ms 971224 KB Output is correct
58 Correct 1725 ms 971220 KB Output is correct
59 Correct 1708 ms 971504 KB Output is correct
60 Correct 1734 ms 971220 KB Output is correct
61 Correct 1734 ms 971344 KB Output is correct
62 Correct 291 ms 971088 KB Output is correct
63 Correct 276 ms 971276 KB Output is correct
64 Correct 965 ms 971348 KB Output is correct
65 Correct 1033 ms 971220 KB Output is correct
66 Correct 2035 ms 971248 KB Output is correct
67 Correct 1924 ms 971288 KB Output is correct
68 Correct 1887 ms 971308 KB Output is correct
69 Correct 2016 ms 971216 KB Output is correct
70 Correct 2067 ms 971220 KB Output is correct
71 Correct 2193 ms 971092 KB Output is correct
72 Correct 2343 ms 971224 KB Output is correct
73 Correct 2158 ms 971348 KB Output is correct
74 Correct 2235 ms 971220 KB Output is correct
75 Correct 281 ms 971172 KB Output is correct
76 Correct 265 ms 971092 KB Output is correct
77 Correct 277 ms 971180 KB Output is correct
78 Correct 1757 ms 971248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 301 ms 970868 KB Output is correct
2 Correct 288 ms 970836 KB Output is correct
3 Correct 289 ms 971300 KB Output is correct
4 Correct 292 ms 970856 KB Output is correct
5 Correct 294 ms 971032 KB Output is correct
6 Correct 425 ms 970840 KB Output is correct
7 Correct 294 ms 971028 KB Output is correct
8 Correct 316 ms 971116 KB Output is correct
9 Correct 278 ms 971076 KB Output is correct
10 Correct 281 ms 971084 KB Output is correct
11 Correct 280 ms 970908 KB Output is correct
12 Correct 289 ms 971124 KB Output is correct
13 Correct 276 ms 970832 KB Output is correct
14 Correct 280 ms 970988 KB Output is correct
15 Correct 280 ms 970932 KB Output is correct
16 Correct 276 ms 970976 KB Output is correct
17 Correct 284 ms 970932 KB Output is correct
18 Correct 277 ms 971088 KB Output is correct
19 Correct 281 ms 971088 KB Output is correct
20 Correct 279 ms 971092 KB Output is correct
21 Correct 280 ms 971120 KB Output is correct
22 Correct 280 ms 971088 KB Output is correct
23 Correct 277 ms 970892 KB Output is correct
24 Correct 284 ms 971372 KB Output is correct
25 Correct 275 ms 971124 KB Output is correct
26 Correct 281 ms 971092 KB Output is correct
27 Correct 314 ms 970832 KB Output is correct
28 Correct 294 ms 970996 KB Output is correct
29 Correct 294 ms 971048 KB Output is correct
30 Correct 300 ms 971088 KB Output is correct
31 Correct 301 ms 970980 KB Output is correct
32 Correct 303 ms 970904 KB Output is correct
33 Correct 299 ms 970980 KB Output is correct
34 Correct 292 ms 970872 KB Output is correct
35 Correct 297 ms 971088 KB Output is correct
36 Correct 290 ms 971000 KB Output is correct
37 Correct 287 ms 970836 KB Output is correct
38 Correct 314 ms 970888 KB Output is correct
39 Correct 281 ms 970836 KB Output is correct
40 Correct 290 ms 971012 KB Output is correct
41 Correct 292 ms 970832 KB Output is correct
42 Correct 292 ms 970996 KB Output is correct
43 Correct 288 ms 970836 KB Output is correct
44 Correct 289 ms 970836 KB Output is correct
45 Correct 295 ms 971188 KB Output is correct
46 Correct 288 ms 970836 KB Output is correct
47 Correct 293 ms 971308 KB Output is correct
48 Correct 289 ms 971000 KB Output is correct
49 Correct 289 ms 970836 KB Output is correct
50 Correct 289 ms 970832 KB Output is correct
51 Correct 303 ms 970964 KB Output is correct
52 Correct 292 ms 971032 KB Output is correct
53 Correct 295 ms 970824 KB Output is correct
54 Correct 303 ms 971152 KB Output is correct
55 Correct 295 ms 970836 KB Output is correct
56 Correct 283 ms 971312 KB Output is correct
57 Correct 276 ms 970836 KB Output is correct
58 Correct 301 ms 970860 KB Output is correct
59 Correct 2094 ms 971136 KB Output is correct
60 Correct 2068 ms 971216 KB Output is correct
61 Correct 2057 ms 971216 KB Output is correct
62 Correct 1930 ms 971220 KB Output is correct
63 Correct 1965 ms 971252 KB Output is correct
64 Correct 2025 ms 971216 KB Output is correct
65 Correct 1945 ms 971216 KB Output is correct
66 Correct 1491 ms 971136 KB Output is correct
67 Correct 1833 ms 971216 KB Output is correct
68 Correct 1847 ms 971224 KB Output is correct
69 Correct 1725 ms 971220 KB Output is correct
70 Correct 1708 ms 971504 KB Output is correct
71 Correct 1734 ms 971220 KB Output is correct
72 Correct 1734 ms 971344 KB Output is correct
73 Correct 291 ms 971088 KB Output is correct
74 Correct 276 ms 971276 KB Output is correct
75 Correct 965 ms 971348 KB Output is correct
76 Correct 1033 ms 971220 KB Output is correct
77 Correct 2035 ms 971248 KB Output is correct
78 Correct 1924 ms 971288 KB Output is correct
79 Correct 1887 ms 971308 KB Output is correct
80 Correct 2016 ms 971216 KB Output is correct
81 Correct 2067 ms 971220 KB Output is correct
82 Correct 2193 ms 971092 KB Output is correct
83 Correct 2343 ms 971224 KB Output is correct
84 Correct 2158 ms 971348 KB Output is correct
85 Correct 2235 ms 971220 KB Output is correct
86 Correct 281 ms 971172 KB Output is correct
87 Correct 265 ms 971092 KB Output is correct
88 Correct 277 ms 971180 KB Output is correct
89 Correct 1757 ms 971248 KB Output is correct
90 Correct 1737 ms 974260 KB Output is correct
91 Correct 2181 ms 1005748 KB Output is correct
92 Correct 2287 ms 1005300 KB Output is correct
93 Correct 2192 ms 1005836 KB Output is correct
94 Correct 2213 ms 1005484 KB Output is correct
95 Correct 2505 ms 1005620 KB Output is correct
96 Correct 2183 ms 1005832 KB Output is correct
97 Correct 1460 ms 974344 KB Output is correct
98 Correct 2048 ms 1005536 KB Output is correct
99 Correct 2089 ms 1006344 KB Output is correct
100 Correct 2077 ms 1005600 KB Output is correct
101 Correct 2053 ms 1005216 KB Output is correct
102 Correct 2112 ms 1005324 KB Output is correct
103 Correct 2120 ms 1005832 KB Output is correct
104 Correct 1288 ms 1003612 KB Output is correct
105 Correct 1351 ms 1008132 KB Output is correct
106 Correct 2478 ms 1013000 KB Output is correct
107 Correct 2138 ms 1012648 KB Output is correct
108 Correct 2261 ms 1012896 KB Output is correct
109 Correct 2068 ms 1012752 KB Output is correct
110 Correct 2165 ms 1013212 KB Output is correct
111 Correct 2350 ms 1006368 KB Output is correct
112 Correct 2416 ms 1006088 KB Output is correct
113 Correct 3008 ms 1006980 KB Output is correct
114 Execution timed out 3552 ms 1004452 KB Time limit exceeded
115 Halted 0 ms 0 KB -