QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#759458#6881. The Mine of Abysswly09AC ✓758ms12500kbC++202.5kb2024-11-18 08:49:132024-11-18 08:49:15

Judging History

你现在查看的是最新测评结果

  • [2024-11-18 08:49:15]
  • 评测
  • 测评结果:AC
  • 用时:758ms
  • 内存:12500kb
  • [2024-11-18 08:49:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int64_t N = 50003;
struct node_t {
  vector<pair<int64_t, int64_t>> v;
  static node_t merge(const node_t &a, const node_t &b) {
    vector<pair<int64_t, int64_t>> c;
    for (const auto &i : a.v)
      for (const auto &j : b.v)
        c.emplace_back(i.first + j.first, i.second + j.second);
    sort(c.begin(), c.end());
    vector<pair<int64_t, int64_t>> ret;
    int64_t l = 0, r = 0;
    for (const auto &i : c) {
      if (i.first > r + 1)
        ret.emplace_back(l, r), tie(l, r) = i;
      else
        r = max(i.second, r);
    }
    ret.emplace_back(l, r);
    return {ret};
  }
} tree[N << 2];
#define lc (p << 1)
#define rc (p << 1 | 1)
void init(int64_t p, int64_t l, int64_t r,
          const vector<pair<int64_t, int64_t>> &v) {
  if (l == r)
    return tree[p].v = {{0, 0}, v[l]}, void();
  int64_t mid = ((r - l) >> 1) + l;
  init(lc, l, mid, v), init(rc, mid + 1, r, v);
  tree[p] = node_t::merge(tree[lc], tree[rc]);
}

void modify(int64_t p, int64_t l, int64_t r, int64_t x,
            const pair<int64_t, int64_t> &y) {
  if (l == r)
    return tree[p].v = {{0, 0}, y}, void();
  int64_t mid = ((r - l) >> 1) + l;
  if (x <= mid)
    modify(lc, l, mid, x, y);
  else
    modify(rc, mid + 1, r, x, y);
  tree[p] = node_t::merge(tree[lc], tree[rc]);
}

node_t query(int64_t p, int64_t l, int64_t r, int64_t s, int64_t t) {
  if (s <= l && r <= t)
    return tree[p];
  int64_t mid = ((r - l) >> 1) + l;
  if (t <= mid)
    return query(lc, l, mid, s, t);
  else if (s > mid)
    return query(rc, mid + 1, r, s, t);
  else
    return node_t::merge(query(lc, l, mid, s, mid),
                         query(rc, mid + 1, r, mid + 1, t));
}

int64_t query(int64_t n, int64_t s, int64_t t) {
  int64_t ret = 0;
  for (const auto &i : query(1, 1, n, s, t).v)
    ret += i.second - i.first + 1;
  return ret;
}

void solve() {
  int64_t n, q;
  cin >> n >> q;
  vector<pair<int64_t, int64_t>> v(n + 1);
  for (int64_t i = 1; i <= n; ++i)
    cin >> v[i].first >> v[i].second;
  init(1, 1, n, v);
  while (q--) {
    int64_t op;
    cin >> op;
    if (op == 1) {
      int64_t k, a, b;
      cin >> k >> a >> b;
      modify(1, 1, n, k, make_pair(a, b));
    } else {
      int64_t l, r;
      cin >> l >> r;
      cout << query(n, l, r) << '\n';
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int64_t t;
  cin >> t;
  while (t--)
    solve();
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 758ms
memory: 12500kb

input:

5
50000 50000
66335693 455373104
899598534 953840292
368422768 959249831
322335641 856660797
480850713 530968323
444246089 548960441
177553896 210027481
240619910 965196933
107673862 824855024
92241752 129406040
4394331 263058383
165733990 352925680
548298523 585259106
87906940 102933202
56167973 68...

output:

6347314288230
13412326698823
14303672645309
10014078679793
3207056352395
17712636872598
6895088186582
2708865372007
13359299717471
7521970208616
29403542534309
19086646921794
22131828538506
3925621911951
8121263956040
2791149376358
11044093486507
7978219310275
3019861426855
7716880379924
66583487561...

result:

ok 125000 lines