QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#731839#8951. 澡堂5k_sync_closer0 0ms26588kbC++143.4kb2024-11-10 11:46:362024-11-10 11:46:40

Judging History

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

  • [2024-11-10 11:46:40]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:26588kb
  • [2024-11-10 11:46:36]
  • 提交

answer

#include <cstdio>
#include <algorithm>
#define int long long
using namespace std;
int n, m, q, T, Z, a[1000050];
struct S
{
    int n, l, f[1050][23], g[1050][23], p[1000050], b[1000050], s[1000050];
    void I()
    {
        for (int i = 0; i <= n + 1; ++i)
            for (int j = 0; j <= 21; ++j)
                f[i][j] = n + 1;
        for (int i = 0; i <= n; ++i)
        {
            b[i] = i * T - a[p[i]], Z += b[i];
            while (l && b[i] < b[s[l]])
                f[s[l]][0] = i, g[s[l]][0] = b[s[l]] * (i - s[l]), --l;
            s[++l] = i;
        }
        b[n + 1] = -1e18;
        for (int j = 1; 1 << j <= n; ++j)
            for (int i = 0; i <= n; ++i)
                f[i][j] = f[f[i][j - 1]][j - 1], g[i][j] = g[i][j - 1] + g[f[i][j - 1]][j - 1];
    }
    int L(int l) { return lower_bound(p + 1, p + n + 1, l) - p; }
    int R(int r) { return upper_bound(p + 1, p + n + 1, r) - p - 1; }
    void F(int l, int r, int d, int &u, int &o, int &c, int &z)
    {
        l = L(l), r = R(r), c += r - l + 1;
        int v = l;
        if (b[v] - d * T >= o)
        {
            for (int j = __lg(n); j >= 0; --j)
                if (b[f[v][j]] - d * T >= o)
                    v = f[v][j];
            v = f[v][0];
        }
        if (v <= r)
        {
            z += o * (v - d - u), u = v;
            for (int j = __lg(n); j >= 0; --j)
                if (f[u][j] <= r)
                    z += g[u][j] - d * T * (f[u][j] - u), u = f[u][j];
            o = b[u] - d * T, u -= d;
        }
    }
} P[6];
signed main()
{
    scanf("%lld%lld%lld%lld", &n, &m, &q, &T), a[0] = -1e15;
    for (int i = 1; i <= n; ++i)
        scanf("%lld", a + i);
    for (int i = 1; i <= m; ++i)
    {
        for (int j = i; j <= n; j += m)
            P[i].p[++P[i].n] = j;
        P[i].I();
    }
    for (int i = 0, x, w; i < q; ++i)
    {
        scanf("%lld%lld", &x, &w);
        int y = upper_bound(a + 1, a + n + 1, w) - a - 1, _ = w;
        if (x <= y)
        {
            int s = 0;
            for (int j = 1; j <= m; ++j)
            {
                int u = 0, o = P[j].b[0], c = 0, z = 0;
                P[j].F(1, x - 1, 0, u, o, c, z);
                P[j % m + 1].F(x + 1, y, P[j % m + 1].L(x + 1) - c - 1, u, o, c, z);
                if ((x - 1) % m + 1 == j)
                {
                    ++c;
                    if (c * T - w < o)
                        z += o * (c - u), u = c, o = c * T - w;
                }
                P[j].F(y + 1, n, P[j].L(y + 1) - c - 1, u, o, c, z);
                z += o * (P[j].n - u + 1);
                s += z;
            }
            printf("%lld\n", Z + a[x] - _ - s);
        }
        else
        {
            int s = 0;
            for (int j = 1; j <= m; ++j)
            {
                int u = 0, o = P[j].b[0], c = 0, z = 0;
                P[j].F(1, y, 0, u, o, c, z);
                if ((x - 1) % m + 1 == j)
                {
                    ++c;
                    if (c * T - w < o)
                        z += o * (c - u), u = c, o = c * T - w;
                }
                P[j % m + 1].F(y + 1, x - 1, P[j % m + 1].L(y + 1) - c - 1, u, o, c, z);
                P[j].F(x + 1, n, P[j].L(x + 1) - c - 1, u, o, c, z);
                z += o * (P[j].n - u + 1);
                s += z;
            }
            printf("%lld\n", Z + a[x] - _ - s);
        }
    }
    return 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: 0ms
memory: 26588kb

input:

1000 5 1000 1969617
59993 133807 154199 240894 438118 483699 540258 892751 922552 1049554 1092961 1153394 1287745 1315664 1372758 1550447 1634967 1817853 1825455 2023239 2064188 2117896 2250036 2453036 2492474 2794776 2917935 3047993 3153958 3163156 3237767 3443614 3664074 3716235 3801008 3822067 40...

output:

145473107761
145400375427
145403718605
145444938654
145438908460
145436948885
145405212826
145454120934
145460664260
145458475414
145433391640
145459823384
145401672860
145361079139
145486629489
145451768180
145426177956
145368877047
145384484360
145392373415
145514759762
145437334277
145471143810
1...

result:

wrong answer 142nd lines differ - expected: '145498361799', found: '145515595199'

Subtask #2:

score: 0
Runtime Error

Test #6:

score: 0
Runtime Error

input:

1000000 1 100000 1165
83 197 266 277 299 529 538 601 629 760 792 1081 1208 1211 1387 1726 1873 1932 2198 2437 2448 2584 2715 2813 3113 3169 3207 3386 3934 4013 4032 4057 4137 4213 4396 4666 4754 4786 4856 4917 4966 5054 5124 5151 5196 5505 5548 5583 5730 5763 6031 6161 6169 6372 6446 6517 6712 6744 ...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Runtime Error

Test #36:

score: 0
Runtime Error

input:

1000000 5 100000 1887
112 168 223 393 535 558 577 631 631 678 682 1043 1099 1268 1337 1396 1437 1472 1510 1587 1804 1984 2013 2290 2294 2392 2474 2547 2694 2717 2742 2841 2880 2906 2985 3030 3047 3064 3108 3275 3375 3440 3451 3488 3950 3957 3963 4047 4086 4335 4378 4448 4490 4544 4622 4864 4875 4897...

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #3:

0%