QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#307804 | #8016. 不休陀螺 | wsyear | 0 | 1082ms | 75716kb | C++14 | 2.8kb | 2024-01-19 09:44:59 | 2024-01-19 09:45:00 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef dbg
#define D(...) fprintf(stderr, __VA_ARGS__)
#define DD(...) D("[Debug] "#__VA_ARGS__ " = "), \
debug_helper::debug(__VA_ARGS__), D("\n")
#include "C:\Users\wsyear\Desktop\OI\templates\debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
template<class T> void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T> void chkmx(T &x, T y) { if (y > x) x = y; }
using namespace std;
const int maxn = 1000010;
int n, E, a[maxn], b[maxn], t[maxn];
ll s[maxn], sum[maxn], mx[maxn], v1[maxn], v2[maxn], ans;
pii que[maxn];
void upd(int x, int v) {
while (x <= n) t[x] += v, x += x & (-x);
}
int qry(int x) {
int res = 0;
while (x) res += t[x], x -= x & (-x);
return res;
}
void solve(int l, int r) {
if (l == r) return ans += (a[l] <= E && a[l] <= b[l]), void();
int mid = (l + r) >> 1;
solve(l, mid), solve(mid + 1, r);
s[mid] = b[mid] - a[mid], sum[mid] = min(0, b[mid] - a[mid]);
per (i, mid - 1, l) s[i] = s[i + 1] + b[i] - a[i];
per (i, mid - 1, l) sum[i] = sum[i + 1] + min(0, b[i] - a[i]);
mx[mid] = min(a[mid], b[mid]);
per (i, mid - 1, l) mx[i] = max(mx[i + 1], 1ll * min(a[i], b[i]));
s[mid + 1] = b[mid + 1] - a[mid + 1], sum[mid + 1] = min(0, b[mid + 1] - a[mid + 1]);
rep (i, mid + 2, r) s[i] = s[i - 1] + b[i] - a[i];
rep (i, mid + 2, r) sum[i] = sum[i - 1] + min(0, b[i] - a[i]);
mx[mid + 1] = min(a[mid + 1], b[mid + 1]);
rep (i, mid + 2, r) mx[i] = max(mx[i - 1], 1ll * min(a[i], b[i]));
rep (i, l, r) v1[i] = mx[i] - sum[i], v2[i] = sum[i] + E;
rep (i, l, r) que[i] = pii(-1, -1);
int pos = mid, p1 = l, p2 = mid;
rep (i, mid + 1, r) {
while (pos >= l && mx[pos] < mx[i]) pos--;
while (p1 <= mid && v1[p1] > v2[i]) p1++;
while (p2 >= l && v1[i] > v2[p2]) p2--;
if (p1 > pos && p2 < pos + 1) ;
else if (p1 > pos) que[i] = pii(pos + 1, p2);
else if (p2 < pos + 1) que[i] = pii(p1, pos);
else que[i] = pii(p1, p2);
}
rep (i, l, mid) s[i] = -s[i];
vector<pii> vec(0);
rep (i, l, r) vec.emplace_back(s[i], i);
sort(ALL(vec));
for (auto tmp : vec) {
int x = tmp.se;
if (x <= mid) upd(x, 1);
else if (que[x] != pii(-1, -1)) ans += qry(que[x].se) - qry(que[x].fi - 1);
}
rep (i, l, mid) upd(i, -1);
}
int main() {
cin.tie(nullptr) -> ios::sync_with_stdio(false);
cin >> n >> E;
rep (i, 1, n) cin >> a[i];
rep (i, 1, n) cin >> b[i];
solve(1, n);
cout << ans << '\n';
}
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: 20120kb
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:
2368013
result:
wrong answer 1st lines differ - expected: '1846283', found: '2368013'
Subtask #2:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 1036ms
memory: 74164kb
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:
186229807
result:
wrong answer 1st lines differ - expected: '124023429', found: '186229807'
Subtask #3:
score: 0
Wrong Answer
Test #10:
score: 0
Wrong Answer
time: 958ms
memory: 75716kb
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:
53496102460
result:
wrong answer 1st lines differ - expected: '99999500000', found: '53496102460'
Subtask #4:
score: 0
Wrong Answer
Test #14:
score: 0
Wrong Answer
time: 206ms
memory: 31416kb
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:
329808215
result:
wrong answer 1st lines differ - expected: '329807918', found: '329808215'
Subtask #5:
score: 0
Wrong Answer
Test #18:
score: 20
Accepted
time: 409ms
memory: 45276kb
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: 0
Accepted
time: 1082ms
memory: 73564kb
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:
117551199
result:
ok single line: '117551199'
Test #20:
score: 0
Accepted
time: 382ms
memory: 42192kb
input:
318889 580944500 0 53440448 62414510 4444108 16412385 37171101 0 0 65074099 0 0 0 0 0 0 1736666 40422852 25240303 0 0 48581689 0 51050599 0 25918077 0 1579933 0 0 6387116 64336506 0 0 21191911 1157620 0 63412896 28547264 15735514 28842299 56755053 1569652 18413574 0 0 38907260 13487516 3629386 0 0 3...
output:
6426676
result:
ok single line: '6426676'
Test #21:
score: 0
Accepted
time: 819ms
memory: 68152kb
input:
634480 869644773 24926780 0 0 5806548 29345967 0 0 24585164 5082228 0 36723829 0 45565685 38830813 40656683 0 43901325 0 0 24818007 0 9578233 0 29516514 0 45637396 0 17904712 3102583 29421661 0 17144626 0 26616707 20864851 30084372 0 13288472 33594305 10029647 27932498 0 37897745 5476038 0 0 0 0 0 0...
output:
24380270
result:
ok single line: '24380270'
Test #22:
score: -20
Wrong Answer
time: 363ms
memory: 45740kb
input:
343922 773619774 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8425454 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11326 0 0 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:
951568406
result:
wrong answer 1st lines differ - expected: '1735552293', found: '951568406'
Subtask #6:
score: 0
Wrong Answer
Test #24:
score: 0
Wrong Answer
time: 585ms
memory: 56016kb
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:
538176048
result:
wrong answer 1st lines differ - expected: '353280708', found: '538176048'