QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#321962#5441. Quartz CollectionduckindogWA 0ms34412kbC++142.0kb2024-02-05 23:34:032024-02-05 23:34:04

Judging History

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

  • [2024-02-05 23:34:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:34412kb
  • [2024-02-05 23:34:03]
  • 提交

answer

//from duckindog wth depression
#include<bits/stdc++.h>

using namespace std;

#define int long long

const int N = 3e5 + 10;
int n, m;
int a[N], b[N];
struct IT {
  //0->11; 1->01; 2->00; 3->10;
  int f4[N << 2][4], f2[N << 2][2], sz[N];
  void update(int s, int l, int r, int i, int x) {
    if (i < l || i > r) return;
    if (l == r) {
      sz[s] += x;
      int val = sz[s] / 4 * 2;
      f4[s][0] = val + sz[s] % 4;        f4[s][0] *= i;
      f4[s][1] = val + (sz[s] % 4 == 2); f4[s][1] *= i;
      f4[s][2] = val;                    f4[s][2] *= i;
      f4[s][3] = val + (sz[s] % 4 >= 1); f4[s][3] *= i;

      for (int j = 0; j < 2; ++j) f2[s][j] = (sz[s] + j) / 2 * i;
      return;
    }
    int mid = l + r >> 1;
    update(s << 1, l, mid, i, x); update(s << 1 | 1, mid + 1, r, i, x);
    sz[s] = sz[s << 1] + sz[s << 1 | 1];
    for (int j = 0; j < 4; ++j) {
      int t = (j + sz[s << 1]) % 4;
      f4[s][t] = f4[s << 1][t] + f4[s << 1 | 1][j];
    }
    for (int j = 0; j < 2; ++j) {
      int t = (j + sz[s << 1]) % 2;
      f2[s][t] = f2[s << 1][t] + f2[s << 1 | 1][j];
    }
  }
} pos, neg;

int sum = 0;
int cal() {
  bool player = neg.sz[1] % 2 == 0;
  return sum + neg.f4[1][3] + pos.f2[1][player];
}

int32_t main() {
  cin.tie(0)->sync_with_stdio(0);

  if (fopen("duck.inp", "r")) {
    freopen("duck.inp", "r", stdin);
    freopen("duck.out", "w", stdout);
  }
  cin >> n >> m;

  for (int i = 1; i <= n; ++i) {
    cin >> a[i] >> b[i];
    sum += b[i];
    if (a[i] - b[i] <= 0) neg.update(1, -1e5, 0, a[i] - b[i], 1);
    else pos.update(1, 1, 1e5, a[i] - b[i], 1);
  }

  cout << cal() << "\n";
  for (int i = 1; i <= m; ++i) {
    int t, x, y; cin >> t >> x >> y;
    sum = sum - b[t] + y;

    if (a[t] - b[t] <= 0) neg.update(1, -1e5, 0, a[t] - b[t], -1);
    else pos.update(1, 1, 1e5, a[t] - b[t], -1);
    a[t] = x; b[t] = y;
    if (a[t] - b[t] <= 0) neg.update(1, -1e5, 0, a[t] - b[t], 1);
    else pos.update(1, 1, 1e5, a[t] - b[t], 1);

    cout << cal() << "\n";
  }

}

詳細信息

Test #1:

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

input:

4 5
2 4
5 7
1 7
2 1
4 5 2
1 6 2
4 4 3
2 1 3
3 6 6

output:

13
14
15
14
10
13

result:

ok 6 numbers

Test #2:

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

input:

1 1
1 1
1 1 1

output:

1
1

result:

ok 2 number(s): "1 1"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 30436kb

input:

100 100
6 7
100 8
5 61
5 75
59 65
51 47
83 37
34 54
87 46
4 26
21 87
12 97
86 68
60 11
62 76
14 83
29 31
91 62
57 80
47 75
85 97
62 77
91 86
14 25
48 77
83 65
39 61
78 77
45 46
90 74
100 91
86 98
55 5
84 42
91 69
100 4
74 98
60 37
75 44
41 12
15 34
36 1
99 16
7 87
36 26
79 42
41 84
17 98
72 16
38 55...

output:

5133
5087
5082
5007
4975
4993
4950
4928
4922
4927
4956
4923
4893
4871
4876
4842
4839
4812
4818
4819
4755
4753
4704
4594
4595
4667
4680
4678
4698
4725
4754
4772
4747
4740
4699
4670
4667
4663
4724
4815
4802
4810
4792
4797
4696
4744
4684
4699
4687
4636
4655
4536
4529
4554
4605
4585
4532
4500
4469
4545
...

result:

wrong answer 1st numbers differ - expected: '5109', found: '5133'