QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#22297#2356. Partition of Queriesasoul#Compile Error//C++202.4kb2022-03-09 14:42:182022-05-18 04:12:56

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-18 04:12:56]
  • 评测
  • [2022-03-09 14:42:18]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l); i <= (r); i ++)
#define per(i, r, l) for(int i = (r); i >= (l); i --)
#define trv(i, u, v) for(int i = head[u], v = e[i].to; i; v = e[i = e[i].nxt].to)
#define fi first
#define se second
#define all(s) s.begin(), s.end()
#define sz(s) (int)(s.size())
#define lb(s) ((s) & -(s))
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
mt19937_64 hua(time(0));
template<typename T> inline bool chkmx(T &x, T y) {return x < y ? x = y, 1 : 0;}
template<typename T> inline bool chkmn(T &x, T y) {return y < x ? x = y, 1 : 0;}
template<int T> using A = array<int, T>;

inline int read() {
	int x = 0, f = 1; char c = getchar();
	for(; !isdigit(c); c = getchar()) if(c == '-')  f = 0;
	for(; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	return f ? x : -x;
}
const int maxn = 1e6;
int n, y;
ll f[maxn + 5], lst[maxn + 5];
ll val[maxn + 5][2], pre[maxn + 5][2];
char s[maxn + 5];
struct Node {
	int l, r, s;
};
deque<Node> q;
ll calc(int l, int r) {
	return pre[r][1] - pre[l - 1][1] - lst[l] * (pre[r][0] - pre[l - 1][0]);
}
bool chk(int s1, int s2, int i) {
	return f[s1] + calc(s1 + 1, i) >= f[s2] + calc(s2 + 1, i);
}
int main() {
//	freopen("in.txt", "r", stdin);
	cin >> n >> y >> s + 1;
	int cur = 0;
	rep(i, 1, n) { 
		if(s[i] == '+') cur ++, lst[i] = lst[i - 1];
		else val[i][0] = 1, lst[i] = val[i][1]= cur;
		pre[i][0] = pre[i - 1][0] + val[i][0];
		pre[i][1] = pre[i - 1][1] + val[i][1];
	}
	q.push_front({1, n, 0});
//	cout << calc(3, n) << '\n';
	rep(i, 1, n) {
//		cout << i << '\n';
		q[0].l = i;
		while(!q.empty() && q.front().l > q.front().r) q.pop_front();
//		if(q.empty()) assert(0);
		f[i] = f[q.front().s] + calc(q.front().s + 1, i) + y;
//		cout << i << ' ' << f[i] << '\n';
		while(!q.empty() && chk(q.back().s, i, q.back().l)) q.pop_back();
		if(q.empty()) {
			q.push_front({i + 1, n, i});
			continue;
		}
		int l = q.back().l, r = q.back().r, ans = r + 1, s = q.back().s;
		int sl = l, sr = r;
		q.pop_back();
		while(l <= r) {
			int mid = l + r >> 1;
			if(chk(s, i, mid)) ans = mid, r = mid - 1;
			else l = mid + 1;
		}
		q.push_back({sl, ans - 1, s});
		if(ans != sr + 1) q.push_back({ans, n, i});
		else if(sr != n) q.push_back({sr + 1, n, i});
//		cout << ans << '\n';
//		for(auto x : q) cout << x.l << ' ' << x.r << ' ' << x.s << '\n';
	}
	cout << f[n] - y << '\n';
	return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:43:23: error: no match for ‘operator>>’ (operand types are ‘std::basic_istream<char>::__istream_type’ {aka ‘std::basic_istream<char>’} and ‘char*’)
   43 |         cin >> n >> y >> 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:43:28: error: cannot bind non-const lvalue reference of type ‘bool&’ to a value of type ‘char*’
   43 |         cin >> n >> y >> 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:43:28: error: invalid conversion from ‘char*’ to ‘short int’ [-fpermissive]
   43 |         cin >> n >> y >> s + 1;
      |                          ~~^~~
      |                            |
      |                            char*
answer.code:43:28: 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:43:28: error: invalid conversion from ‘char*’ to ‘short unsigned int’ [-fpermissive]
   43 |         cin >> n >> y >> s + 1;
      |                          ~~^~~
      |                            |
      |                            char*
answer.code:43:28: 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:43:28: error: invalid conversion from ‘char*’ to ‘int’ [-fpermissive]
   43 |         cin >> n >> y >> s + 1;
      |                          ~~^~~
      |                            |
      |                            char*
answer.code:43:28: 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 ...