QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725916#9528. New Energy Vehicleyeah14WA 94ms90700kbC++174.7kb2024-11-08 20:37:562024-11-08 20:37:59

Judging History

This is the latest submission verdict.

  • [2024-11-08 20:37:59]
  • Judged
  • Verdict: WA
  • Time: 94ms
  • Memory: 90700kb
  • [2024-11-08 20:37:56]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ull long long
#define PII  pair<int ,int>
const int INF = 0x3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;
int fp(int a, int x, int mod) {
    int ans = 1;
    while (x) {
        if (x & 1)ans *= a;
        ans %= mod;
        a *= a;
        a %= mod;
        x >>= 1;
    }
    return ans;
}
bool check1(int n) {
    for (int i = 2; i <= n / 2; i++) {
        if (n % i == 0)return 0;
    }
    return 1;
}
struct tree {
    int sum, pre, suf;
    int tag = -1;
};
tree tr[4 * N];
int ls(int p) { return p << 1; }
int rs(int p) { return (p << 1) + 1; }
int history[N], tot = 0;
void add_tag(int p, int d, int pl, int pr) {
    tr[p].tag += d;
    tr[p].sum += d * (pr - pl + 1);
}
void push_down(int p, int len) {
    if (tr[p].tag != -1) {
        tr[ls(p)].tag = tr[rs(p)].tag = tr[p].tag;
        tr[ls(p)].pre = tr[ls(p)].sum = (tr[p].tag == 0) ? 0 : (len - (len >> 1));
        tr[rs(p)].pre = tr[rs(p)].sum = (tr[p].tag == 0) ? 0 : (len >> 1);
        tr[p].tag = -1;
    }
}
void push_up(int p, int len) {
    tr[p].pre = tr[ls(p)].pre;
    tr[p].suf = tr[rs(p)].suf;
    if (tr[ls(p)].pre == (len - (len >> 1))) {
        tr[p].pre = tr[ls(p)].pre + tr[rs(p)].pre;
    }
    if (tr[rs(p)].suf == (len >> 1)) {
        tr[p].suf = tr[rs(p)].suf + tr[ls(p)].suf;
    }
}
void build(int pl, int pr, int p) {
    tr[p].tag = -1;
    if (pl == pr) {
        tr[p].sum = tr[p].pre = tr[p].suf = 1;
        return;
    }
    int mid = (pl + pr) >> 1;
    build(pl, mid, ls(p));
    build(mid + 1, pr, rs(p));
    push_up(p, pr - pl + 1);
}

void update(int L, int R, int c, int p, int pl, int pr) {
    if (L <= pl && R >= pr) {
        tr[p].pre = tr[p].suf = tr[p].sum = (c == 0) ? 0 : pr - pl + 1;
        tr[p].tag = c;
        return;
    }
    int mid = (pl + pr) >> 1;
    if (L <= mid)update(L, R, c, ls(p), pl, mid);
    if (R > mid)update(L, R, c, rs(p), mid + 1, pr);
    //else update(x, c, rs(p), mid + 1, pr);
    push_up(p, pr - pl + 1);
}

int query(int len, int p, int pl, int pr) {
    if (pl == pr)return pl;
    int mid = (pl + pr) >> 1;
    if (len <= tr[ls(p)].sum) {
        if (len <= tr[p].pre)return pl;
        else return query(len, ls(p), pl, mid);
    }
    else if (len <= tr[rs(p)].pre + tr[ls(p)].suf) {
        return mid - tr[ls(p)].suf + 1;
    }
    else if (len <= tr[rs(p)].sum) {
        if (len <= tr[rs(p)].pre)return pl;
        else return query(len, rs(p), mid + 1, pr);
    }

}



struct strc {
    int c, nxt, id;
    bool operator<(const strc a)const {
        return nxt > a.nxt;
    }
};
int a[N];
queue<int>p[N];
PII b[N];
priority_queue<strc>q1, q2;
void solve() {
    int n, m;
    cin >> n >> m;
    int sum = 0;
    int ans = 0;

    while (!q1.empty())q1.pop();
    while (!q2.empty())q2.pop();
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        while (!p[i].empty())p[i].pop();
    }
    for (int i = 1; i <= m; i++) {
        cin >> b[i].first >> b[i].second;
    }
    sort(b + 1, b + 1 + m);
    b[m + 1] = { INF,INF };
    for (int i = 1; i <= m; i++) {
        p[b[i].second].push(i);
    }
    for (int i = 1; i <= n; i++) {
        p[i].push(m + 1);
        q1.push({ a[i],p[i].front(),i});
        p[i].pop();
    }
    int s = 0;
    for (int i = 1; i <= m; i++) {
        while (!q1.empty() && s < b[i].first) {
            strc tt = q1.top(); q1.pop();
            if (s + tt.c>b[i].first) {
                tt.c = tt.c - (b[i].first - s);
                q1.push(tt);
                s = b[i].first;
            }
            else {
                s += tt.c;
                if (p[tt.id].empty())continue;

                tt.nxt = p[tt.id].front();
                tt.c = a[tt.id];
                p[tt.id].pop();
                q2.push(tt);
            }
        }
        strc tt;
        if (s < b[i].first)break;
        if (!q1.empty()) tt = q1.top();
        else tt = { 0,0,0 };
        if (tt.id == b[i].second) {
            q1.pop();
            tt.nxt = p[tt.id].front();
            tt.c = a[tt.id];
            p[tt.id].pop();
            q1.push(tt);
        }
        else {
            q1.push(q2.top());
            q2.pop();
        }
    }
    while (!q1.empty()) {
        s += q1.top().c;
        q1.pop();
    }
    cout << s << endl;
}

//&&(((sum[n]+k)%mid==0)||(sum[n]/mid!=(sum[n]+k)/mid)||(mid-(sum[n]%mid)>=k))
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    //while (t--) {
    //    //if (k == 100000)cout << k - t + 1 << " ";
    //    solve();
    //}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 86296kb

input:

2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1

output:

12
9

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 11ms
memory: 85036kb

input:

6
3 2
2 2 2
6 1
7 1
2 2
3 3
2 1
6 2
2 3
2 2
5 1
7 2
9 1
2 2
3 3
2 1
6 2
1 1
999999999
1000000000 1
1 1
1000000000
1000000000 1

output:

9
11
4
11
999999999
2000000000

result:

ok 6 lines

Test #3:

score: -100
Wrong Answer
time: 94ms
memory: 90700kb

input:

10
230 8042
599 1039 69 1011 1366 824 14117 1523 806 5002 332 55 3769 996 359 1040 255 1135 3454 3609 6358 2509 3695 8785 3890 1304 3394 14611 33 89 2245 508 22 1043 10411 628 1279 714 903 585 7413 5099 845 148 4689 2110 8683 1613 143 3263 2599 110 244 3297 4742 1571 425 1822 15692 572 9397 328 1691...

output:

1543020
1578939
1526016
1527381
1547404
1564631
1051423
1548178
1114655
1072438

result:

wrong answer 7th lines differ - expected: '1051729', found: '1051423'