QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#698059#9528. New Energy VehiclewkrCompile Error//C++142.4kb2024-11-01 17:10:072024-11-01 17:10:07

Judging History

This is the latest submission verdict.

  • [2024-11-01 17:10:07]
  • Judged
  • [2024-11-01 17:10:07]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define close ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
const int N = 1e5 + 5;
int tree[N];
int n, m;
int lowbit(int x)
{
    return x & -x;
}
void add(int pos, int val)
{
    while (pos <= n)
    {
        tree[pos] += val;
        pos += lowbit(pos);
    }
}
int query(int x)
{
    int ans = 0;
    while (x >= 1)
    {
        ans += tree[x];
        x -= lowbit(x);
    }
    return ans;
}
int query(int l, int r)
{
    return query(r) - query(l - 1);
}
void update(int pos, int k)
{
    while (pos <= n)
    {
        tree[pos] += k;
        pos += lowbit(pos);
    }
}
int ask(int pos)
{
    int ans = 0;
    while (pos >= 1)
    {
        ans += tree[pos];
        pos -= lowbit(pos);
    }
    return ans;
}
void solved()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        tree[i] = 0;
    }
    vector<int> arr(n + 1, 0);
    int total = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
        total += arr[i];
    }
    vector<int> vis(n + 1, 1);
    brr[0] = {0, 0};
    vector<array<int, 2>> brr(m + 1);
    for (int i = 1; i <= m; i++)
    {
        int x, v;
        cin >> x >> v;
        brr[i] = {x, v};
    }
    sort(brr.begin() + 1, brr.end());
    int cntx = 0;
    map<int, int> mp;
    for (int i = 1; i <= m; i++)
    {
        int dis = brr[i][0] - brr[i - 1][0];
        int id = brr[i][1];
        int v = arr[id];
        if (total < dis)
        {
            break;
        }
        else
        {
            if (v >= dis)
            {
                total += dis;
                int cnt = dis - v;
                for (auto index : mp)
                {
                    if (index.first != id)
                    {
                        int c = min(index.second, cnt);
                        cnt -= c;
                        mp[index] -= c;
                        total += c;
                    }
                    if (!cnt)
                    {
                        break;
                    }
                }
            }
            else
            {
                mp[id] = dis - v;
                total += v;
            }
        }
    }
    cout << total << endl;
}

signed main()
{
    close;
    int T;
    cin >> T;
    while (T--)
    {
        solved();
    }
}

Details

answer.code: In function ‘void solved()’:
answer.code:68:5: error: ‘brr’ was not declared in this scope; did you mean ‘arr’?
   68 |     brr[0] = {0, 0};
      |     ^~~
      |     arr
answer.code:100:27: error: no match for ‘operator[]’ (operand types are ‘std::map<long long int, long long int>’ and ‘std::pair<const long long int, long long int>’)
  100 |                         mp[index] -= c;
      |                           ^
In file included from /usr/include/c++/13/map:63,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:152,
                 from answer.code:1:
/usr/include/c++/13/bits/stl_map.h:504:7: note: candidate: ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = long long int; _Tp = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >; mapped_type = long long int; key_type = long long int]’
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_map.h:504:34: note:   no known conversion for argument 1 from ‘std::pair<const long long int, long long int>’ to ‘const std::map<long long int, long long int>::key_type&’ {aka ‘const long long int&’}
  504 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_map.h:524:7: note: candidate: ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = long long int; _Tp = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >; mapped_type = long long int; key_type = long long int]’
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_map.h:524:29: note:   no known conversion for argument 1 from ‘std::pair<const long long int, long long int>’ to ‘std::map<long long int, long long int>::key_type&&’ {aka ‘long long int&&’}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~