# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1170909 | jbareja | Meetings (JOI19_meetings) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
int N; // liczba miast
int Q; // liczba zapytań
vector<pair<int,int>> roads = {{ 0, 0 }}; // roads[i] - przedział czasu, w którym można przejść między wierzchołkami i, i+1
int answer(int v_start, int t_start, int v_end, int t_end) {
int time = t_start;
int leaps_cnt = 0;
if (v_start <= v_end) {
for (int 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 {
for (int 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) {
int P, S, E;
cin >> P >> S >> E;
roads[P] = { S, E };
}
else if (T == 2) {
int A, B, C, D;
cin >> A >> B >> C >> D;
cout << answer(A, B, C, D) << "\n";
}
}
}