QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#307784#8016. 不休陀螺alpha102220 576ms115752kbC++142.3kb2024-01-19 09:18:362024-01-19 09:18:36

Judging History

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

  • [2024-01-19 09:18:36]
  • 评测
  • 测评结果:20
  • 用时:576ms
  • 内存:115752kb
  • [2024-01-19 09:18:36]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int N = 1e6;

int n, e, a[N + 5], b[N + 5];

struct SegmentTree {
  #define ls (u << 1)
  #define rs (ls | 1)
  struct node {
    int min, tag;
  } seg[N * 4 + 5];
  void apply(int k, int u) { seg[u].min += k, seg[u].tag += k; }
  void pushDown(int u) {
    if (!seg[u].tag) return ;
    apply(seg[u].tag, ls), apply(seg[u].tag, rs), seg[u].tag = 0;
  }
  void pushUp(int u) { seg[u].min = min(seg[ls].min, seg[rs].min); }
  void update(int l, int r, int k, int u, int tl, int tr) {
    if (l <= tl && tr <= r) return apply(k, u);
    int mid = (tl + tr) >> 1;
    pushDown(u);
    if (l <= mid) update(l, r, k, ls, tl, mid);
    if (r > mid) update(l, r, k, rs, mid + 1, tr);
    pushUp(u);
  }
  int query(int u, int tl, int tr) {
    if (seg[u].min >= 0) return tl - 1;
    if (tl == tr) return tl;
    int mid = (tl + tr) >> 1;
    pushDown(u);
    return seg[rs].min < 0 ? query(rs, mid + 1, tr) : query(ls, tl, mid);
  }
} seg;

int stk[N + 5], top;
ll sum[N + 5], ind[N + 5];
int len, sid[N + 5];
vector<pair<int, int>> qry[N + 5];

struct BinaryIndexedTree {
  int c[N + 5];
  void update(int x, int k) { for (; x <= len; x += x & -x) c[x] += k; }
  int query(int x) { int ret = 0; for (; x; x &= x - 1) ret += c[x]; return ret;}
} bit;

ll ans;

int main() {
  scanf("%d%d", &n, &e);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1; i <= n; ++i) scanf("%d", b + i), ind[i] = sum[i] = sum[i - 1] + b[i] - a[i];
  sort(ind, ind + n + 1), len = unique(ind, ind + n + 1) - ind;
  for (int i = 0; i <= n; ++i) sid[i] = lower_bound(ind, ind + len, sum[i]) - ind + 1;
  seg.update(1, n, e, 1, 1, n);
  for (int i = 1; i <= n; ++i) {
    for (; top && min(a[i], b[i]) >= min(a[stk[top]], b[stk[top]]); --top) seg.update(stk[top - 1] + 1, stk[top], min(a[stk[top]], b[stk[top]]), 1, 1, n);
    seg.update(stk[top] + 1, i, -min(a[i], b[i]), 1, 1, n), stk[++top] = i;
    seg.update(1, i, min(b[i] - a[i], 0), 1, 1, n);
    qry[min(seg.query(1, 1, n), i)].emplace_back(sid[i], -1), qry[i].emplace_back(sid[i], 1);
  }
  for (int i = 1; i <= n; ++i) {
    bit.update(sid[i - 1], 1);
    for (auto [x, w]: qry[i]) ans += bit.query(x) * w;
  }
  printf("%lld\n", ans);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

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:

1933757

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 576ms
memory: 104428kb

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:

773708420

result:

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

Subtask #3:

score: 10
Accepted

Test #10:

score: 10
Accepted
time: 553ms
memory: 115752kb

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:

99999500000

result:

ok single line: '99999500000'

Test #11:

score: 0
Accepted
time: 458ms
memory: 106368kb

input:

829382 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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:

68786703753

result:

ok single line: '68786703753'

Test #12:

score: 0
Accepted
time: 409ms
memory: 100044kb

input:

715382 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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:

51176496753

result:

ok single line: '51176496753'

Test #13:

score: 0
Accepted
time: 115ms
memory: 55088kb

input:

212234 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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:

4504051185

result:

ok single line: '4504051185'

Subtask #4:

score: 10
Accepted

Test #14:

score: 10
Accepted
time: 89ms
memory: 49096kb

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:

329807918

result:

ok single line: '329807918'

Test #15:

score: 0
Accepted
time: 213ms
memory: 73736kb

input:

402729 5000
0 1 0 0 0 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 0 1 1 0 1 1 1 1 1 1 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 1 1 1 1 0 0 1 0 0 1 0 0 1 1 1 1 0 0 1 0 0 1 1 0 0 1 1 0 0 1 1 1 0 1 1 0 0 0 1 0 1 1 0 1 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 1 1 1 0 1 1 0 1 ...

output:

4060615624

result:

ok single line: '4060615624'

Test #16:

score: 0
Accepted
time: 512ms
memory: 108160kb

input:

942956 10000
1 0 1 1 1 0 1 0 1 1 1 0 1 0 0 1 0 0 1 0 0 0 0 0 1 1 0 1 1 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 1 0 1 1 0 0 1 1 1 0 0 0 1 0 0 1 0 1 0 1 0 1 0 0 0 1 1 0 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 0 0 0 0 0 0 1 1 1 0 1 0 1 1 1 0 1 1 1...

output:

20162916507

result:

ok single line: '20162916507'

Test #17:

score: 0
Accepted
time: 424ms
memory: 102652kb

input:

802501 1000
1 1 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 1 1 0 1 0 0 0 1 0 0 0 0 0 1 1 0 1 1 0 1 0 0 0 1 1 0 1 1 1 1 0 1 0 0 1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 1 1 1 0 1 0 0 0 1 1 0 1 0 1 0 1 1 0 1 0 0 1 1 1 1 0 0 1 1 0 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 0 0 1 1 0 0 1 1 0 1 1 1 1 1 0 0 0 1 0 0 ...

output:

1660083853

result:

ok single line: '1660083853'

Subtask #5:

score: 0
Wrong Answer

Test #18:

score: 0
Wrong Answer
time: 217ms
memory: 71512kb

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:

733706027

result:

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

Subtask #6:

score: 0
Wrong Answer

Test #24:

score: 0
Wrong Answer
time: 337ms
memory: 77008kb

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:

770110145

result:

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