QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#591418#7787. Maximum Ratingsolar_express#WA 1ms3728kbC++231.3kb2024-09-26 15:51:452024-09-26 15:51:47

Judging History

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

  • [2024-09-26 15:51:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3728kb
  • [2024-09-26 15:51:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int n, q;
int64_t qt;
const int N = 2e5+5;
int a[N];

map<int, long> sum, cnt;
map<int, int> c2;
int cntp;
const int LIM = 1e9+7;

void fwmod(map<int, long> &c, int x, long v) {
  for (; x < LIM; x += x & -x) c[x] += v;
}

long fwget(map<int, long> &c, int x) {
  long ret = 0;
  for (; x; x -= x & -x) ret += c[x];
  return ret;
}

void rem(int x) {
  --cntp;
  ++c2[x];
  fwmod(cnt, x, -1);
  fwmod(sum, x, -x);
}

void ins(int x) {
  ++cntp;
  --c2[x];
  fwmod(cnt, x, 1);
  fwmod(sum, x, x);
}

int qry() {
  int x = 0;
  long xs = 0;
  for (int i = 29; i >= 0; --i) if ((x+(1<<i)<LIM) && xs+sum[x+(1<<i)] < qt) {
    x += 1<<i;
  }
  // cout << "dbg" << x << '\n';
  if (x > LIM) {
    return cntp+1;
  }
  int res = fwget(cnt, x);
  int nn = cnt[x+1];
  res += (qt-xs) / (x+1);
  return res+1;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (a[i] <= 0) qt -= a[i];
    else ins(a[i]);
  }
  while (q--) {
    int x, v;
    cin >> x >> v;
    if (a[x] <= 0) qt += a[x];
    else rem(a[x]);
    a[x] = v;
    if (v <= 0) qt -= v;
    else ins(v);
    cout << qry() << '\n';
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0ms
memory: 3648kb

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: 0ms
memory: 3648kb

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3580kb

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: 3724kb

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:

999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
...

result:

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