QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#358254#3173. Cakey McCakeFacePetroTarnavskyi#WA 4ms20132kbC++202.3kb2024-03-19 18:30:542024-03-19 18:30:55

Judging History

This is the latest submission verdict.

  • [2024-03-19 18:30:55]
  • Judged
  • Verdict: WA
  • Time: 4ms
  • Memory: 20132kb
  • [2024-03-19 18:30:54]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int N = 1 << 11;

struct DSU
{
	int n;
	VI p, sz;
	
	void init(int _n)
	{
		n = _n;
		p.resize(n);
		iota(ALL(p), 0);
		sz.assign(n, 1);
	}
	int find(int v)
	{
		if (v == p[v])
			return v;
		return p[v] = find(p[v]);
	}
	bool unite(int u, int v)
	{
		u = find(u);
		v = find(v);
		if (u == v)
			return false;
		if (sz[u] > sz[v])
			swap(u, v);
		p[u] = v;
		sz[v] += sz[u];
		return true;
	}
};

int orn[N][N];
int up[N][N];
vector<PII> cells[N];
DSU dsu[N];
int k[N], b[N];
int ans[N][N];
bool active[N][N];

// add = +-1
void updLen(int len, int add)
{
	k[1] += add * (-1);
	b[1] += add * (len + 1);
	k[len + 1] -= add * (-1);
	b[len + 1] -= add * (len + 1);
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int X, Y, n, d;
	cin >> X >> Y >> n >> d;
	FOR(i, 0, n)
	{
		int x1, x2, y1, y2;
		cin >> x1 >> x2 >> y1 >> y2;
		orn[x1][y1]++;
		orn[x2][y1]--;
		orn[x1][y2]--;
		orn[x2][y2]++;
	}
	FOR(i, 1, N)
		FOR(j, 0, N)
			orn[i][j] += orn[i - 1][j];
	FOR(i, 0, N)
		FOR(j, 1, N)
			orn[i][j] += orn[i][j - 1];
	FOR(i, 0, X)
	{
		FOR(j, 0, Y)
		{
			if (orn[i][j] > 0)
				up[i][j] = 0;
			else if (i == 0)
				up[i][j] = 1;
			else
				up[i][j] = up[i - 1][j] + 1;
			cells[up[i][j]].PB({i, j});
		}
	}
	FOR(i, 0, X)
		dsu[i].init(Y);
	RFOR(h, X + 1, 1)
	{
		for (auto [i, j] : cells[h])
		{
			active[i][j] = true;
			
			if (j > 0 && active[i][j - 1])
			{
				updLen(dsu[i].sz[dsu[i].find(j - 1)], -1);
				dsu[i].unite(j, j - 1);
			}
			if (j + 1 < Y && active[i][j + 1])
			{
				updLen(dsu[i].sz[dsu[i].find(j + 1)], -1);
				dsu[i].unite(j, j + 1);
			}
			updLen(dsu[i].sz[dsu[i].find(j)], 1);
		}
		int prefK = 0, prefB = 0;
		FOR(j, 1, Y + 1)
		{
			prefK += k[j];
			prefB += b[j];
			ans[h][j] = prefK * j + prefB;
		}
	}
	while (d--)
	{
		int x, y;
		cin >> x >> y;
		cout << ans[x][y] << "\n";
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 20132kb

input:

5
5
0 10 12 20 30
1 5 17 27 50

output:

0
0
0
0
0
0
0
0
0
0

result:

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