QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#876186#9737. Let's Go! New AdventureMax_s_xaMWA 50ms12280kbC++174.0kb2025-01-30 18:09:482025-01-30 18:09:48

Judging History

This is the latest submission verdict.

  • [2025-01-30 18:09:48]
  • Judged
  • Verdict: WA
  • Time: 50ms
  • Memory: 12280kb
  • [2025-01-30 18:09:48]
  • Submitted

answer

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <random>
#include <ctime>
#include <chrono>
#include <numeric>
#include <iomanip>
#include <cassert>

typedef long long ll;
typedef double lf;
typedef unsigned long long ull;

// #define DEBUG 1
struct IO
{
    #define MAXSIZE (1 << 20)
    #define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
    #if DEBUG
    #else
    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
    #endif
    #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
    #define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')

    template <typename T>
    void Read(T &x)
    {
        #if DEBUG
        std::cin >> x;
        #else
        bool sign = 0; char ch = gc(); x = 0;
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
        if (sign) x = -x;
        #endif
    }
    void Read(char *s)
    {
        #if DEBUG
        std::cin >> s;
        #else
        char ch = gc();
        for (; blank(ch); ch = gc());
        for (; !blank(ch); ch = gc()) *s++ = ch;
        *s = 0;
        #endif
    }
    void Read(char &c) {for (c = gc(); blank(c); c = gc());}

    void Push(const char &c)
    {
        #if DEBUG
        putchar(c);
        #else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
        #endif
    }
    template <typename T>
    void Write(T x)
    {
        if (x < 0) x = -x, Push('-');
        static T sta[35];
        int top = 0;
        do sta[top++] = x % 10, x /= 10; while (x);
        while (top) Push(sta[--top] ^ 48);
    }
    template <typename T>
    void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)

using namespace std;

const int MAXN = 5e5 + 10;

int n, m, c;
ll a[MAXN], b[MAXN], f[MAXN];

struct Line
{
    int l, r, x;
}st[MAXN];
int head, tail;

inline ll Calc(ll x) { return upper_bound(b + 1, b + m + 1, x) - b - 1; }
struct Frac
{
    ll k, a, b;
    bool operator < (const Frac &u) const
    {
        if (k ^ u.k) return k < u.k;
        return (__int128)a * u.b < (__int128)u.a * b;
    }
};
inline Frac F(ll x)
{
    int p = upper_bound(b + 1, b + m + 1, x) - b - 1;
    return Frac{p, x - b[p], p == m ? 1 : b[p + 1] - b[p]};
}
inline bool cmp(int x, int y, int z)
{
    Frac u = F(a[z] - a[y]), v = F(a[z] - a[x]);
    u.k += f[y], v.k += f[x];
    return u < v;
}

int main()
{
    #ifndef DEBUG
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    int T;
    Read(T);
    while (T--)
    {
        Read(n), Read(m), Read(c);
        for (int i = 1; i <= n; i++) Read(a[i]), a[i] += a[i - 1];
        for (int i = 1; i <= m; i++) Read(b[i]), b[i] += b[i - 1];
        f[0] = 0, st[head = tail = 1] = Line{1, n, 0};
        for (int i = 1; i <= n; i++)
        {
            f[i] = f[st[head].x] + Calc(a[i] - a[st[head].x]) - c;
            if (head <= tail && st[head].l <= i) st[head].l = i + 1;
            if (head <= tail && st[head].l > st[head].r) head++;
            while (head <= tail && !cmp(st[tail].x, i, st[tail].l)) tail--;
            if (head > tail) st[++tail] = Line{i + 1, n, i};
            else
            {
                int l = st[tail].l + 1, r = st[tail].r, mid, p = r + 1;
                while (l <= r)
                {
                    mid = l + r >> 1;
                    if (cmp(st[tail].x, i, mid)) l = mid + 1;
                    else p = mid, r = mid - 1;
                }
                st[tail].r = p - 1;
                if (p <= n) st[++tail] = Line{p, n, i};
            }
        }
        cout << f[n] << '\n';
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 12016kb

input:

2
5 4 2
1 0 3 1 2
0 1 1 2
4 5 1
7 16 23 4
1 3 6 20 20

output:

3
6

result:

ok 2 number(s): "3 6"

Test #2:

score: 0
Accepted
time: 6ms
memory: 11800kb

input:

50000
1 1 4
4
4
4 1 4
0 1 2 1
4
3 3 2
0 0 4
0 1 3
1 4 3
4
0 1 1 2
3 1 4
3 1 0
4
3 2 4
1 0 3
1 3
2 2 4
4 0
1 3
2 1 3
1 3
4
4 3 0
0 1 3 0
1 1 2
1 2 2
4
1 3
3 3 1
2 2 0
1 1 2
3 4 1
2 2 0
0 1 1 2
1 1 0
4
4
3 3 3
0 2 2
1 1 2
2 1 2
0 4
4
3 2 4
1 1 2
0 4
4 3 4
0 0 2 2
0 0 4
2 2 1
3 1
1 3
2 3 3
1 3
0 1 3
2 ...

output:

-3
-3
1
1
-3
-2
-2
-2
3
0
2
4
1
0
-1
-2
-1
1
0
-1
2
0
2
-3
0
0
0
1
2
1
0
-2
-1
-3
8
0
1
0
2
-1
-1
-1
0
1
1
0
0
-1
0
1
-1
0
2
0
2
2
1
-2
2
0
-2
-1
0
7
-2
-2
-1
-3
-2
0
2
1
2
-3
2
6
0
6
1
4
3
0
-1
2
0
3
1
-2
-3
1
0
-2
-2
1
-1
8
1
4
1
2
0
2
1
2
0
0
8
3
0
0
2
0
0
-2
4
0
2
2
1
-3
1
5
4
3
1
2
2
0
1
1
1
-1...

result:

ok 50000 numbers

Test #3:

score: 0
Accepted
time: 13ms
memory: 12012kb

input:

50000
6 5 0
2 0 1 3 1 1
0 1 2 2 3
3 7 1
3 0 5
0 0 1 1 1 2 3
8 8 3
3 1 0 0 0 3 0 1
0 0 0 1 1 1 1 4
1 8 3
8
0 0 1 1 1 1 2 2
1 6 1
8
0 0 1 2 2 3
8 2 3
0 3 2 0 1 2 0 0
3 5
4 3 4
2 6 0 0
2 2 4
5 5 1
3 1 2 1 1
1 1 2 2 2
6 6 2
0 1 1 3 3 0
0 0 0 1 2 5
8 2 1
1 1 1 0 1 2 1 1
1 7
2 4 4
0 8
1 1 3 3
7 6 2
3 1 1 ...

output:

12
10
8
5
5
-1
-1
4
12
1
0
8
-1
0
24
6
2
2
0
2
5
10
2
3
4
7
5
6
4
4
5
14
4
5
0
9
-1
5
-1
4
1
3
12
7
15
-2
3
13
2
11
6
10
3
2
3
0
6
4
19
0
3
-2
6
10
13
-1
5
-2
6
1
2
4
0
8
25
2
12
7
6
1
8
3
0
7
14
1
-1
1
14
4
19
2
0
4
2
2
0
-2
0
6
4
13
4
-1
22
2
-1
5
23
2
5
5
3
2
9
13
14
7
4
1
18
3
15
37
2
-2
13
5
0
...

result:

ok 50000 numbers

Test #4:

score: 0
Accepted
time: 16ms
memory: 12280kb

input:

50000
5 4 2
0 16 15 10 9
1 9 10 30
2 3 2
41 9
6 13 31
2 6 1
14 36
2 6 6 7 7 22
4 5 4
3 31 12 4
0 7 7 16 20
1 4 0
50
2 10 18 20
8 1 0
0 1 6 7 12 6 11 7
50
8 7 2
6 2 7 6 1 6 3 19
1 4 6 6 8 10 15
2 2 4
21 29
24 26
6 4 3
2 3 4 28 4 9
3 3 10 34
8 8 1
0 6 1 6 18 18 0 1
1 1 2 3 5 6 14 18
3 5 2
20 13 17
0 0...

output:

2
1
6
1
4
1
5
-2
1
15
3
4
6
9
3
3
3
1
6
4
1
-1
4
11
9
3
8
6
4
7
2
1
2
0
2
-1
0
-2
10
-1
-2
-1
-1
4
2
3
6
5
7
6
8
1
-2
6
4
8
7
4
-1
3
2
1
1
2
0
-3
1
-2
5
6
9
4
1
8
-1
9
7
9
4
7
14
4
6
20
0
2
1
9
3
-3
3
1
0
7
-1
3
0
1
1
3
15
6
-2
0
0
2
12
2
1
1
-1
1
3
-1
-1
4
3
-1
11
2
7
3
10
4
2
5
1
1
0
2
13
0
2
3
-1...

result:

ok 50000 numbers

Test #5:

score: 0
Accepted
time: 16ms
memory: 11880kb

input:

50000
3 6 3
37 24 39
1 6 15 15 16 47
7 8 4
11 23 17 1 32 13 3
1 1 3 4 14 23 26 28
3 4 3
59 10 31
10 12 25 53
5 7 2
18 3 11 25 43
3 6 10 16 19 19 27
7 8 0
10 1 9 46 11 3 20
0 3 4 11 16 17 22 27
6 6 4
5 7 8 65 9 6
4 5 16 19 21 35
4 1 3
13 71 9 7
100
4 6 2
37 63 0 0
3 7 13 15 26 36
7 6 4
3 6 63 16 4 1 ...

output:

3
4
1
5
21
2
-2
4
2
4
7
-1
14
15
2
-1
-2
3
11
1
3
29
-1
1
1
11
0
2
0
6
4
12
2
1
0
-2
-2
0
20
4
2
-1
3
1
-1
1
10
18
1
4
-2
0
3
-3
-1
1
0
-1
0
0
1
4
1
1
2
2
0
0
3
-1
4
6
18
-1
5
2
0
-2
8
1
0
4
0
11
13
7
0
1
3
4
5
6
3
1
0
2
13
-1
-1
1
2
4
2
4
-3
2
6
5
-3
1
0
7
7
0
6
2
0
1
2
0
-1
-2
-3
2
-2
10
16
1
6
5
...

result:

ok 50000 numbers

Test #6:

score: 0
Accepted
time: 20ms
memory: 11880kb

input:

50000
1 6 0
10
0 0 1 1 2 6
6 3 3
0 5 1 2 2 0
3 3 4
2 10 3
10 0
0 0 0 1 1 1 1 2 2 2
5 10 1
0 6 3 1 0
0 0 0 0 0 1 2 2 2 3
9 5 5
2 1 1 1 0 0 0 4 1
0 1 1 4 4
6 1 5
2 0 4 0 4 0
10
6 1 3
5 1 1 0 1 2
10
3 7 0
0 0 10
0 0 0 1 2 3 4
3 7 0
7 1 2
0 0 1 1 2 3 3
8 9 2
0 0 2 1 3 0 1 3
0 0 1 1 1 1 2 2 2
10 5 1
0 1 ...

output:

6
0
7
26
0
-4
-2
13
13
10
5
19
1
1
10
7
-1
4
24
9
2
0
8
5
7
6
0
0
7
8
1
3
2
12
23
-2
13
-3
0
2
1
12
-4
2
1
1
7
0
5
10
0
10
35
6
3
10
28
-2
23
1
6
4
4
-1
3
4
19
4
1
1
-2
0
3
-1
1
18
11
8
0
7
3
18
7
6
-1
1
3
24
-1
5
9
21
-1
1
0
3
0
0
2
0
0
17
7
17
-1
1
39
7
4
6
0
-1
-1
0
2
1
11
-1
1
0
8
-2
6
1
-3
5
5
...

result:

ok 50000 numbers

Test #7:

score: 0
Accepted
time: 34ms
memory: 12008kb

input:

50000
4 4 0
6 3 4 2
1 1 2 11
1 2 7
15
5 10
11 6 0
1 2 0 1 1 2 1 3 0 3 1
0 1 2 2 3 7
1 3 5
15
2 5 8
4 9 1
0 5 5 5
0 0 0 0 1 1 4 4 5
2 5 1
7 8
0 2 3 3 7
13 10 0
0 3 0 1 1 1 2 1 0 4 1 1 0
0 0 0 0 0 0 2 2 4 7
15 1 1
0 0 2 3 2 1 0 2 1 0 1 1 2 0 0
15
15 6 1
0 0 6 1 1 0 1 1 0 2 0 2 1 0 0
0 1 2 2 3 7
6 15 5...

output:

10
-5
22
-2
18
5
82
0
10
25
2
15
13
-3
-3
3
-2
23
12
7
-3
-4
3
-1
1
28
3
0
-3
36
4
3
7
4
59
-1
1
59
1
40
2
15
9
59
2
15
30
59
3
9
26
19
1
-1
74
-1
3
2
-2
7
4
1
-2
0
-1
7
7
6
30
25
2
10
4
14
-3
9
10
7
1
10
8
10
10
19
-4
15
31
9
-3
15
-2
9
15
18
-2
5
10
1
75
15
1
3
11
2
41
7
3
29
27
0
41
-1
30
14
0
7
...

result:

ok 50000 numbers

Test #8:

score: 0
Accepted
time: 38ms
memory: 12144kb

input:

47525
16 2 0
0 0 1 2 0 1 2 0 1 0 1 0 1 0 1 0
4 6
11 3 10
1 0 1 2 2 1 1 2 0 0 0
0 3 7
9 10 7
1 1 0 1 2 1 0 0 4
0 0 0 0 0 1 1 1 1 6
1 14 3
10
0 0 0 0 0 1 1 1 1 1 1 1 1 2
11 14 3
2 1 2 0 0 4 0 1 0 0 0
0 0 0 0 0 0 1 1 1 1 1 1 2 2
4 9 3
9 0 1 0
0 0 0 1 1 1 1 1 5
10 14 5
3 2 2 0 2 0 1 0 0 0
0 0 0 0 0 0 1 ...

output:

2
-7
4
11
43
6
20
105
4
-3
66
34
-5
34
48
3
70
28
0
17
0
22
43
14
35
101
4
-1
4
46
-4
-5
-1
49
-6
3
2
1
54
-3
13
-7
-1
2
6
-6
59
24
1
-2
16
11
61
8
7
6
10
177
7
-8
-3
146
-5
52
-4
46
6
24
6
24
-1
82
10
10
-2
4
50
8
0
46
27
31
31
-2
3
129
80
0
4
5
3
-3
2
1
8
-7
9
82
78
110
7
4
18
73
0
18
106
105
25
7...

result:

ok 47525 numbers

Test #9:

score: 0
Accepted
time: 50ms
memory: 12012kb

input:

47367
20 2 2
0 0 1 0 0 2 1 1 0 4 0 3 1 3 1 0 1 2 0 0
5 15
2 5 5
8 12
2 2 4 4 8
14 5 5
2 1 2 0 3 0 0 7 1 2 0 0 2 0
0 1 4 6 9
3 18 5
3 17 0
0 0 0 0 0 1 1 1 1 1 1 1 1 2 2 2 2 4
11 15 5
0 0 0 1 1 5 4 2 0 7 0
0 0 0 1 1 1 1 1 2 2 2 2 2 2 3
7 17 5
2 3 8 1 2 1 3
0 0 0 0 0 0 0 1 1 1 1 1 2 2 3 3 5
2 13 3
10 1...

output:

0
0
0
15
11
32
14
1
-5
-3
84
77
6
8
0
9
-2
73
3
51
5
-2
111
38
24
4
10
-3
-2
3
16
-1
5
4
47
65
-1
-1
11
-6
1
1
5
31
1
9
1
-8
-1
26
73
68
-2
18
60
5
-1
9
37
31
9
1
20
8
9
13
0
1
1
16
14
6
13
15
13
5
5
-4
8
116
4
15
14
6
0
29
0
8
6
24
14
28
-5
79
0
27
-1
5
40
4
2
6
-6
-3
5
17
1
-2
-6
-2
2
90
17
40
14
...

result:

ok 47367 numbers

Test #10:

score: -100
Wrong Answer
time: 37ms
memory: 12212kb

input:

47439
15 15 6
5 4 5 1 9 1 10 6 2 0 2 2 1 0 2
0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
9 11 4
4 1 7 3 1 30 0 2 2
0 0 0 0 0 1 1 1 1 2 4
16 13 3
1 2 9 4 2 4 4 1 2 1 1 5 0 0 2 12
0 0 0 0 0 0 1 1 1 1 2 2 2
14 3 2
0 9 0 3 2 0 2 1 3 11 1 10 1 7
0 4 6
20 2 1
6 2 1 0 0 3 2 7 2 4 1 2 2 3 1 4 5 1 3 1
1 9
13 17 2
2 4 1 3 ...

output:

44
33
89
3
4
148
11
-1
91
5
96
133
41
65
153
91
8
-1
49
-4
21
15
-2
46
-6
25
-6
37
13
-3
209
104
111
-2
77
0
19
4
2
102
122
11
8
14
-4
89
-2
-6
-1
35
34
15
4
4
-1
32
54
-3
-6
95
24
44
12
12
3
44
3
83
0
22
23
-4
46
-3
-7
77
82
0
7
30
32
12
23
-1
65
-2
13
80
8
56
2
198
68
0
127
99
21
-6
15
78
-2
124
0...

result:

wrong answer 122nd numbers differ - expected: '8', found: '7'