제출 #256832

#제출 시각아이디문제언어결과실행 시간메모리
256832fedoseevtimofeyBitaro, who Leaps through Time (JOI19_timeleap)C++14
4 / 100
3079 ms8512 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;
 
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];
  }
  for (int tt = 0; tt < q; ++tt) {
    int t;
    cin >> t;
    if (t == 1) {
      int p, s, e;
      cin >> p >> s >> e;
      --p;
      l[p] = s;
      r[p] = e - 1;
    } else {
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      --a, --c;
      ll ans = 0;
      int tm = b;
      if (a <= c) { 
        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);
      } else {
        for (int i = a - 1; 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); 
      }
      cout << ans << '\n';
    }
  } 
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...