QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#661533#7787. Maximum Ratinghbhz_zcyWA 1ms7964kbC++142.6kb2024-10-20 16:41:112024-10-20 16:41:15

Judging History

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

  • [2024-10-20 16:41:15]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7964kb
  • [2024-10-20 16:41:11]
  • 提交

answer

//g++ k.cpp -o k -g -std=c++14 -O0 -Wall -fsanitize=undefined
#include <iostream>
#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std;
int qd()
{
    int rt = 0, ng = 0;
    char c = getchar();
    while (c < '0' || c > '9')
        ng ^= (c == '-'), c = getchar();
    while ('0' <= c && c <= '9')
        rt = (rt << 3) + (rt << 1) + c - 48, c = getchar();
    return ng ? -rt : rt;
}
const int maxn = 4e5 + 10;
int N, Q, a[maxn], ls[maxn], lstop = 0, qt[maxn][2];
LL nsum;
struct node
{
    int xv, cnt;
    LL v;
} f[maxn << 4];
void pushup(int t) { f[t].v = f[t << 1].v + f[t << 1 | 1].v, f[t].cnt = f[t << 1].cnt + f[t << 1 | 1].cnt; }
void build(int t, int l, int r)
{
    	// printf("%d:%d %d\n",t,l,r);
    if(l>r)  return;
    if (l == r)
    {
        f[t].xv = ls[l];
        return;
    }
    int m = (l + r) >> 1;
    build(t << 1, l, m), build(t << 1 | 1, m + 1, r);
    f[t].xv = max(f[t << 1].xv, f[t << 1 | 1].xv);
}
void change(int t, int l, int r, int v, int num)
{
    if(l>r)  return;
    if (l == r)
    {
        f[t].v += 1LL * ls[l] * num, f[t].cnt += num;
        return;
    }
    int m = (l + r) >> 1;
    f[t << 1].xv >= v ? change(t << 1, l, m, v, num) : change(t << 1 | 1, m + 1, r, v, num);
    pushup(t);
}
int ask(int t, int l, int r, LL v)
{
    if(l>r)  return 0;
    if (v >= f[t].v)
        return f[t].cnt;
    if (l == r)
        return ls[l] ? v / ls[l] : 0;
    int m = (l + r) >> 1;
    return v <= f[t].v ? ask(t << 1, l, m, v) : f[t << 1].cnt + ask(t << 1 | 1, m + 1, r, v - f[t << 1].v);
}
int main()
{
    // freopen("test.in","r",stdin);
    N = qd(), Q = qd();
    for (int i = 1; i <= N; i++)
    {
        a[i] = qd();
        if (a[i] <= 0)
            nsum += a[i];
        else
            ls[++lstop] = a[i];
    }
    for (int i = 1; i <= Q; i++)
    {
        qt[i][0] = qd(), qt[i][1] = qd();
        if (qt[i][1] > 0)
            ls[++lstop] = qt[i][1];
    }
    sort(ls + 1, ls + lstop + 1);
    lstop = unique(ls + 1, ls + lstop + 1) - ls - 1; //printf("%d %d\n\n",lstop,nsum);
    build(1, 1, lstop);
    for (int i = 1; i <= N; i++)
        change(1, 1, lstop, a[i], 1);
    for (int i = 1; i <= Q; i++)
    {
        int t = qt[i][0], x = qt[i][1];
        if (a[t] <= 0)
            nsum -= a[t];
        else
            change(1, 1, lstop, a[t], -1);
        if (x <= 0)
            nsum += x;
        else
            change(1, 1, lstop, x, 1);
        a[t] = x;
         printf("%d\n", ask(1, 1, lstop, -nsum) + 1);
    }
    // while(1);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7924kb

input:

3 5
1 2 3
3 4
2 -2
1 -3
3 1
2 1

output:

1
2
2
2
3

result:

ok 5 number(s): "1 2 2 2 3"

Test #2:

score: 0
Accepted
time: 1ms
memory: 7908kb

input:

3 5
1 2 3
3 4
2 -2
1 3
3 1
2 1

output:

1
2
1
2
1

result:

ok 5 number(s): "1 2 1 2 1"

Test #3:

score: 0
Accepted
time: 1ms
memory: 7964kb

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 1ms
memory: 7948kb

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 1ms
memory: 5928kb

input:

1000 1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

946
65
252
410
915
592
983
487
343
899
809
432
586
587
139
464
804
84
476
699
504
149
579
352
375
856
545
166
140
657
568
509
275
710
873
430
537
879
301
1
298
970
923
510
984
642
55
879
941
344
464
788
917
994
571
610
491
442
926
101
986
840
624
613
425
345
816
423
275
221
317
113
386
116
469
260
4...

result:

ok 1000 numbers

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 7888kb

input:

1000 1000
1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000...

output:

1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
1000
...

result:

wrong answer 1st numbers differ - expected: '500', found: '1000'