QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#712879#9528. New Energy Vehicle0x3fffffffCompile Error//C++234.9kb2024-11-05 17:22:252024-11-05 17:22:26

Judging History

This is the latest submission verdict.

  • [2024-11-05 17:22:26]
  • Judged
  • [2024-11-05 17:22:25]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define int long long
using PII = pair<int, int>;


void solve() {
    int n, m;cin >> n >> m;
    vector<int>a(n + 1);
    for (int i = 1;i <= n;i++) {
        cin >> a[i];
    }
    priority_queue<PII, vector<PII>, greater<PII>>q;
    vector<int>x(m + 1), t(m + 1), vis(n + 1);
    vector<int>nxt(m + 4, m + 1), p(n + 1, m + 1);
    for (int i = 1;i <= m;i++) {
        cin >> x[i] >> t[i];
        q.emplace(i, t[i]);
        vis[t[i]] = 1;
    }
    auto b = a;
    // for (int i = 1;i <= m;i++) {
    //     cout << nxt[t[i]] << " ";
    // }
    // cout << "\n";return;
    for (int i = m;i >= 1;i--) {
        nxt[i] = p[t[i]];
        p[t[i]] = i;
    }
    // for (int i = 1;i <= m;i++) {
    //     cout << nxt[i] << " ";
    // }
    // cout << "\n";return;

    for (int i = 1;i <= n;i++) {
        if (!vis[i])q.emplace(m + 1, i);
    }

    auto look = [&]() {
        auto tmp = q;
        while (tmp.size()) {
            auto [xx, y] = tmp.top();
            tmp.pop();
            cerr << xx << " " << y << "\n";
        }
        cerr << "\n";
        for (int i = 1;i <= n;i++) {
            cerr << format("b[{}]={}\n", i, b[i]);
        }
        cerr << "\n";
    };


    LL ans = 0;
    queue<PII>que;
    for (int i = 1;i <= m;i++) {
        if (q.empty())break;
        while (not q.empty() and ans + b[q.top().second] < x[i]) {
            // cerr << "ok\n";
            ans += b[q.top().second];
            b[q.top().second] = 0;
            que.emplace(q.top());
            q.pop();
        }

        if (q.empty())break;
        auto [tt, id] = q.top();q.pop();
        b[id] = ans + b[id] - x[i];
        if (b[id] != 0 and id != t[i]) {
            q.emplace(id, id);
        }
        ans = x[i];
        cerr << i << "now\n";
        while (not que.empty()) {
            if (b[que.front().second]) {
                q.push(que.front());
            }
            que.pop();
        }
        look();
        q.emplace(nxt[i], t[i]);
        b[t[i]] = a[t[i]];

    }
    while (not q.empty()) {
        ans += b[q.top().second];q.pop();
    }
    cout << ans << "\n";
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
    cin >> T;
    while (T--)
        solve();
    return 0;
}#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define int long long
using PII = pair<int, int>;


void solve() {
    int n, m;cin >> n >> m;
    vector<int>a(n + 1);
    for (int i = 1;i <= n;i++) {
        cin >> a[i];
    }
    priority_queue<PII, vector<PII>, greater<PII>>q;
    vector<int>x(m + 1), t(m + 1), vis(n + 1);
    vector<int>nxt(n + 4, m + 1), p(n + 1, m + 1);
    for (int i = 1;i <= m;i++) {
        cin >> x[i] >> t[i];
        q.emplace(i, t[i]);
        vis[t[i]] = 1;
    }
    auto b = a;
    // for (int i = 1;i <= m;i++) {
    //     cout << nxt[t[i]] << " ";
    // }
    // cout << "\n";return;
    for (int i = m;i >= 1;i--) {
        nxt[i] = p[t[i]];
        p[t[i]] = i;
    }
    // for (int i = 1;i <= m;i++) {
    //     cout << nxt[i] << " ";
    // }
    // cout << "\n";return;

    for (int i = 1;i <= n;i++) {
        if (!vis[i])q.emplace(m + 1, i);
    }

    auto look = [&]() {
        auto tmp = q;
        while (tmp.size()) {
            auto [xx, y] = tmp.top();
            tmp.pop();
            cerr << xx << " " << y << "\n";
        }
        cerr << "\n";
        for (int i = 1;i <= n;i++) {
            cerr << format("b[{}]={}\n", i, b[i]);
        }
        cerr << "\n";
    };


    LL ans = 0;
    queue<PII>que;
    for (int i = 1;i <= m;i++) {
        if (q.empty())break;
        while (not q.empty() and ans + b[q.top().second] < x[i]) {
            // cerr << "ok\n";
            ans += b[q.top().second];
            b[q.top().second] = 0;
            que.emplace(q.top());
            q.pop();
        }

        if (q.empty())break;
        auto [tt, id] = q.top();q.pop();
        b[id] = ans + b[id] - x[i];
        if (b[id] != 0 and id != t[i]) {
            q.emplace(id, id);
        }
        ans = x[i];
        cerr << i << "now\n";
        while (not que.empty()) {
            if (b[que.front().second]) {
                q.push(que.front());
            }
            que.pop();
        }
        look();
        q.emplace(nxt[i], t[i]);
        b[t[i]] = a[t[i]];

    }
    while (not q.empty()) {
        ans += b[q.top().second];q.pop();
    }
    cout << ans << "\n";
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
    cin >> T;
    while (T--)
        solve();
    return 0;
}

Details

answer.code:104:2: error: stray ‘#’ in program
  104 | }#include <bits/stdc++.h>
      |  ^
answer.code:104:12: error: ‘bits’ was not declared in this scope
  104 | }#include <bits/stdc++.h>
      |            ^~~~
answer.code:104:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
  104 | }#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
answer.code:104:12: error: ‘bits’ was not declared in this scope
  104 | }#include <bits/stdc++.h>
      |            ^~~~
answer.code:104:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
  104 | }#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
answer.code:104:12: error: ‘bits’ was not declared in this scope
  104 | }#include <bits/stdc++.h>
      |            ^~~~
answer.code:104:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
  104 | }#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
answer.code:104:12: error: ‘bits’ was not declared in this scope
  104 | }#include <bits/stdc++.h>
      |            ^~~~
answer.code:104:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
  104 | }#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
answer.code:104:12: error: ‘bits’ was not declared in this scope
  104 | }#include <bits/stdc++.h>
      |            ^~~~
answer.code:104:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
  104 | }#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
answer.code:104:12: error: ‘bits’ was not declared in this scope
  104 | }#include <bits/stdc++.h>
      |            ^~~~
answer.code:104:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
  104 | }#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
answer.code:104:12: error: ‘bits’ was not declared in this scope
  104 | }#include <bits/stdc++.h>
      |            ^~~~
answer.code:104:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
  104 | }#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
answer.code:104:12: error: ‘bits’ was not declared in this scope
  104 | }#include <bits/stdc++.h>
      |            ^~~~
answer.code:104:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
  104 | }#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
answer.code:104:12: error: ‘bits’ was not declared in this scope
  104 | }#include <bits/stdc++.h>
      |            ^~~~
answer.code:104:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
  104 | }#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
answer.code:104:3: error: ‘include’ does not name a type
  104 | }#include <bits/stdc++.h>
      |   ^~~~~~~
answer.code:111:6: error: redefinition of ‘void solve()’
  111 | void solve() {
      |      ^~~~~
answer.code:8:6: note: ‘void solve()’ previously defined here
    8 | void solve() {
      |      ^~~~~
answer.code:195:8: error: redefinition of ‘int main()’
  195 | signed main() {
      |        ^~~~
answer.code:92:8: note: ‘int main()’ previously defined here
   92 | signed main() {
      |        ^~~~