답안 #389520

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
389520 2021-04-14T06:58:29 Z 8e7 Permutation Recovery (info1cup17_permutation) C++14
컴파일 오류
0 ms 0 KB
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#define ll long long
#define maxn 70005
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
#define pii pair<int, int>
using namespace std;
string q[maxn], b[maxn], c[maxn];
int a[maxn], found[maxn];


string operator *(string a, string b) { //addition
	if (a == "-" || b == "-") return "-";
	if (a.size() < b.size()) {
		int d = b.size() - a.size();
		for (int i = 0;i < d;i++) a += 0;
	} else {
		int d = a.size() - b.size();
		for (int i = 0;i < d;i++) b += 0;
	}

	string ret;
	int cur = 0, tmp = 0;
	for (int i = 0;i < a.size();i++) {
		cur = tmp;
		cur += a[i] - 0 + b[i] - 0;
		tmp = (cur > 9 ? (cur -= 10, 1) : 0);
		ret += char(0 + cur);
	}
	if (tmp) ret += 0;
	return ret;
}
string operator / (string a, string b) { //subtraction
	if (a == "-") return a;
	int d = a.size() - b.size();
	for (int i = 0;i < d;i++) b += 0;
	string ret;
	int cur = 0, tmp = 0;
	for (int i = 0;i < a.size();i++) {
		cur = tmp;
		cur += a[i] - b[i];
		ret += char(cur + (cur < 0 ? (tmp = -1, 10) : (tmp = 0, 0)));
	}
	while (ret.size() > 1 && ret[ret.size() - 1] == 0) ret.pop_back();
	return ret;
}
bool operator <= (string a, string b) {
	if (a == "-") return false;
	else if (b == "-") return true;
	if (a.size() != b.size()) return a.size() < b.size();
	for (int i = a.size() - 1;i >= 0;i--) {
		if (a[i] != b[i]) return a[i] < b[i];
	}
	return true;
}


string seg[4 * maxn], tag[4 * maxn];
int mpos[4 * maxn];
void upd(int cur, int l, int r) {
	string vl = seg[cur * 2] / tag[cur * 2], vr = seg[cur * 2 + 1] / tag[cur * 2 + 1];
	if (vr <= vl) {
		seg[cur] = vr;
		mpos[cur] = mpos[cur * 2 + 1];
	} else {
		seg[cur] = vl;
		mpos[cur] = mpos[cur * 2];
	}
}
void init(int cur, int l, int r) {
	if (r <= l) return;
	if (r - l == 1) {
		seg[cur] = c[l];
		mpos[cur] = l;
		return;
	}
	int mid = (l + r) / 2;
	init(cur * 2, l, mid);
	init(cur * 2 + 1, mid, r);
	upd(cur, l, r);
}
void remove(int cur, int l, int r, int ind) {
	if (r <= l) return;
	if (r - l == 1) {
		seg[cur] = "-";
		return;
	}

	int mid = (l + r) / 2;
	if (ind < mid) remove(cur * 2, l, mid, ind);
	else remove(cur * 2 + 1, mid, r, ind);
	upd(cur, l, r);
}
void modify(int cur, int l, int r, int ql, int qr, string val) {
	if (r <= l || qr <= l || ql >= r) return;
	if (ql <= l && qr >= r) {
		tag[cur] = tag[cur] * val;
		return;
	}
	int mid = (l + r) / 2;
	modify(cur * 2, l, mid, ql, qr, val);
	modify(cur * 2 + 1, mid, r, ql, qr, val);
	upd(cur, l, r);
}
int main() {
	io
	int n;
	cin >> n;


	for (int i = 0;i < n;i++) cin >> q[i], reverse(q[i].begin(), q[i].end());
	for (int i = 0;i < n;i++) {
		b[i] = q[i] / (i ? q[i - 1] : char(0));
		c[i] = (i ? (q[i - 1] * char(1)) / b[i] : char(0));
	}
	init(1, 0, n);
	for (int i = 0;i < n;i++) {
		int ind = mpos[1];
		a[ind] = n - i;
		remove(1, 0, n, ind);
		modify(1, 0, n, ind + 1, n, b[ind]);
		//dbg(1, 0, n);
	}
	for (int i = 0;i < n;i++) cout << a[i] << " ";
	cout << "\n";
}
/*
4
1 2 5 6

6
1 3 5 9 11 21
 */

Compilation message

permutation.cpp: In function 'std::string operator*(std::string, std::string)':
permutation.cpp:21:31: error: ambiguous overload for 'operator+=' (operand types are 'std::string' {aka 'std::__cxx11::basic_string<char>'} and 'int')
   21 |   for (int i = 0;i < d;i++) a += 0;
      |                             ~~^~~~
In file included from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from permutation.cpp:2:
/usr/include/c++/9/bits/basic_string.h:1168:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator+=(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1168 |       operator+=(const basic_string& __str)
      |       ^~~~~~~~
/usr/include/c++/9/bits/basic_string.h:1177:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator+=(const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1177 |       operator+=(const _CharT* __s)
      |       ^~~~~~~~
/usr/include/c++/9/bits/basic_string.h:1186:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator+=(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1186 |       operator+=(_CharT __c)
      |       ^~~~~~~~
permutation.cpp:24:31: error: ambiguous overload for 'operator+=' (operand types are 'std::string' {aka 'std::__cxx11::basic_string<char>'} and 'int')
   24 |   for (int i = 0;i < d;i++) b += 0;
      |                             ~~^~~~
In file included from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from permutation.cpp:2:
/usr/include/c++/9/bits/basic_string.h:1168:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator+=(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1168 |       operator+=(const basic_string& __str)
      |       ^~~~~~~~
/usr/include/c++/9/bits/basic_string.h:1177:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator+=(const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1177 |       operator+=(const _CharT* __s)
      |       ^~~~~~~~
/usr/include/c++/9/bits/basic_string.h:1186:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator+=(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1186 |       operator+=(_CharT __c)
      |       ^~~~~~~~
permutation.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for (int i = 0;i < a.size();i++) {
      |                 ~~^~~~~~~~~~
permutation.cpp:35:15: error: ambiguous overload for 'operator+=' (operand types are 'std::string' {aka 'std::__cxx11::basic_string<char>'} and 'int')
   35 |  if (tmp) ret += 0;
      |           ~~~~^~~~
In file included from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from permutation.cpp:2:
/usr/include/c++/9/bits/basic_string.h:1168:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator+=(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1168 |       operator+=(const basic_string& __str)
      |       ^~~~~~~~
/usr/include/c++/9/bits/basic_string.h:1177:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator+=(const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1177 |       operator+=(const _CharT* __s)
      |       ^~~~~~~~
/usr/include/c++/9/bits/basic_string.h:1186:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator+=(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1186 |       operator+=(_CharT __c)
      |       ^~~~~~~~
permutation.cpp: In function 'std::string operator/(std::string, std::string)':
permutation.cpp:41:30: error: ambiguous overload for 'operator+=' (operand types are 'std::string' {aka 'std::__cxx11::basic_string<char>'} and 'int')
   41 |  for (int i = 0;i < d;i++) b += 0;
      |                            ~~^~~~
In file included from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from permutation.cpp:2:
/usr/include/c++/9/bits/basic_string.h:1168:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator+=(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1168 |       operator+=(const basic_string& __str)
      |       ^~~~~~~~
/usr/include/c++/9/bits/basic_string.h:1177:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator+=(const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1177 |       operator+=(const _CharT* __s)
      |       ^~~~~~~~
/usr/include/c++/9/bits/basic_string.h:1186:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator+=(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1186 |       operator+=(_CharT __c)
      |       ^~~~~~~~
permutation.cpp:44:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  for (int i = 0;i < a.size();i++) {
      |                 ~~^~~~~~~~~~
permutation.cpp: In function 'int main()':
permutation.cpp:118:20: error: operands to ?: have different types 'std::string' {aka 'std::__cxx11::basic_string<char>'} and 'char'
  118 |   b[i] = q[i] / (i ? q[i - 1] : char(0));
      |                  ~~^~~~~~~~~~~~~~~~~~~~
permutation.cpp:119:25: error: no match for 'operator*' (operand types are 'std::string' {aka 'std::__cxx11::basic_string<char>'} and 'char')
  119 |   c[i] = (i ? (q[i - 1] * char(1)) / b[i] : char(0));
      |                ~~~~~~~~ ^ ~~~~~~~
      |                       |   |
      |                       |   char
      |                       std::string {aka std::__cxx11::basic_string<char>}
permutation.cpp:17:8: note: candidate: 'std::string operator*(std::string, std::string)'
   17 | string operator *(string a, string b) { //addition
      |        ^~~~~~~~
permutation.cpp:17:36: note:   no known conversion for argument 2 from 'char' to 'std::string' {aka 'std::__cxx11::basic_string<char>'}
   17 | string operator *(string a, string b) { //addition
      |                             ~~~~~~~^