QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#69044#4583. Concerto de PandemicSanguineChameleonWA 2ms13632kbC++204.9kb2022-12-22 21:22:562022-12-22 21:22:58

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-22 21:22:58]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:13632kb
  • [2022-12-22 21:22:56]
  • 提交

answer

// BEGIN BOILERPLATE CODE

#include <bits/stdc++.h>
using namespace std;

#ifdef KAMIRULEZ
	const bool kami_loc = true;
	const long long kami_seed = 69420;
#else
	const bool kami_loc = false;
	const long long kami_seed = chrono::steady_clock::now().time_since_epoch().count();
#endif

const string kami_fi = "kamirulez.inp";
const string kami_fo = "kamirulez.out";
mt19937_64 kami_gen(kami_seed);

long long rand_range(long long rmin, long long rmax) {
	uniform_int_distribution<long long> rdist(rmin, rmax);
	return rdist(kami_gen);
}

long double rand_real(long double rmin, long double rmax) {
	uniform_real_distribution<long double> rdist(rmin, rmax);
	return rdist(kami_gen);
}

void file_io(string fi, string fo) {
	if (fi != "" && (!kami_loc || fi == kami_fi)) {
		freopen(fi.c_str(), "r", stdin);
	}
	if (fo != "" && (!kami_loc || fo == kami_fo)) {
		freopen(fo.c_str(), "w", stdout);
	}
}

void set_up() {
	if (kami_loc) {
		file_io(kami_fi, kami_fo);
	}
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

void just_do_it();

void just_exec_it() {
	if (kami_loc) {
		auto pstart = chrono::steady_clock::now();
		just_do_it();
		auto pend = chrono::steady_clock::now();
		long long ptime = chrono::duration_cast<chrono::milliseconds>(pend - pstart).count();
		string bar(50, '=');
		cout << '\n' << bar << '\n';
		cout << "Time: " << ptime << " ms" << '\n';
	}
	else {
		just_do_it();
	}
}

int main() {
	set_up();
	just_exec_it();
	return 0;
}

// END BOILERPLATE CODE

// BEGIN MAIN CODE

const int ms = 2e5 + 20;
const int st = 20;
const long long inf = 1e12 + 20;
long long a[ms];
int nxtf[ms];
bool f[ms];
int dr[ms];
int dl[ms];
vector<int> q[ms];
int nxtr[ms];
long long dist[ms][st];
int n, m, k, p;

bool check(long long md) {
	dr[n - 1] = 0;
	long long cd = 0;
	for (int i = 0; i < n; i++) {
		int pv = (i + n - 1) % n;
		if (dr[pv] == 0) {
			dr[i] = 0;
			cd = 0;
		}
		else {
			dr[i] = dr[pv] - 1;
			cd -= a[i];
			cd -= 1;
		}
		int cc = (i + dr[i]) % n;
		while (dr[i] < n - 1) {
			cc = (cc + 1) % n;
			if (cd + 1 + a[cc] <= md) {
				dr[i]++;
				cd = cd + 1 + a[cc];
			}
			else {
				break;
			}
		}
	}
	cd = 0;
	dl[0] = 0;
	for (int i = n - 1; i >= 0; i--) {
		int pv = (i + 1) % n;
		if (dl[pv] == 0) {
			dl[i] = 0;
			cd = 0;
		}
		else {
			dl[i] = dl[pv] - 1;
			cd -= a[i];
			cd -= 1;
		}
		int cc = (i + n - dl[i]) % n;
		while (dl[i] < n - 1) {
			cc = (cc + n - 1) % n;
			if (cd + 1 + a[cc] <= md) {
				dl[i]++;
				cd = cd + 1 + a[cc];
			}
			else {
				break;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		q[i].clear();
		nxtr[i] = -1;
	}
	for (int i = 0; i < n; i++) {
		if (a[i] > 0) {
			continue;
		}
		if (dl[i] + dr[i] >= n - 1) {
			return true;
		}
		dl[i] = (i + n - dl[i]) % n;
		dr[i] = (i + dr[i]) % n;
		q[dl[i]].push_back(i);
	}
	int ff = -1;
	for (int k = 0; k < 2; k++) {
		for (int i = 0; i < n; i++) {
			for (auto x: q[i]) {
				if (ff == -1) {
					ff = x;
					continue;
				}
				int d1 = (dr[ff] + n - dl[ff]) % n - (i + n - dl[ff]) % n;
				int d2 = (dr[x] + n - dl[x]) % n - (i + n - dl[x]) % n;
				if (d1 < d2) {
					ff = x;
				}
			}
			nxtr[i] = ff;
		}
	}
	for (int i = 0; i < n; i++) {
		if (f[i]) {
			dist[i][0] = (dr[nxtr[i]] + n - i) % n + 1;
		}
	}
	for (int k = 1; k < st; k++) {
		for (int i = 0; i < n; i++) {
			if (f[i]) {
				int j = (dist[i][k - 1] + i) % n;
				dist[i][k] = dist[i][k - 1] + 1 + (nxtf[j] + n - j) % n + dist[nxtf[j]][k - 1] - 1;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (a[i] > 0) {
			continue;
		}
		int mi = n - (dr[i] + n - dl[i]) % n - 1;
		int cc = (dr[i] + 1) % n;
		long long cd = (nxtf[cc] + n - cc) % n;
		if (cd >= mi) {
			return true;
		}
		cc = nxtf[cc];
		int cr = 1;
		for (int j = st - 1; j >= 0; j--) {
			if (cd + dist[cc][j] < mi) {
				cr += (1 << j);
				cd += dist[cc][j];
				cc = (dist[cc][j] - 1 + cc) % n;
				cc = (cc + 1) % n;
				cd += (nxtf[cc] + n - cc) % n;
				cc = nxtf[cc];
			}
		}
		cr += (1 << 0);
		cd += dist[cc][0];
		cc = (dist[cc][0] - 1 + cc) % n;
		cc = (cc + 1) % n;
		cd += (nxtf[cc] + n - cc) % n;
		cc = nxtf[cc];
		if (cd >= mi && cr <= p) {
			return true;
		}
	}
	return false;
}

void just_do_it() {
	cin >> n >> m >> k >> p;
	for (int i = 0; i < m; i++) {
		int u, w;
		cin >> u >> w;
		u--;
		a[u] = w;
	}
	for (int i = 0; i < k; i++) {
		int u;
		cin >> u;
		u--;
		f[u] = true;
	}
	for (int i = 0; i < n; i++) {
		if (f[i]) {
			nxtf[0] = i;
			break;
		}
	}
	for (int i = n - 1; i >= 1; i--) {
		if (f[i]) {
			nxtf[i] = i;
		}
		else {
			nxtf[i] = nxtf[(i + 1) % n];
		}
	}
	long long lt = 0;
	long long rt = inf;
	long long res = -1;
	while (lt <= rt) {
		long long mt = (lt + rt) / 2;
		if (check(mt)) {
			res = mt;
			rt = mt - 1;
		}
		else {
			lt = mt + 1;
		}
	}
	cout << res;
}

// END MAIN CODE

详细

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 13632kb

input:

10 4 3 2
1 2
4 4
6 2
7 5
2 5 8

output:

5

result:

wrong answer 1st lines differ - expected: '4', found: '5'