QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#574133#1140. Distributing CandiesXiaohuba0 276ms58272kbC++234.9kb2024-09-18 20:53:212024-09-18 20:53:21

Judging History

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

  • [2024-09-18 20:53:21]
  • 评测
  • 测评结果:0
  • 用时:276ms
  • 内存:58272kb
  • [2024-09-18 20:53:21]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

// #define LOCK_GETCHAR
// #define USE_INT_128

#if __cplusplus < 201400
#warning "Please use c++14 or higher."
#define CONSTEXPR_FUNC
#define ENABLE_IF_INT
#else
#define CONSTEXPR_FUNC constexpr
#define ENABLE_IF_INT , enable_if_t<_is_integer<T>, int> = 0
template <class T> constexpr bool _is_integer = numeric_limits<T>::is_integer;
template <> constexpr bool _is_integer<bool> = false;
template <> constexpr bool _is_integer<char> = false;
#ifdef USE_INT_128
template <> constexpr bool _is_integer<__int128> = true;
template <> constexpr bool _is_integer<__uint128_t> = true;
#endif
#endif

#if !defined(_WIN32) && !defined(LOCK_GETCHAR)
#define getchar getchar_unlocked
#endif

#define il inline
#define mkp make_pair
#define fi first
#define se second
#define _loop_i_t(j, k) make_signed_t<decltype((j) - (k))>
#define For(i, j, k) for (_loop_i_t(j, k) i = (j); i <= (k); ++i) // NOLINT
#define ForDown(i, j, k)                                                       \
  for (_loop_i_t(j, k) i = (j); i >= decltype(i)(k); --i) // NOLINT
#define eb emplace_back
#ifndef ONLINE_JUDGE
#define FileIO(filename)                                                       \
  freopen(filename ".in", "r", stdin);                                         \
  freopen(filename ".out", "w", stdout)
#else
#define FileIO(filename) void(0)
#endif

using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using db = double;
using ldb = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#ifdef USE_INT_128
using lll = __int128_t;
using ulll = __uint128_t;
#endif

// clang-format off
CONSTEXPR_FUNC il ll qpow(ll x, ull y, ll mod){ ll ans = 1; x %= mod; while (y) { if (y & 1) (ans *= x) %= mod; (x *= x) %= mod; y >>= 1; } return ans; }
template<typename T> CONSTEXPR_FUNC il void cmin(T & x, const T &y){ x = min(x, y); }
template<typename T> CONSTEXPR_FUNC il void cmax(T & x, const T &y){ x = max(x, y); }
template<typename T ENABLE_IF_INT> il void read(T &x){ x = 0; int f = 1; int c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } x *= f; }
template<typename T, typename ... Args> il void read(T &x, Args &... y){ read(x), read(y...); }
// clang-format on

// File head end

namespace {
constexpr ll MAXN = 2e5 + 5, INF = ll(1e18) + 5;
struct Node {
  int l, r;
  pair<ll, int> maxv, minv;
  ll tag;
  Node() : l(0), r(0), maxv{}, minv{}, tag(0) {}
} T[MAXN << 2];
vector<int> todo[MAXN];
#define lc(p) ((p) << 1)
#define rc(p) ((p) << 1 | 1)
il void pu(int p) {
  T[p].maxv = max(T[lc(p)].maxv, T[rc(p)].maxv);
  T[p].minv = min(T[lc(p)].minv, T[rc(p)].minv);
}
void build(int p, int l, int r) {
  T[p].l = l, T[p].r = r;
  if (l == r)
    return T[p].maxv.se = T[p].minv.se = l, void();
  int mid = (l + r) >> 1;
  build(lc(p), l, mid), build(rc(p), mid + 1, r);
  pu(p);
}
il void f(int p, ll v) { T[p].maxv.fi += v, T[p].minv.fi += v, T[p].tag += v; }
void pd(int p) {
  if (T[p].tag)
    f(lc(p), T[p].tag), f(rc(p), T[p].tag), T[p].tag = 0;
}
void add(int p, int ql, ll val) {
  int l = T[p].l, r = T[p].r;
  if (ql <= l)
    return f(p, val);
  int mid = (l + r) >> 1;
  pd(p);
  if (ql <= mid)
    add(lc(p), ql, val);
  add(rc(p), ql, val);
  pu(p);
}
tuple<int, int, bool> qry(int p, int v, pair<ll, int> minv,
                          pair<ll, int> maxv) { // 1->maxv 0->minv
  int l = T[p].l, r = T[p].r;
  if (l == r) {
    cmax(maxv, T[p].maxv), cmin(minv, T[p].minv);
    assert(maxv.fi - minv.fi > v);
    return T[p].maxv == maxv ? make_tuple(l, minv.se, 1)
                             : make_tuple(l, maxv.se, 0);
  }
  pd(p);
  auto mn = min(minv, T[rc(p)].minv), mx = max(maxv, T[rc(p)].maxv);
  if (mx.fi - mn.fi > v)
    return qry(rc(p), v, minv, maxv);
  else
    return qry(lc(p), v, mn, mx);
}
ll at(int p, int pos) {
  while (T[p].l != T[p].r) {
    pd(p);
    int mid = (T[p].l + T[p].r) >> 1;
    p = p << 1 | (pos > mid);
  }
  return T[p].maxv.fi;
}
} // namespace

std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
                                    std::vector<int> r, std::vector<int> v) {
  int n = c.size(), q = l.size();
  vector<int> Ans(n);
  build(1, 1, q);
  For(i, 1, q) {
    todo[l[i - 1] + 1].eb(i);
    todo[r[i - 1] + 2].eb(-i);
  }
  ll sum = 0;
  For(i, 1, n) {
    for (int j : todo[i]) {
      if (j > 0)
        add(1, j, v[j - 1]), sum += v[j - 1];
      else
        add(1, j, -v[j - 1]), sum -= v[j - 1];
    }
    if (T[1].maxv.fi - T[1].minv.fi <= c[i - 1]) {
      Ans[i - 1] = sum - T[1].minv.fi;
      continue;
    }
    auto [id1, id2, tp] = qry(1, c[i - 1], {INF, 0}, {0, 0});
    if (tp)
      Ans[i - 1] = sum - at(1, id2);
    else
      Ans[i - 1] = sum + c[i - 1] - at(1, id2);
  }
  return Ans;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 5ms
memory: 43304kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
8
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
8
0 7 1
0 7 1
0 7 300000000
0 7 994967293
0 7 1
0 7 1000000000
0 7 1000000000
0 7 1000000000

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

result:

ok 3 lines

Test #2:

score: 0
Wrong Answer
time: 3ms
memory: 41828kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
10
283 43634 101056 10340 6009 5133 30 2 3677888 210
10
1 8 26416
2 7 -51219
2 4 17793
3 7 75426
3 7 22307
1 1 60258
3 7 -29824
0 8 24839
2 8 -60304
0 1 -26411

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
-1289 17223 14341 0 0 0 0 0 84084 0

result:

wrong answer 3rd lines differ - expected: '0 17223 0 0 0 0 0 0 0 0', found: '-1289 17223 14341 0 0 0 0 0 84084 0'

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 0
Wrong Answer
time: 276ms
memory: 58272kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
200000
11408901 370732653 37843 28 53693 15782410 103 297546 1112427 170319071 26 1 6172 11614171 431 884673599 1 3 50085 154 57 28200 145886 898969 74758 72 845768 6 69787 11 31012465 55362 253 2363145 47186217 1103 19622 594 7867 1 4299 28130 48 4689582 12 ...

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
87153 87153 37843 28 53693 406667 103 297546 766665 971468 26 1 6172 1257294 431 1536484 1 3 50085 154 57 28200 145886 898969 74758 72 845768 6 69787 11 3043755 55362 253 2363145 3459533 1103 19622 594 7867 1 4299 28130 48 4317336 12 431 123 4531465 4806 3...

result:

wrong answer 3rd lines differ - expected: '87153 87153 37843 28 53693 406...46468 9 1756 429030 247071 1629', found: '87153 87153 37843 28 53693 406...587028498 1426340428 1419487506'

Subtask #3:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 5ms
memory: 42652kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
1000
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000...

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

wrong answer 3rd lines differ - expected: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...0 1000 1000 1000 1000 1000 1000'

Subtask #4:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 4ms
memory: 42712kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
10
11 440 51 41 11 1 3 108 148 14
10
0 9 60
0 9 -9
0 9 -30
0 9 41
0 9 82
0 9 69
0 9 -79
0 9 -39
0 9 72
0 9 41

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
11 187 51 41 11 1 3 108 143 14

result:

wrong answer 3rd lines differ - expected: '11 208 51 41 11 1 3 108 143 14', found: '11 187 51 41 11 1 3 108 143 14'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%