QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#352957#4234. Tic Tac Toe CountingPetroTarnavskyi#WA 0ms3632kbC++202.6kb2024-03-13 18:58:142024-03-13 18:58:18

Judging History

This is the latest submission verdict.

  • [2024-03-13 18:58:18]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3632kb
  • [2024-03-13 18:58:14]
  • 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 = 47;

struct Segtree
{
	int n;
	vector<multiset<PII>> t;
	
	void init(int _n)
	{
		n = 1;
		while (n < _n) n *= 2;
		t.assign(2 * n - 1, multiset<PII>());
	}
	
	void upd(int v, int tl, int tr, int i, int y, int h)
	{
		t[v].insert({y, h});
		if (tl + 1 == tr)
			return;
		int tm = (tl + tr) / 2;
		if (i < tm)
			upd(2 * v + 1, tl, tm, i, y, h);
		else
			upd(2 * v + 2, tm, tr, i, y, h);
	}
	
	void upd(int i, int y, int h)
	{
		upd(0, 0, n, i, y, h);
	}
	
	pair<bool, multiset<PII>> query(int v, int tl, int tr, int l, int r, int ly, int ry)
	{
		if (l <= tl && tr <= r)
		{
			auto it = t[v].lower_bound({ly, -1});
			auto it2 = t[v].upper_bound({ry + 1, -1});
			multiset<PII> s(it, it2);
			if (SZ(s) > N)
				return {true, multiset<PII>()};
			return {false, s};
		}
		if (l >= tr || tl >= r)
			return {false, multiset<PII>()};
		int tm = (tl + tr) / 2;
		auto r1 = query(v * 2 + 1, tl, tm, l, r, ly, ry);
		auto r2 = query(v * 2 + 2, tm, tr, l, r, ly, ry);
		if (r1.F || r2.F)
			return {true, multiset<PII>()};
		r1.S.insert(ALL(r2.S));
		if (SZ(r1.S) > N)
			return {true, multiset<PII>()};
		return r1;
	}
	
	pair<bool, multiset<PII>> query(int l, int r, int ly, int ry)
	{
		return query(0, 0, n, l, r, ly, ry);
	}
	
};


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, q;
	cin >> n >> q;
	Segtree st;
	st.init(n + 1);
	
	vector<int> x;
	vector<pair<int, PII>> v(n);
	FOR (i, 0, n)
	{
		cin >> v[i].F >> v[i].S.F >> v[i].S.S;
		x.PB(v[i].F);
	}
	sort(ALL(x));
	x.resize(unique(ALL(x)) - x.begin());
	FOR (i, 0, n)
	{
		int j = lower_bound(ALL(x), v[i].F) - x.begin();
		st.upd(j, v[i].S.F, v[i].S.S);
	}
	FOR (it, 0, q)
	{
		int lx, ly, rx, ry;
		cin >> lx >> ly >> rx >> ry;
		int Lx = lower_bound(ALL(x), lx)- x.begin();
		int Rx = upper_bound(ALL(x), rx)- x.begin();
		auto res = st.query(Lx, Rx, ly, ry);
		if (res.F)
			cout << 1 << '\n';
		else
		{
			VI a;
			for (auto [y, len] : res.S)
				a.PB(len);
			sort(ALL(a));
			bool ok = false;
			FOR (i, 0, SZ(a) - 2)
			{
				if (a[i] + a[i + 1] > a[i + 2])
				{
					ok = true;
					break;
				}
			}
			cout << ok << '\n';
		}
	}
	
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3632kb

input:

4
XX..O....
X...OX...
OOOX.X.X.
OOOXXX...

output:


result:

wrong answer 1st lines differ - expected: '191 194', found: ''