답안 #256898

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
256898 2020-08-03T11:09:57 Z fedoseevtimofey Bitaro, who Leaps through Time (JOI19_timeleap) C++14
0 / 100
3000 ms 19728 KB
#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 - 1;
    } 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;
      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 - 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';
  }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3058 ms 19728 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -