QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#296145#6338. Choruschy12321Compile Error//C++201.6kb2024-01-02 11:16:172024-01-02 11:16:17

Judging History

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

  • [2024-01-02 11:16:17]
  • 评测
  • [2024-01-02 11:16:17]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

constexpr int N = 1e6 + 10;

int n, m, r[N], g[N];
int head, tail, q[N];
ll pre[N], cnt[N], sum[N], f[N];
char s[2 * N];

inline ll x(int i) {return i;}

inline ll y(int i) {return f[i] + pre[i - 1] + i;}

inline ll w(int l, int r) {return (cnt[r] - l) * r - sum[r] + pre[l];}

bool check(ll k) {
    for (int i = 2; i <= n + 1; i++) f[i] = 1e18, g[i] = m + 1;
    q[head = tail = 1] = 1;
    for (int i = 2; i <= n + 1; i++) {
        while (head < tail && i * (x(q[head + 1]) - x(q[head])) > (y(q[head + 1]) - y(q[head]))) head++;
        f[i] = f[q[head]] + w(q[head] - 1, i - 1) - k;
        g[i] = g[q[head]] + 1;
        while (head < tail && (y(i) - y(q[tail])) * (x(q[tail] - x(q[tail - 1]))) < (y(q[tail]) - y(q[tail - 1])) * (x(i) - x(q[tail]))) tail--;
        q[++tail] = i;
    }
    return g[n + 1] <= m;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(nullptr), cout.tie(nullptr);
    cin >> n >> m >> (s + 1);
    for (int i = 1, up = 0, right = 0; i <= 2 * n; i++) s[i] == 'A' ? right++ : r[++up] = right;
    ll init = 0;
    for (int i = 1; i <= n; i++) {
        if (r[i] < i) init += i - r[i], r[i] = i;
        pre[i] += pre[i - 1] + r[i];
        cnt[r[i]]++, sum[r[i]] += r[i];
    }
    for (int i = 1; i <= n; i++) cnt[i] += cnt[i - 1], sum[i] += sum[i - 1];
    ll L = -5e11, R = 0, mid, ans;
    while (L <= R) {
        mid = (L + R) >> 1;
        if (check(mid)) ans = mid, L = mid + 1;
        else R = mid - 1;
    }
    check(ans), cout << init + f[n + 1] + m * ans;
    return 0;
}

详细

answer.code: In function ‘int main()’:
answer.code:35:19: error: no match for ‘operator>>’ (operand types are ‘std::basic_istream<char>::__istream_type’ {aka ‘std::basic_istream<char>’} and ‘char*’)
   35 |     cin >> n >> m >> (s + 1);
      |     ~~~~~~~~~~~~~ ^~ ~~~~~~~
      |              |          |
      |              |          char*
      |              std::basic_istream<char>::__istream_type {aka std::basic_istream<char>}
In file included from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:1:
/usr/include/c++/11/istream:168:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ (near match)
  168 |       operator>>(bool& __n)
      |       ^~~~~~~~
/usr/include/c++/11/istream:168:7: note:   conversion of argument 1 would be ill-formed:
answer.code:35:25: error: cannot bind non-const lvalue reference of type ‘bool&’ to a value of type ‘char*’
   35 |     cin >> n >> m >> (s + 1);
      |                      ~~~^~~~
In file included from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:1:
/usr/include/c++/11/istream:172:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]’ (near match)
  172 |       operator>>(short& __n);
      |       ^~~~~~~~
/usr/include/c++/11/istream:172:7: note:   conversion of argument 1 would be ill-formed:
answer.code:35:25: error: invalid conversion from ‘char*’ to ‘short int’ [-fpermissive]
   35 |     cin >> n >> m >> (s + 1);
      |                      ~~~^~~~
      |                         |
      |                         char*
answer.code:35:25: error: cannot bind rvalue ‘(short int)(((char*)(& s)) + 1)’ to ‘short int&’
In file included from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:1:
/usr/include/c++/11/istream:175:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ (near match)
  175 |       operator>>(unsigned short& __n)
      |       ^~~~~~~~
/usr/include/c++/11/istream:175:7: note:   conversion of argument 1 would be ill-formed:
answer.code:35:25: error: invalid conversion from ‘char*’ to ‘short unsigned int’ [-fpermissive]
   35 |     cin >> n >> m >> (s + 1);
      |                      ~~~^~~~
      |                         |
      |                         char*
answer.code:35:25: error: cannot bind rvalue ‘(short unsigned int)(((char*)(& s)) + 1)’ to ‘short unsigned int&’
In file included from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:1:
/usr/include/c++/11/istream:179:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]’ (near match)
  179 |       operator>>(int& __n);
      |       ^~~~~~~~
/usr/include/c++/11/istream:179:7: note:   conversion of argument 1 would be ill-formed:
answer.code:35:25: error: invalid conversion from ‘char*’ to ‘int’ [-fpermissive]
   35 |     cin >> n >> m >> (s + 1);
      |                      ~~~^~~~
      |                         |
      |                         char*
answer.code:35:25: error: cannot bind rvalue ‘(int)(((char*)(& s)) + 1)’ to ‘int&’
In file included from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:1:
/usr/include/c++/11/istream:182:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ (near match)
  182 ...