QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#117606#5441. Quartz CollectionUrgantTeam#WA 1ms42412kbC++234.4kb2023-07-01 20:06:572023-07-01 20:06:59

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-01 20:06:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:42412kb
  • [2023-07-01 20:06:57]
  • 提交

answer

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long double ld;
typedef long long ll;

#define int long long

int const maxn = 1e5 + 5;
int a[maxn], b[maxn], c[maxn], w[2 * maxn], type[maxn], cnt[(1 << 19)], s1[2][(1 << 19)];
int s2[2][3][(1 << 19)];
map < int, int > add;
int my, alice, need;

void merge(int i, int l, int r) {
    cnt[i] = cnt[2 * i + 1] + cnt[2 * i + 2];
    s1[1][i] = s1[1][2 * i + 1];
    s1[0][i] = s1[0][2 * i + 2];
    if (cnt[2 * i + 1] % 2 == 0) {
        s1[1][i] += s1[1][2 * i + 2];
        s1[0][i] += s1[0][2 * i + 2];
    } else {
        s1[1][i] += s1[0][2 * i + 2];
        s1[0][i] += s1[1][2 * i + 2];
    }

    for (int start = 0; start <= 1; start++) {
        for (int need = 1; need <= 2; need++) {
            s2[start][need][i] = s2[start][need][2 * i + 1];
            int nS = start, nN = need;
            nN -= (cnt[2 * i + 1] % 4);
            while (nN <= 0) {
                nN += 2;
                nS ^= 1;
            }
            s2[start][need][i] += s2[nS][nN][2 * i + 2];
        }
    }
}

void update(int i, int l, int r, int lq, int value) {
    if (r - l == 1) {
        cnt[i] = value;
        if (value) s1[1][i] = w[l];
        else s1[1][i] = 0;
        s1[0][i] = 0;
        for (int j = 0; j <= 1; j++) {
            for (int z = 0; z <= 2; z++) {
                s2[j][z][i] = 0;
                if (j == 1 && z && value) s2[j][z][i] = w[l];
            }
        }
    } else {
        int m = (r + l) / 2;
        if (lq < m) update(2 * i + 1, l, m, lq, value);
        else update(2 * i + 2, m, r, lq, value);
        merge(i, l, r);
    }
}

int get1(int i, int l, int r, int lq, int rq) {
    if (lq >= r || l >= rq) return 0;
    if (lq <= l && r <= rq) {
        int ans = s1[my][i];
        my ^= (cnt[i] % 2);
        return ans;
    }
    int m = (r + l) / 2;
    return get1(2 * i + 1, l, m, lq, rq) + get1(2 * i + 2, m, r, lq, rq);
}

int get2(int i, int l, int r, int lq, int rq) {
    if (lq >= r || l >= rq) return 0;
    if (lq <= l && r <= rq) {
        int ans = s2[alice][need][i];
        need -= (cnt[i] % 4);
        while (need <= 0) {
            need += 2;
            alice ^= 1;
        }
        return ans;
    }
    int m = (r + l) / 2;
    return get2(2 * i + 1, l, m, lq, rq) + get2(2 * i + 2, m, r, lq, rq);
}

void adds(int v, int t) {
    update(0, 0, 2 * maxn, v, t);
}

/*void solve(int n) {
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += b[i];
        c[i] = a[i] - b[i];
    }
    sort(c + 1, c + n + 1);
    int ptr = 1;
    while (ptr <= n && c[ptr] <= 0) ptr++;
    for (int i = 0; i < ptr; i += 4) {
        for (int j = i; j <= min(ptr - 1, i + 1); j++) ans += c[j];
    }
    if ((ptr - 1) % 2 == 1) {
        ptr++;
    }
    for (int i = ptr; i <= n; i += 2) ans += c[i];
    cout << ans << '\n';
}*/

main()
{
 	//freopen("input.txt", "r", stdin);
 	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m, t, x, y, sum = 0, cntt = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
        sum += b[i];
        cntt += (a[i] < b[i]);
        w[i] = a[i] - b[i];
    }
    vector < vector < int > > Q;
    for (int i = 1; i <= m; i++) {
        cin >> t >> x >> y;
        w[i + n] = x - y;
        Q.push_back({t, x, y});
    }
    sort(w + 1, w + n + m + 1);
    for (int i = 1; i <= n; i++) {
        type[i] = lower_bound(w + 1, w + n + m + 1, a[i] - b[i]) - w + add[a[i] - b[i]];
        add[a[i] - b[i]]++;
        adds(type[i], 1);
    }

    for (int i = 0; i <= m; i++) {
        if (i) {
            t = Q[i - 1][0], x = Q[i - 1][1], y = Q[i - 1][2];
            sum -= b[t], cntt -= (a[t] < b[t]), adds(type[t], 0);
            a[t] = x, b[t] = y;
            type[t] = lower_bound(w + 1, w + n + m + 1, a[t] - b[t]) - w + add[a[t] - b[t]], add[a[t] - b[t]]++;
            sum += b[t], cntt += (a[t] < b[t]), adds(type[t], 1);
        }
        int pos = lower_bound(w + 1, w + n + m + 1, 0) - w;
        alice = 1, need = 1;
        int ans = get2(0, 0, 2 * maxn, 0, pos) + sum;
        if (cntt % 2 == 0) my = 1, ans += get1(0, 0, 2 * maxn, pos, 2 * maxn);
        else my = 0, ans += get1(0, 0, 2 * maxn, pos, 2 * maxn);
        cout << ans << '\n';
    }
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 42304kb

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: 1ms
memory: 42412kb

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:

5917
5680
5581
5431
5399
5073
5030
5008
5003
5625
5154
5121
5091
5534
5519
5485
4841
4791
5227
5323
5281
4714
5169
5180
5109
4593
5241
5160
5150
5158
5187
4680
4666
4679
4638
4609
4573
4627
4749
4783
5270
4913
4803
4810
5003
4867
4795
4772
5024
4759
4721
4928
4594
4858
4612
4472
4419
4983
4367
4816
...

result:

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