QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#536888#4561. Catfish FarmWansur#Compile Error//C++232.0kb2024-08-29 17:54:432024-08-29 17:54:47

Judging History

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

  • [2024-08-29 17:54:47]
  • 评测
  • [2024-08-29 17:54:43]
  • 提交

answer

#include "fish.h"
#include <bits/stdc++.h>
#define ent '\n'

using namespace std;
typedef long long ll;
const int maxn = 1e5 + 12;

set<int> s[maxn];
map<int, ll> dp[maxn], dpt[maxn], d[maxn];
map<int, ll> pref[maxn], mx[maxn], suff[maxn];
map<int, ll>  a[maxn], mval[maxn];

long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
    ll ans = 0;
    for(int i=0;i<m;i++){
        x[i]++, y[i]++;
        a[x[i]][y[i]] += w[i];
        for(int d=-1;d<=1;d++){
            s[x[i] + d].insert(y[i]);
        }
    }
    s[0].insert(0);
    s[0].insert(n);
    for(int i=1;i<=n;i++){
        s[i].insert(0);
        s[i].insert(n);
        int sum = 0;
        for(int x:s[i]){
            sum += a[i][x];
            pref[i][x] = sum;
        }
    }
    for(int i=1;i<=n;i++){

        ll val = -1e18;

        for(int x:s[i]){
            auto it = s[i-1].upper_bound(x);
            it--;
            int y = *it;
            dp[i][x] = max(mx[i-1][y] + pref[i-1][y], mval[i-1][y]);
            d[i][x] = max(dp[i][x], suff[i-1][x] - pref[i][x]);
            val = max(val, d[i][x]);
            mval[i][x] = val;
            ans = max(ans, d[i][x]);
        }

        for(auto x:s[i-1]){
            auto it = s[i].upper_bound(x);
            it--;
            int y = *it;
            dpt[i][x] = d[i-1][x] + pref[i][y];
        }

        val = -1e18;

        for(int x:s[i]){
            auto it = s[i-1].upper_bound(x);
            it--;
            
            val = max(val, max(dp[i][x], dpt[i][y]) - pref[i][x]);
            mx[i][x] = val;
        }

        val = -1e18;

        if(i < n){
            for(auto it = --s[i].end();;it--){
                int x = *it;
                auto I = s[i+1].upper_bound(x);
                I--;
                int y = *I;

                val = max(val, d[i][x] + pref[i+1][y]);
                suff[i][x] = val;
                if(it == s[i].begin()) break;
            }
        }
    }
    return ans;
}

Details

answer.code: In function ‘long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)’:
answer.code:62:48: error: no match for ‘operator[]’ (operand types are ‘std::map<int, long long int>’ and ‘std::vector<int>’)
   62 |             val = max(val, max(dp[i][x], dpt[i][y]) - pref[i][x]);
      |                                                ^
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:2:
/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 = int; _Tp = long long int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, long long int> >; mapped_type = long long int; key_type = 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::vector<int>’ to ‘const std::map<int, long long int>::key_type&’ {aka ‘const 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 = int; _Tp = long long int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, long long int> >; mapped_type = long long int; key_type = 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::vector<int>’ to ‘std::map<int, long long int>::key_type&&’ {aka ‘int&&’}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~