QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#308282 | #8016. 不休陀螺 | Xiaohuba | 0 | 1153ms | 78660kb | C++23 | 5.3kb | 2024-01-19 20:27:05 | 2024-01-19 20:27:06 |
Judging History
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;
pii a[MAXN];
ll sum[MAXN];
struct Node {
int l, r;
ll minv, tag;
Node() : l(0), r(0), minv(1e18), tag(0) {}
} T[MAXN << 1];
#define mid(p) ((T[p].l + T[p].r) >> 1)
#define lc(p) (mid(p) << 1)
#define rc(p) (mid(p) << 1 | 1)
il void pu(int p) { T[p].minv = min(T[lc(p)].minv, T[rc(p)].minv); }
il void f(int p, ll tg) { assert(p), T[p].minv += tg, T[p].tag += tg; }
il void pd(int p) {
f(lc(p), T[p].tag);
f(rc(p), T[p].tag);
T[p].tag = 0;
}
void build(int p, int l, int r) {
T[p].l = l, T[p].r = r;
if (l == r)
return T[p].minv = E - a[l].fi, void();
build(lc(p), l, mid(p)), build(rc(p), mid(p) + 1, r);
pu(p);
}
void add(int p, int ql, int qr, int val) {
int l = T[p].l, r = T[p].r;
if (ql <= l && qr >= r)
return f(p, val);
pd(p);
if (ql <= mid(p))
add(lc(p), ql, qr, val);
if (qr > mid(p))
add(rc(p), ql, qr, val);
pu(p);
}
ll qry(int p, int ql, int qr) {
int l = T[p].l, r = T[p].r;
if (ql <= l && qr >= r)
return T[p].minv;
pd(p);
ll ans = 1e18;
if (ql <= mid(p))
cmin(ans, qry(lc(p), ql, qr));
if (qr > mid(p))
cmin(ans, qry(rc(p), ql, qr));
return ans;
}
bst st;
ll Cur = 0;
il bool ok(int l, int r) {
// if (l < r)
// cerr << "> " << l << ' ' << r << ' ' << qry(1, l, r - 1) << '\n';
return l >= r ||
(qry(1, l, r - 1) >= a[r].fi - a[r].se && E - a[r].fi >= Cur);
}
il void ins(int l, int pos) {
add(1, pos, pos, -Cur);
if (a[pos].se < a[pos].fi) {
Cur += a[pos].fi - a[pos].se;
if (l < pos)
add(1, l, pos - 1, a[pos].se - a[pos].fi);
}
st.insert(mkp(sum[pos], pos));
}
il void del(int pos, int r) {
if (a[pos].se < a[pos].fi) {
Cur -= a[pos].fi - a[pos].se;
if (pos < r)
add(1, pos + 1, r, a[pos].fi - a[pos].se);
}
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;
build(1, 1, n);
ll cnt = 0;
for (int i = 1, j = 0; i <= n; i++) {
while (j + 1 <= n && ok(i, j + 1))
j++, ins(i, j);
cnt += st.size() - st.order_of_key(mkp(sum[i - 1], n + 5));
del(i, j);
// cerr << i << ' ' << j << ' ' << Cur << ' ' << qry(1, 3, 3) << '\n';
}
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: 20
Accepted
time: 4ms
memory: 53384kb
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:
1846283
result:
ok single line: '1846283'
Test #2:
score: 0
Accepted
time: 3ms
memory: 53616kb
input:
4329 694688892 165277824 152780705 114369871 103975989 100188012 147665514 101173335 39350309 37624153 95413467 157561608 10779445 35486823 19200231 55106545 50853515 35799174 92799915 152580135 158388210 132197954 75468895 66543749 104662491 59493152 108170563 22295314 152619070 77921052 105881528 ...
output:
889705
result:
ok single line: '889705'
Test #3:
score: -20
Wrong Answer
time: 6ms
memory: 53684kb
input:
4932 10000000 879202 367773 895593 794951 253764 695611 164309 502290 638542 960084 766095 457948 783698 475707 157847 491793 196608 378324 211974 924944 42162 797172 334660 900879 522660 328814 402169 938267 498991 347773 922727 827106 16528 994043 12381 756925 642283 186848 423956 927655 344750 14...
output:
10724239
result:
wrong answer 1st lines differ - expected: '10724274', found: '10724239'
Subtask #2:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 897ms
memory: 65256kb
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:
124023426
result:
wrong answer 1st lines differ - expected: '124023429', found: '124023426'
Subtask #3:
score: 0
Wrong Answer
Test #10:
score: 0
Wrong Answer
time: 1153ms
memory: 78660kb
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:
99999499932
result:
wrong answer 1st lines differ - expected: '99999500000', found: '99999499932'
Subtask #4:
score: 0
Wrong Answer
Test #14:
score: 0
Wrong Answer
time: 173ms
memory: 54364kb
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:
318602438
result:
wrong answer 1st lines differ - expected: '329807918', found: '318602438'
Subtask #5:
score: 0
Wrong Answer
Test #18:
score: 20
Accepted
time: 360ms
memory: 57408kb
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:
36107528
result:
ok single line: '36107528'
Test #19:
score: -20
Wrong Answer
time: 956ms
memory: 64724kb
input:
822037 644760584 0 2469002 0 5619339 0 0 0 41690 0 2840922 7972819 2323916 0 7218270 0 0 6647344 1095198 0 5412830 6654778 0 4588035 0 5181193 5073101 0 0 0 2371931 2740725 6756043 4534813 1080318 3180435 0 0 0 7537979 0 9432571 3034547 1737404 7266942 0 0 5894473 2658989 0 3648760 6086440 768115 16...
output:
117551198
result:
wrong answer 1st lines differ - expected: '117551199', found: '117551198'
Subtask #6:
score: 0
Wrong Answer
Test #24:
score: 0
Wrong Answer
time: 570ms
memory: 61120kb
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:
353280691
result:
wrong answer 1st lines differ - expected: '353280708', found: '353280691'