QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#119757#6630. Triangle Collectionbatrr#0 17ms5756kbC++231.9kb2023-07-05 17:23:572024-07-04 00:18:36

Judging History

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

  • [2024-07-04 00:18:36]
  • 评测
  • 测评结果:0
  • 用时:17ms
  • 内存:5756kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-05 17:23:57]
  • 提交

answer

#include <bits/stdc++.h>

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = 300500, inf = 1e9, mod = 998244353;
const ll INF = 1e18;

int sum(int a, int b) {
    a += b;
    if (a >= mod)
        a -= mod;
    return a;
}

int sub(int a, int b) {
    a -= b;
    if (a < 0)
        a += mod;
    return a;
}

int mult(int a, int b) {
    return 1ll * a * b % mod;
}

int bp(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = mult(res, a);
        a = mult(a, a);
        b >>= 1;
    }
    return res;
}

int inv(int x) {
    return bp(x, mod - 2);
}

int n, q;
ll a[N], s;
ll b[N];

/*
 1 0 1
 2 1 0
 3 0 0
 4 2 0
 5 2 1
 6 3 0
 */
void solve() {
    cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        s += a[i];
    }
    while (q--) {
        int p, x;
        {
            cin >> p >> x;
            s += x;
            a[p] += x;
        }
        ll ans = 0;
        for (int i = 1; i <= n; i++)
            b[i] = a[i];
        for (int i = n, j = n; i >= 1; i--) {
            while (b[i] >= 2) {
                j = min(j, i + i - 1);
                while (j > i && b[j] == 0)
                    j--;
                b[i] -= 2;
                b[j] -= 1;
                ans++;
            }
            while(b[j] >= 3){
                b[j] -= 3;
                ans++;
            }
        }
        cout << ans << "\n";
    }
}

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    int t = 1;
//    cin >> t;
    for (int i = 1; i <= t; i++) {
//        cout << "Case #" << i << endl;
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5724kb

input:

1 23
1485
1 -12
1 -30
1 -20
1 6
1 24
1 5
1 31
1 14
1 -34
1 -22
1 -45
1 37
1 46
1 9
1 22
1 -9
1 9
1 -46
1 -47
1 39
1 36
1 -36
1 50

output:

491
481
474
476
484
486
496
501
490
482
467
480
495
498
505
502
505
490
474
487
499
487
504

result:

wrong answer 9th numbers differ - expected: '489', found: '490'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #28:

score: 0
Wrong Answer
time: 7ms
memory: 5684kb

input:

1999 2000
1 1 1 1 0 2 0 2 1 0 2 1 2 2 2 1 2 0 0 1 2 2 0 1 0 1 0 2 0 0 2 1 1 1 1 0 1 2 1 2 1 1 1 1 1 0 2 2 0 2 1 1 2 0 0 2 0 0 2 1 2 0 0 1 1 2 0 2 2 2 1 2 0 2 1 2 0 1 2 2 2 1 1 2 1 1 1 1 0 0 1 1 0 1 2 1 0 0 2 0 2 2 2 0 1 1 2 0 0 1 0 0 2 1 2 1 2 0 1 1 2 2 0 0 1 2 2 1 2 1 2 2 2 0 0 1 1 2 1 1 2 2 2 2 2 ...

output:

660
660
660
661
661
661
661
660
660
660
660
661
662
662
663
663
662
661
662
662
661
660
661
660
660
660
661
661
661
661
662
661
661
660
661
660
659
658
658
659
659
658
659
660
660
660
660
660
660
659
659
659
659
659
659
659
659
660
659
658
658
658
658
657
657
657
658
657
656
657
657
657
656
656
655
...

result:

wrong answer 615th numbers differ - expected: '660', found: '661'

Subtask #4:

score: 0
Wrong Answer

Test #35:

score: 0
Wrong Answer
time: 17ms
memory: 5756kb

input:

2000 1999
0 1 0 3 0 1 0 0 0 0 0 0 0 2 0 0 0 0 3 1 1 0 2 0 0 3 0 0 0 0 0 4 0 0 1 0 1 0 0 0 0 1 2 1 0 0 0 0 7 0 1 3 1 0 1 1 0 3 2 1 0 1 1 3 3 1 0 2 0 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 1 2 3 0 1 0 3 3 0 0 0 0 1 0 1 2 0 0 2 2 0 1 2 1 2 0 0 0 1 1 0 1 2 0 0 0 0 2 0 5 0 0 0 0 0 1 0 0 2 0 1 2 0 1 0 0 0 2 0 ...

output:

670
670
670
670
670
670
670
670
670
671
671
671
671
672
672
672
671
671
671
672
672
672
671
671
670
670
669
669
668
668
669
669
669
669
669
669
668
668
668
668
667
667
666
666
665
665
665
665
665
665
665
665
665
665
665
665
665
665
665
665
665
666
666
667
667
668
668
668
668
668
668
668
668
667
667
...

result:

wrong answer 1st numbers differ - expected: '666', found: '670'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%