QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#291571#7627. PhonyDJ2006WA 1ms11784kbC++173.1kb2023-12-26 22:18:192023-12-26 22:18:20

Judging History

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

  • [2023-12-26 22:18:20]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:11784kb
  • [2023-12-26 22:18:19]
  • 提交

answer

#include <cstdio>
#include <algorithm>

#include <utility>

#define mid ((L + R) >> 1)
#define ls (u << 1)
#define rs (u << 1 | 1)
#define lson ls, L, mid
#define rson rs, mid + 1, R

const long long INF = 1e18;

const int N = 5e5;

int n, m;
int id[N + 5];
int order[N + 5];

long long k, x;
long long a[N + 5];
long long r[N + 5];

char opt[3];

struct sgt {
	int mn[N * 4 + 5];
	int sum[N * 4 + 5];
	
	void pushup(int u) {
		mn[u] = std::min(mn[ls], mn[rs]);
		sum[u] = sum[ls] + sum[rs];
	}
	
	void build(int u = 1, int L = 1, int R = n) {
		if (L == R) { mn[u] = n; sum[u] = 0; return ; }
		build(lson); build(rson); pushup(u);
	}
	
	void upd(int x, int y, int u = 1, int L = 1, int R = n) {
		if (L == R) return sum[u] += y, void();
		x <= mid ? upd(x, y, lson) : upd(x, y, rson); pushup(u);
	}
	
	int asksum(int ql, int qr, int u = 1, int L = 1, int R = n) {
		if (qr < L || ql > R) return 0;
		if (ql <= L && R <= qr) return sum[u];
		return asksum(ql, qr, lson) + asksum(ql, qr, rson);
	}
	
	std::pair<int, int> askpos(int ql, int qr, int siz, int u = 1, int L = 1, int R = n) {
		if (qr < L || ql > R || !siz || !sum[u]) return { -1, siz };
		if (ql <= L && R <= qr && sum[u] <= siz) return { mn[u], siz - sum[u] };
		auto now = askpos(ql, qr, siz, rson);
		if (now.second) now = askpos(ql, qr, now.second, lson);
		return now;
	}
} T;

int pos, pre;

long long mx;

void add() {
	while (pos <= n && a[pos] / k == mx) {
		T.upd(id[pos++], 1);
	}
}

void add2() {
	while (pos <= n && a[pos] / k == mx - 1 && id[pos] > pre) {
		T.upd(id[pos++], 1);
	}
}

void decrease(long long x) {
	if (!x) {
		return ;
	}
	int presum = T.asksum(1, pre);
	if (x < presum) {
		auto now = T.askpos(1, pre, x);
		pre = now.first - 1;
		add2();
	} else {
		mx -= 1;
		add();
		x -= presum;
		pre = n;
		if (x) {
			long long sum = T.asksum(1, n);
			long long t = x / sum;
			if (pos > n || mx - t > a[pos] / k) {
				mx -= t;
				x -= t * sum;
				decrease(x);
			} else {
				long long t = mx - a[pos] / k;
				mx -= t;
				x -= t * sum;
				add();
				decrease(x);
			}
		}
	}
}

int main() {
	#ifdef LOCAL
		freopen("data.in", "r", stdin);
//		freopen("data.out", "w", stdout);
	#endif
	scanf("%d %d %lld", &n, &m, &k);
	for (int i = 1; i <= n; i++)
		scanf("%lld", &a[i]);
	std::sort(a + 1, a + n + 1, std::greater<>());
	for (int i = 1; i <= n; i++)
		order[i] = i;
	std::sort(order + 1, order + n + 1, [&](int x, int y) {
		return a[x] % k < a[y] % k;
	});
	for (int i = 1; i <= n; i++) {
		id[order[i]] = i;
		r[i] = a[order[i]] % k;
	}
	T.build(); pos = 1; pre = n; mx = a[1] / k; add();
	while (m--) {
		scanf("%s %lld", opt, &x);
		if (opt[0] == 'C') {
			decrease(x);
		} else {
			if (x < pos) {
				int sum = T.asksum(1, pre);
				if (x < sum) {
					auto now = T.askpos(1, pre, x);
					auto ans = k * mx + r[now.first];
					printf("%lld\n", ans);
				} else {
					x -= sum;
					auto now = T.askpos(1, n, x);
					auto ans = k * (mx - 1) + r[now.first];
					printf("%lld\n", ans);
				}
			} else {
				printf("%lld\n", a[x]);
			}
		}
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 9824kb

input:

3 5 5
7 3 9
A 3
C 1
A 2
C 2
A 3

output:

3
4
-1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 11784kb

input:

5 8 8
294 928 293 392 719
A 4
C 200
A 5
C 10
A 2
C 120
A 1
A 3

output:

294
207
199
7
7

result:

wrong answer 2nd lines differ - expected: '200', found: '207'