Submission #389463

# Submission time Handle Problem Language Result Execution time Memory
389463 2021-04-14T06:24:14 Z 8e7 Permutation Recovery (info1cup17_permutation) C++14
25 / 100
1 ms 332 KB
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#define ll long long
#define maxn 100005
#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;
//#include <bits/extc++.h>
//using namespace __gnu_pbds;
//template<lcass T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//find by order, order of key
ll q[maxn], b[maxn], c[maxn];
int a[maxn], found[maxn];

/*
string operator *(string a, string b) { //addition
	if (a.size() < b.size()) swap(a, b);
	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 += '1';
	return ret;
}
string operator / (string a, string b) { //subtraction
	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');
		ret += char('0' + cur + (cur < 0 ? (tmp = -1, 10) : (tmp = 0, 0)));
	}
	while (ret.size() && ret[ret.size() - 1] == '0') ret.pop_back();
	return ret;
}
bool operator < (string a, string b) {
	if (a.size() != b.size()) return a.size() < b.size();
}
*/
ll seg[4 * maxn], tag[4 * maxn];
int mpos[4 * maxn];
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);
	seg[cur] = min(seg[cur * 2], seg[cur * 2 + 1]);
	if (seg[cur] == seg[cur * 2 + 1]) {
		mpos[cur] = mpos[cur * 2 + 1];
	} else {
		mpos[cur] = mpos[cur * 2];
	}
}
void modify(int cur, int l, int r, int ql, int qr, ll val) {
	if (r <= l || qr <= l || ql >= r) return;
	if (ql <= l && qr >= r) {
		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);
	seg[cur] = min(seg[cur * 2] + tag[cur * 2], seg[cur * 2 + 1] + tag[cur * 2 + 1]);
	if (seg[cur] == seg[cur * 2 + 1] + tag[cur * 2 + 1]) {
		mpos[cur] = mpos[cur * 2 + 1];
	} else {
		mpos[cur] = mpos[cur * 2];
	}
}

int main() {
	io
	int n;
	cin >> n;
	/*
	for (int i = 0;i < n;i++) {
		string a, b;
		cin >> a >> b;
		reverse(a.begin(), a.end()), reverse(b.begin(), b.end());
		string res = a / b;
		reverse(res.begin(), res.end());
		cout << res << endl;
	}
	*/
	for (int i = 0;i < n;i++) cin >> q[i];
	ll tb = 0;
	for (int i = 0;i < n;i++) {
		b[i] = q[i] - (i ? q[i - 1] : 0);
		c[i] = tb + 1 - b[i];
		tb += b[i];
	}
	init(1, 0, n);
	for (int i = 0;i < n;i++) {
		int ind = mpos[1];
		a[ind] = n - i;
		modify(1, 0, n, ind, ind + 1, 1LL<<60);
		modify(1, 0, n, ind + 1, n, -b[ind]);

	}
	for (int i = 0;i < n;i++) cout << a[i] << " ";
	cout << "\n";
}
/*
4
1 2 5 6

6
1 3 5 9 11 21
 */
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -