QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#535707#7622. Yet Another CoffeeFoedere0WA 0ms7704kbC++232.6kb2024-08-28 13:44:092024-08-28 13:44:10

Judging History

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

  • [2024-08-28 13:44:10]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:7704kb
  • [2024-08-28 13:44:09]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef pair<int, int> PII;
const int N = 1000010;
int mod = 998244353;
int n, m;
PII d[N];
int a[N];
int lz[N];
void pushup(int p)
{
    d[p].first = min(d[2 * p].first, d[2 * p + 1].first);
    if (d[2 * p].first < d[2 * p + 1].first)
    {
        d[p].second = d[2 * p].second;
    }
    else
    {
        d[p].second = d[2 * p + 1].second;
    }
}
void updown(int p)
{
    if (lz[p])
    {
        d[p * 2].first += lz[p];
        d[p * 2 + 1].first += lz[p];
        lz[p * 2] += lz[p];
        lz[2 * p + 1] += lz[p];
        lz[p] = 0;
    }
}
void build(int s, int t, int p)
{
    lz[p] = 0;
    d[p].first = 0;
    d[p].second = 0;
    if (s == t)
    {
        d[p].first = a[s];
        d[p].second = s;
        return;
    }
    int mid = (s + t) / 2;
    build(s, mid, p * 2);
    build(mid + 1, t, 2 * p + 1);
    pushup(p);
}
void update(int l, int r, int c, int s, int t, int p)
{
    if (s >= l && t <= r)
    {
        d[p].first += c;
        lz[p] += c;
        return;
    }
    updown(p);
    int mid = (s + t) / 2;
    if (l <= mid)
    {
        update(l, r, c, s, mid, p * 2);
    }
    if (r > mid)
    {
        update(l, r, c, mid + 1, t, 2 * p + 1);
    }
    pushup(p);
}
PII getid(int l, int r, int s, int t, int p)
{
    if (l <= s && t <= r)
    {
        return d[p];
    }
    int mid = (s + t) / 2;
    updown(p);
    PII tt;
    tt.first = 1e18;
    if (l <= mid)
    {
        if (tt.first > getid(l, r, s, mid, p * 2).first)
        {
            tt = getid(l, r, s, mid, p * 2);
        }
    }
    if (r > mid)
    {
        if (tt.first > getid(l, r, mid + 1, t, 2 * p + 1).first)
        {
            tt = getid(l, r, mid + 1, t, 2 * p + 1);
        }
    }
    // cout << " " << tt.second << endl;
    return tt;
}
void solve()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    build(1, n, 1);
    // cout << m << endl;
    while (m--)
    {
        int r, w;
        cin >> r >> w;
        // cout << r << " " << w << endl;
        update(1, r, -w, 1, n, 1);
        PII t = getid(1, r, 1, n, 1);
        // cout << t.second << endl;
        a[t.second] -= w;
    }
    sort(a + 1, a + 1 + n);
    int sum = 0;
    for (int i = 1; i <= n; i++)
    {
        sum += a[i];
        cout << sum << " ";
    }
    cout << endl;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 7704kb

input:

5
10 14
17 37 59 65 53 73 68 177 160 111
10 177
5 193
2 30
3 63
2 339
3 263
5 178
2 190
9 23
10 328
10 200
9 8
3 391
6 230
12 9
152 306 86 88 324 59 18 14 42 260 304 55
3 50
2 170
1 252
7 811
1 713
7 215
10 201
4 926
8 319
19 20
182 74 180 201 326 243 195 31 170 263 284 233 48 166 272 281 179 116 31...

output:

-2596 -2559 -2506 -2447 -2382 -2314 -2241 -2130 -1970 -1793 
-3455 -3441 -3423 -3387 -3345 -3290 -3231 -3143 -2883 -2579 -2273 -1949 
-3325 -5635 -6422 -6374 -6258 -6092 -5922 -5743 -5563 -5368 -5167 -4934 -4691 -4428 -4156 -3875 -3591 -3272 -2946 
-3219 -2987 -2572 -2140 -1707 -1238 -768 -274 243 1...

result:

wrong answer 11th numbers differ - expected: '-3505', found: '-3455'