Submission #1127305

#TimeUsernameProblemLanguageResultExecution timeMemory
1127305OI_AccountBitaro, who Leaps through Time (JOI19_timeleap)C++20
4 / 100
3093 ms4816 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 300'000; int n, q; ll l[N + 10], r[N + 10]; void readInput() { cin >> n >> q; for (int i = 1; i < n; i++) cin >> l[i] >> r[i]; } void queryChange() { int idx; cin >> idx; cin >> l[idx] >> r[idx]; } ll calcAns(int a, ll b, int c, ll d) { if (a == c) return max(0ll, b - d); int nxt = (a < c? a + 1: a - 1); int edge = min(a, nxt); if (b < l[edge]) return calcAns(nxt, l[edge] + 1, c, d); if (r[edge] <= b) return calcAns(nxt, r[edge], c, d) + b - r[edge] + 1; return calcAns(nxt, b + 1, c, d); } void queryGet() { int a, b, c, d; cin >> a >> b >> c >> d; cout << calcAns(a, b, c, d) << '\n'; } void solve() { while (q--) { int type; cin >> type; if (type == 1) queryChange(); else queryGet(); } cout.flush(); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); readInput(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...