Submission #256899

#TimeUsernameProblemLanguageResultExecution timeMemory
256899fedoseevtimofeyBitaro, who Leaps through Time (JOI19_timeleap)C++14
4 / 100
3083 ms19548 KiB
#include <iostream> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm> #include <random> #include <iomanip> #include <functional> #include <cassert> using namespace std; typedef long long ll; const int N = 3e5 + 7; struct Query { int t, a, b, c, d, i; }; ll res[N]; void solve(int n, vector <int> l, vector <int> r, vector <Query> qrs) { int q = qrs.size(); for (int tt = 0; tt < q; ++tt) { int t = qrs[tt].t; if (t == 1) { int p = qrs[tt].a, s = qrs[tt].b, e = qrs[tt].c; l[p] = s; r[p] = e; } else { int a = qrs[tt].a, b = qrs[tt].b, c = qrs[tt].c, d = qrs[tt].d; assert(a <= c); ll ans = 0; int tm = b; for (int i = a; i < c; ++i) { ans += max(0, tm - r[i]); tm = min(tm, r[i]); tm = max(tm, l[i]); ++tm; } ans += max(0, tm - d); res[qrs[tt].i] = ans; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int n, q; cin >> n >> q; vector <int> l(n - 1), r(n - 1); for (int i = 0; i < n - 1; ++i) { cin >> l[i] >> r[i]; --r[i]; } vector <Query> qrs; int cnt_qr = 0; for (int tt = 0; tt < q; ++tt) { int t; cin >> t; if (t == 1) { int p, s, e; cin >> p >> s >> e; --p; --e; qrs.push_back({t, p, s, e, -1, -1}); } else { int a, b, c, d; cin >> a >> b >> c >> d; --a, --c; qrs.push_back({t, a, b, c, d, cnt_qr++}); } } { vector <Query> qr; for (auto qq : qrs) { if (qq.t == 1) qr.push_back(qq); else if (qq.a <= qq.c) qr.push_back(qq); } solve(n, l, r, qr); } { reverse(l.begin(), l.end()); reverse(r.begin(), r.end()); vector <Query> qr; for (auto qq : qrs) { if (qq.t == 1) { qq.a = (n - 1) - qq.a - 1; qr.push_back(qq); } else if (qq.a > qq.c) { qq.a = n - qq.a - 1; qq.c = n - qq.c - 1; qr.push_back(qq); } } solve(n, l, r, qr); } for (int i = 0; i < cnt_qr; ++i) { cout << res[i] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...