QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#308237#8016. 不休陀螺Xiaohuba0 504ms160576kbC++235.4kb2024-01-19 19:29:352024-01-19 19:29:35

Judging History

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

  • [2024-01-19 19:29:35]
  • 评测
  • 测评结果:0
  • 用时:504ms
  • 内存:160576kb
  • [2024-01-19 19:29:35]
  • 提交

answer

// clang-format off
#include <bits/stdc++.h>

using namespace std;

#if __cplusplus < 201400
  #warning "Please use c++14 or higher."
  #define INLINE_V
  #define REGISTER_V register
  #define CPP14CONSTEXPR
  #define gcd __gcd
  #define CPP14ENABLE_IF
#elif __cplusplus < 201700
  #define INLINE_V
  #define REGISTER_V
  #define CPP14CONSTEXPR constexpr
  #define gcd __gcd
  #define CPP14ENABLE_IF ,enable_if_t<_is_integer<T>, int> = 0
#else
  #define INLINE_V inline
  #define REGISTER_V
  #define CPP14CONSTEXPR constexpr
  #define CPP14ENABLE_IF ,enable_if_t<_is_integer<T>, int> = 0
#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 For(i,j,k) for(REGISTER_V int i=(j);i<=(k);++i) // NOLINT
#define ForDown(i,j,k) for(REGISTER_V int i=(j);i>=(k);--i) // NOLINT
#define pb push_back
#define eb emplace_back
#ifndef ONLINE_JUDGE
#define FileIO(filename) freopen(filename".in","r",stdin);freopen(filename".out","w",stdout)
#else
#define FileIO(filename)
#endif

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

#if __cplusplus >= 201400
  template <class T> INLINE_V constexpr bool _is_integer = numeric_limits<T>::is_integer;
  // template <> INLINE_V constexpr bool _is_integer<__int128> = true;
  // template <> INLINE_V constexpr bool _is_integer<__uint128_t> = true;
  template <> INLINE_V constexpr bool _is_integer<bool> = false;
  template <> INLINE_V constexpr bool _is_integer<char> = false;
  template <class T CPP14ENABLE_IF>
    INLINE_V constexpr T INF = numeric_limits<T>::max() >> 1;
#endif

template<typename T> constexpr il T sq(const T & x){return x*x;}
template<typename T> CPP14CONSTEXPR il void cmin(T & x, const T &y){x=min(x,y);}
template<typename T> CPP14CONSTEXPR il void cmax(T & x, const T &y){x=max(x,y);}
template<typename T> CPP14CONSTEXPR il T qpow(T x, ull y, T mod){T ans=1;x%=mod;while(y){if(y&1)(ans*=x)%=mod;(x*=x)%=mod;y>>=1;}return ans;}
template<typename T> CPP14CONSTEXPR il T qpow(T x, ull y){T ans=1;while(y){if(y&1)ans*=x;x*=x;y>>=1;}return ans;}
template<typename T CPP14ENABLE_IF> 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...); }

// File head end
// clang-format on

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using bst = __gnu_pbds::tree<pair<ll, int>, null_type, less<>, rb_tree_tag,
                             tree_order_statistics_node_update>;

namespace {
constexpr ll MAXN = 1e6 + 5;
int n, E, id[MAXN];
pii a[MAXN];
ll sum[MAXN];
class PrioQueue {
  struct Node {
    ll val, tag;
    int lc, rc, fa;
    Node() : val(0), tag(0), lc(0), rc(0), fa(0) {}
  } static T[MAXN * 4];
#define lc(p) (T[p].lc)
#define rc(p) (T[p].rc)
#define fa(p) (T[p].fa)
  static mt19937 rnd;
  static int cnt;
  int rt;

public:
  PrioQueue() : rt(0) {}
  il void pd(int p) {
    T[lc(p)].val += T[p].tag, T[lc(p)].tag += T[p].tag;
    T[rc(p)].val += T[p].tag, T[rc(p)].tag += T[p].tag;
  }
  int merge(int p, int q) {
    if (!p || !q)
      return p | q;
    pd(p), pd(q);
    if (T[p].val < T[q].val) {
      int &ch = (rnd() & 1) ? lc(p) : rc(p);
      return ch = merge(ch, q), fa(ch) = p, p;
    } else {
      int &ch = (rnd() & 1) ? lc(q) : rc(q);
      return ch = merge(ch, p), fa(ch) = q, q;
    }
  }
  il void erase(int p) {
    int f = fa(p);
    pd(f), pd(p);
    if (!f)
      rt = merge(lc(p), rc(p)), fa(rt) = 0;
    else if (lc(f) == p)
      lc(f) = merge(lc(p), rc(p)), fa(lc(f)) = f;
    else
      rc(f) = merge(lc(p), rc(p)), fa(rc(f)) = f;
  }
  il void add(int val) {
    if (rt)
      T[rt].val += val, T[rt].tag += val;
  }
  il int insert(ll val) {
    int p = ++cnt;
    T[p].val = val;
    return rt = merge(rt, p), p;
  }
  il ll top() const { return T[rt].val; }
  il bool empty() const { return !rt; }
};

PrioQueue::Node PrioQueue::T[MAXN * 4];
mt19937 PrioQueue::rnd = mt19937(random_device{}());
int PrioQueue::cnt = 0;

PrioQueue pq;
bst st;
ll Cur = 0;
il bool ok(int pos) {
  return pq.empty() ||
         (pq.top() >= a[pos].fi - a[pos].se && (E - a[pos].fi) >= Cur);
}
il void ins(int pos) {
  if (a[pos].se < a[pos].fi) {
    Cur += a[pos].fi - a[pos].se;
    pq.add(a[pos].se - a[pos].fi);
  }
  id[pos] = pq.insert(E - a[pos].fi);
  st.insert(mkp(sum[pos], pos));
}
il void del(int pos) {
  if (a[pos].se < a[pos].fi) {
    Cur -= a[pos].fi - a[pos].se;
    pq.add(a[pos].fi - a[pos].se);
  }
  pq.erase(id[pos]);
  st.erase(mkp(sum[pos], pos));
}

il void solver_main() {
  read(n, E);
  For(i, 1, n) read(a[i].fi);
  For(i, 1, n) read(a[i].se);
  For(i, 1, n) sum[i] = sum[i - 1] + a[i].se - a[i].fi;

  ll cnt = 0;
  for (int i = 1, j = 0; i <= n; i++) {
    while (j + 1 <= n && ok(j + 1))
      ins(++j);
    cnt += st.size() - st.order_of_key(mkp(sum[i - 1], 0));
    // cerr << i << ' ' << j << '\n';
    del(i);
  }
  cout << cnt << '\n';
}
} // namespace

signed main() { return solver_main(), 0; }

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 133140kb

input:

5000 939255322
47952340 92329911 61615795 40122788 47258178 29326499 9822850 42767362 86610596 60318756 52429688 87502511 50194916 96377063 74322128 19511341 28794957 53813791 79075058 35555414 5249682 45174421 101856091 25257909 94697470 45853817 82945426 108415825 41731145 87133877 75167193 598696...

output:

1778108

result:

wrong answer 1st lines differ - expected: '1846283', found: '1778108'

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 335ms
memory: 147272kb

input:

774484 763692678
47702350 34856775 28447988 4178162 45063720 8232662 36845607 27038945 44858289 5952529 39159657 21628528 60199611 5544054 59216841 39287087 43449994 20034684 56440004 11583811 44465341 32347476 49196492 22731571 9481143 11726859 35167370 23103544 23109378 38822668 29778048 58004104 ...

output:

76882660

result:

wrong answer 1st lines differ - expected: '124023429', found: '76882660'

Subtask #3:

score: 0
Wrong Answer

Test #10:

score: 0
Wrong Answer
time: 504ms
memory: 160576kb

input:

1000000 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

99999500004

result:

wrong answer 1st lines differ - expected: '99999500000', found: '99999500004'

Subtask #4:

score: 0
Wrong Answer

Test #14:

score: 0
Wrong Answer
time: 89ms
memory: 138860kb

input:

174457 888
0 0 0 0 1 0 0 1 1 1 0 1 0 1 1 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 0 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 1 1 1 0 1 0 1 0 0 1 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 1 0 0 0 1 0 1 1 1 0 1 0 0 0 1 0 1 0 1 1 1 1 0 0 0 0 1 1 1 1 1 1 0 1 0 1 1 0 0 1 0 0 1 0 0 1 0 1 0 0 1 1...

output:

282831301

result:

wrong answer 1st lines differ - expected: '329807918', found: '282831301'

Subtask #5:

score: 0
Wrong Answer

Test #18:

score: 0
Wrong Answer
time: 139ms
memory: 141540kb

input:

343922 773619774
0 8292680 5684115 0 0 170056 5385926 0 0 1588575 0 0 10947891 170867 35145 0 0 103085 7231562 0 0 0 0 11128944 0 4872226 0 2879880 7565181 0 8631665 0 5162564 9511835 514165 0 9628987 14357934 174784 0 12400154 0 0 8198218 0 8496060 0 0 0 0 10376826 3523227 0 14548249 0 6840016 0 0 ...

output:

20314358

result:

wrong answer 1st lines differ - expected: '36107528', found: '20314358'

Subtask #6:

score: 0
Wrong Answer

Test #24:

score: 0
Wrong Answer
time: 220ms
memory: 143852kb

input:

468676 582048177
6889433 7293342 20676061 15545414 4911497 12352219 8921719 1705801 19695926 25259227 2645394 17518171 19753552 9449377 982708 22479531 1267985 15594372 20685422 9627290 2017543 6459134 18614020 16206301 14962487 12932255 7101003 29140540 6479702 20607124 2540287 15565156 20274141 11...

output:

262687185

result:

wrong answer 1st lines differ - expected: '353280708', found: '262687185'