Submission #2601442


Source Code Expand

#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;

long long H, W, N, M, D, S, A[100009], B1[100009], B2[100009]; vector<long long>G[100009];
multiset<long long>State;

void add(long long V) {
	/*auto pos = State.begin();
	while (pos != State.end()) { cout << *pos << " "; pos++; }cout << endl;
	cout << S << endl << endl;
	cout << "add " << V << endl;*/

	auto pos1 = State.lower_bound(V);
	auto pos2 = pos1; pos2--;
	long long L = *pos2, R = *pos1;
	if (R - L - 1 > D && L != V && R != V) {
		S++;
		if (R - V - 1 <= D) S += R - V - 1;
		if (V - L - 1 <= D) S += V - L - 1;
	}
	State.insert(V);
}
void lose(long long V) {
	/*auto pos = State.begin();
	while (pos != State.end()) { cout << *pos << " "; pos++; }cout << endl;
	cout << S << endl << endl;
	cout << "lose " << V << endl;*/
	auto pos0 = State.lower_bound(V); State.erase(pos0);
	auto pos1 = State.lower_bound(V);
	auto pos2 = pos1; pos2--;
	long long L = *pos2, R = *pos1;

	if (R - L - 1 > D && L != V && R != V) {
		S--;
		if (R - V - 1 <= D) S -= R - V - 1;
		if (V - L - 1 <= D) S -= V - L - 1;
	}
}

vector<long long> solve(long long T) {
	vector<long long>J;
	State.clear(); S = 0;
	State.insert(-(1LL << 60));
	State.insert((1LL << 60));
	for (int i = 0; i <= W; i++) G[i].clear();
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < T; j++) {
			add(A[i] - 1 + (H*W) * 1LL * j);
		}
	}
	for (int i = 1; i <= M; i++) {
		for (int j = 0; j < T; j++) {
			add((B1[i] - 1)*W + (B2[i] - 1) + (H*W) * 1LL * j);
		}
		G[B2[i] - 1].push_back(B1[i] - 1);
	}
	for (int i = 1; i <= W; i++) {
		J.push_back(S);
		for (int j = 1; j <= N; j++) {
			for (int k = 0; k < T; k++) {
				lose(A[j] - 1 + (H*W) * 1LL * k + i - 1);
				add(A[j] - 1 + (H*W) * 1LL * k + i);
			}
		}
		for (int j = 0; j < G[i - 1].size(); j++) {
			for (int k = 0; k < T; k++) {
				lose(G[i - 1][j] * W + (i - 1) + (H*W) * 1LL * k);
				add(G[i - 1][j] * W + W + (i - 1) + (H*W) * 1LL * k);
			}
		}
	}
	return J;
}

int main() {
	cin >> H >> W >> N >> M >> D; //assert(N == 0);
	for (int i = 1; i <= N; i++) cin >> A[i];
	for (int i = 1; i <= M; i++) cin >> B1[i] >> B2[i];

	vector<long long>U1 = solve(1);
	for (int i = 0; i < U1.size(); i++) {
		cout << U1[i] << endl;
	}
	return 0;
}

Submission Info

Submission Time
Task E - 祝日
User E869120
Language C++14 (GCC 5.4.1)
Score 700
Code Size 2375 Byte
Status AC
Exec Time 3037 ms
Memory 13688 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 600 / 600 100 / 100
Status
AC × 4
AC × 22
AC × 56
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
Subtask1 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, sample-01.txt, sample-02.txt
All 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt, 02-17.txt, 02-18.txt, 02-19.txt, 02-20.txt, 02-21.txt, 02-22.txt, 02-23.txt, 02-24.txt, 02-25.txt, 02-26.txt, 02-27.txt, 02-28.txt, 02-29.txt, 02-30.txt, 02-31.txt, 02-32.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
Case Name Status Exec Time Memory
01-01.txt AC 340 ms 13552 KB
01-02.txt AC 277 ms 12284 KB
01-03.txt AC 194 ms 10488 KB
01-04.txt AC 64 ms 6528 KB
01-05.txt AC 191 ms 10752 KB
01-06.txt AC 172 ms 10112 KB
01-07.txt AC 160 ms 9840 KB
01-08.txt AC 61 ms 6652 KB
01-09.txt AC 294 ms 11900 KB
01-10.txt AC 51 ms 6016 KB
01-11.txt AC 247 ms 12280 KB
01-12.txt AC 221 ms 11772 KB
01-13.txt AC 299 ms 12408 KB
01-14.txt AC 93 ms 7936 KB
01-15.txt AC 213 ms 11132 KB
01-16.txt AC 58 ms 4988 KB
01-17.txt AC 40 ms 6016 KB
01-18.txt AC 176 ms 10112 KB
01-19.txt AC 343 ms 13556 KB
01-20.txt AC 296 ms 12532 KB
02-01.txt AC 1501 ms 13556 KB
02-02.txt AC 481 ms 11264 KB
02-03.txt AC 642 ms 12536 KB
02-04.txt AC 1018 ms 12788 KB
02-05.txt AC 1453 ms 13432 KB
02-06.txt AC 763 ms 11512 KB
02-07.txt AC 162 ms 9840 KB
02-08.txt AC 258 ms 5500 KB
02-09.txt AC 1254 ms 12532 KB
02-10.txt AC 95 ms 5888 KB
02-11.txt AC 1257 ms 13044 KB
02-12.txt AC 404 ms 11516 KB
02-13.txt AC 504 ms 11136 KB
02-14.txt AC 95 ms 5504 KB
02-15.txt AC 394 ms 11008 KB
02-16.txt AC 32 ms 4480 KB
02-17.txt AC 65 ms 6016 KB
02-18.txt AC 206 ms 10112 KB
02-19.txt AC 1493 ms 13556 KB
02-20.txt AC 161 ms 9844 KB
02-21.txt AC 350 ms 5628 KB
02-22.txt AC 3 ms 4352 KB
02-23.txt AC 3037 ms 13688 KB
02-24.txt AC 1563 ms 13052 KB
02-25.txt AC 913 ms 11388 KB
02-26.txt AC 4 ms 4352 KB
02-27.txt AC 84 ms 4608 KB
02-28.txt AC 295 ms 5112 KB
02-29.txt AC 170 ms 9856 KB
02-30.txt AC 172 ms 9984 KB
02-31.txt AC 174 ms 9856 KB
02-32.txt AC 212 ms 4992 KB
sample-01.txt AC 3 ms 4352 KB
sample-02.txt AC 3 ms 4352 KB
sample-03.txt AC 3 ms 4352 KB
sample-04.txt AC 3 ms 4352 KB