Submission #1170928

#TimeUsernameProblemLanguageResultExecution timeMemory
1170928jbarejaBitaro, who Leaps through Time (JOI19_timeleap)C++20
4 / 100
3094 ms8624 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int N; // liczba miast int Q; // liczba zapytań vector<pair<ll,ll>> roads = {{ 0, 0 }}; // roads[i] - przedział czasu, w którym można przejść między wierzchołkami i, i+1 ll answer(ll v_start, ll t_start, ll v_end, ll t_end) { ll time = t_start; ll leaps_cnt = 0; if (v_start < v_end) { for (ll i=v_start; i<v_end; i++) { const auto& [L, R] = roads[i]; if (time < L) time = L; if (time >= R) { leaps_cnt += time - (R-1); time = R-1; } time++; } } else if (v_start > v_end) { for (ll i=v_start-1; i>=v_end; i--) { const auto& [L, R] = roads[i]; if (time < L) time = L; if (time >= R) { leaps_cnt += time - (R-1); time = R-1; } time++; } } if (time > t_end) leaps_cnt += time - t_end; return leaps_cnt; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> Q; for (int i=0; i<N-1; i++) { int L, R; cin >> L >> R; roads.push_back({ L, R }); } for (int i=0; i<Q; i++) { int T; cin >> T; if (T == 1) { ll P, S, E; cin >> P >> S >> E; roads[P] = { S, E }; } else if (T == 2) { ll A, B, C, D; cin >> A >> B >> C >> D; cout << answer(A, B, C, D) << "\n"; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...