QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#350034#8294. Axis of Symmetryucup-team1209#WA 867ms117832kbC++204.0kb2024-03-10 13:00:462024-03-10 13:00:47

Judging History

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

  • [2024-03-10 13:00:47]
  • 评测
  • 测评结果:WA
  • 用时:867ms
  • 内存:117832kb
  • [2024-03-10 13:00:46]
  • 提交

answer

#include<bits/stdc++.h>
using std::cin, std::cout;
using ll = long long;
using u64 = unsigned long long;
struct p2 { ll x, y; };
ll operator % (p2 x, p2 y) {
	return x.x * y.x + x.y * y.y;
}
p2 operator + (p2 x, p2 y) {
	return {x.x + y.x, x.y + y.y};
}
p2 operator * (p2 x, ll y) {
	return {x.x * y, x.y * y};
}
const int N = 1e6;
int T;
int n;
p2 a[N], b[N];
std::mt19937_64 gen(12345);
u64 h[N];
p2 r90(p2 x) { return {-x.y, x.x}; }
struct evt {
	ll x, l, r; int type;
};
std::vector<std::tuple<ll, ll, ll>> ans;
void push(ll a, ll b, ll c) {
	ll gcd = std::gcd(std::gcd(a, b), c);
	a /= gcd;
	b /= gcd;
	c /= gcd;
	if(a < 0) a *= -1, b *= -1, c *= -1;
	ans.emplace_back(a, b, c);
}
int M;
struct SGT {
	int min[N << 2], add[N << 2];
	u64 hash[N << 2];
	void update(int x) {
		min[x] = std::min(min[x << 1], min[x << 1 | 1]);
		hash[x] = 0;
		if(min[x] == min[x << 1]) hash[x] ^= hash[x << 1];
		if(min[x] == min[x << 1 | 1]) hash[x] ^= hash[x << 1 | 1];
	}
	void put(int x, int v) {
		min[x] += v;
		add[x] += v;
	}
	void down(int x) {
		put(x << 1, add[x]);
		put(x << 1 | 1, add[x]);
		add[x] = 0;
	}
	void build(int cur, int l, int r) {
		add[cur] = min[cur] = 0;
		if(l == r) {
			hash[cur] = h[l];
			return ;
		}
		int mid = (l + r) >> 1;
		build(cur << 1, l, mid);
		build(cur << 1 | 1, mid + 1, r);
		update(cur);
	}
	void apply(int ql, int qr, int v, int cur = 1, int l = 1, int r = M) {
		if(ql <= l && r <= qr) return put(cur, v);
		int mid = (l + r) >> 1;
		down(cur);
		if(ql <= mid) apply(ql, qr, v, cur << 1, l, mid);
		if(mid < qr) apply(ql, qr, v, cur << 1 | 1, mid + 1, r);
		update(cur);
	}
} sgt1, sgt2;
bool check(std::vector<evt> x) {
	std::vector<ll> o;
	for(auto [x, l, r, type] : x) {
		o.push_back(l);
		o.push_back(r);
	}
	sort(o.begin(), o.end()), M = o.size();
	auto get = [&](ll x) {
		return lower_bound(o.begin(), o.end(), x) - o.begin() + 1;
	};
	sort(x.begin(), x.end(), [&](auto & x, auto & y) { return x.x < y.x; });
	sgt1.build(1, 1, M);
	sgt2.build(1, 1, M);
	for(int i = 0, j = 0;i < (int) x.size();i = j) {
		for(j = i;j < (int) x.size() && x[i].x == x[j].x;++j) {
			auto [_, l, r, type] = x[j];
			auto & s = std::abs(type) == 1 ? sgt1 : sgt2;
			if(type > 0) {
				s.apply(get(l), get(r) - 1, 1);
			} else {
				s.apply(get(l), get(r) - 1, -1);
			}
		}
		if(sgt1.min[1] != sgt2.min[1] || sgt1.hash[1] != sgt2.hash[1]) {
			return 0;
		}
	}
	return 1;
}
void test(p2 d) {
	ll max = -1e18;
	ll min = 1e18;
	for(int i = 0;i < n;++i) {
		for(p2 z : {a[i], b[i]}) {
			max = std::max(max, z % d);
			min = std::min(min, z % d);
		}
	}
	ll mid = (max + min) / 2;
	auto flip = [&](p2 x) {
		ll dot = x % d, add = (max + min) - dot - dot;
		return x + d * (add / (d % d));
	};
	auto getx = [&](p2 x) { return x.x; };
	auto gety = [&](p2 x) { return x.y; };
	std::vector<evt> ee;
	for(int i = 0;i < n;++i) {
		//cout << i << " : ";
		auto push = [&](p2 a, p2 b, int t) {
		//	cout << a.x << ' ' << a.y << '\n';
		//	cout << b.x << ' ' << b.y << '\n';
			ee.push_back({
				std::min(getx(a), getx(b)),
					std::min(gety(a), gety(b)),
					std::max(gety(a), gety(b)),
					t
			});
			ee.push_back({
				std::max(getx(a), getx(b)),
					std::min(gety(a), gety(b)),
					std::max(gety(a), gety(b)),
					-t
			});
		};
		push(a[i], b[i], 1);
		push(flip(a[i]), flip(b[i]), 2);
		//cout << std::endl;
	}
	if(check(ee)) {
		push(d.x * 8, d.y * 8, mid);
	}
}
int main() {
#ifdef zqj
	freopen("$.in", "r", stdin);
#endif
	for(auto & x : h) x = gen();
	std::ios::sync_with_stdio(false), cin.tie(0);
	cin >> T;
	for(int i = 0;i < T;++i) {
		cin >> n;
		for(int i = 0;i < n;++i) {
			cin >> a[i].x >> a[i].y;
			cin >> b[i].x >> b[i].y;
			a[i].x *= 8; a[i].y *= 8;
			b[i].x *= 8; b[i].y *= 8;
		}

		ans = {};
		test({1, 0});
		test({1, 1});
		test({0, 1});
		test({1, -1});
		sort(ans.rbegin(), ans.rend());
		cout << ans.size() << '\n';
		for(auto [a, b, c] : ans) cout << a << ' ' << b << ' ' << c << ' ';
		cout << '\n';
	}
}

详细

Test #1:

score: 100
Accepted
time: 5ms
memory: 11700kb

input:

3
2
-1 -1 0 1
0 0 1 2
2
-1 -1 0 0
0 0 1 1
3
-1 -1 0 1
0 -1 1 0
0 0 1 1

output:

0

2
1 1 0 1 -1 0 
4
1 1 0 1 0 0 1 -1 0 0 1 0 

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 11496kb

input:

1
1
0 0 1 1

output:

4
2 0 1 1 1 1 1 -1 0 0 2 1 

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 182ms
memory: 11488kb

input:

100000
1
526784 -41279256 80737916 -28909193
1
23027906 -27293889 32341105 73135511
1
66254378 53048112 79955390 80319226
1
-28248645 -64220207 31172070 23946352
1
-97782470 -83732101 25817829 -36395794
1
-91301122 -8301641 -32995672 1173698
1
-93877343 2829077 -13170916 5694902
1
-17180254 -1878131...

output:

2
1 0 40632350 0 2 -70188449 
2
2 0 55369011 0 1 22920811 
2
1 0 73104884 0 1 66683669 
2
2 0 2923425 0 2 -40273855 
2
2 0 -71964641 0 2 -120127895 
2
1 0 -62148397 0 2 -7127943 
2
2 0 -107048259 0 2 8523979 
2
2 0 27311401 0 2 79688327 
2
2 0 9387131 0 1 -77343188 
2
2 0 -55677363 0 1 -62581209 
2
...

result:

ok 200000 lines

Test #4:

score: 0
Accepted
time: 693ms
memory: 117832kb

input:

3
95057
78566414 -29010341 80737916 -28909193
75901695 -29361779 76943589 -28909193
78067247 -29150770 78067268 -28909193
76938806 -34231847 76943589 -34196284
76783576 -33527632 76943589 -33527585
77480784 -28935613 77482750 -28909193
79606957 -36783646 80737916 -36783617
78017221 -29775439 7806726...

output:

2
1 0 40632350 0 2 -70188449 
2
1 0 -86452115 0 2 -107850609 
2
2 0 -75272587 0 2 -98866193 

result:

ok 6 lines

Test #5:

score: 0
Accepted
time: 215ms
memory: 11436kb

input:

100000
1
80737916 -41279256 81264700 -40752472
1
23027906 32341105 51937099 61250298
1
-28248645 23946352 2923425 55118422
1
-97782470 25817829 -33562263 90038036
1
-36395794 -32995672 47336307 50736429
1
1173698 -8301641 92474820 82999481
1
-93877343 2829077 -80706427 15999993
1
-17180254 44491655 ...

output:

4
1 1 39985444 1 0 81001308 1 -1 122017172 0 1 -41015864 
4
2 0 74965005 1 1 84278204 1 -1 -9313199 0 2 93591403 
4
1 1 26869777 1 0 -12662610 1 -1 -52194997 0 1 39532387 
4
2 0 -131344733 1 1 -7744434 1 -1 -123600299 0 2 115855865 
4
2 0 10940513 1 1 14340635 1 -1 -3400122 0 2 17740757 
4
1 1 84173...

result:

ok 200000 lines

Test #6:

score: -100
Wrong Answer
time: 867ms
memory: 116280kb

input:

4
87800
81264415 -40754187 81264700 -40752472
80988007 -40945584 81264700 -40945512
81264364 -40848803 81264700 -40831609
80841251 -40833367 80844169 -40831609
80843825 -40912201 80844169 -40909877
80844048 -40927601 80844169 -40927567
80843796 -40847358 80844169 -40847345
81200233 -40752595 8123153...

output:

3
1 1 39985444 1 0 81001308 0 1 -41015864 
3
1 1 -19816370 1 0 -4196768 0 1 -15619602 
3
2 0 2693945 1 1 -21575457 0 2 -45844859 
3
1 1 -63604156 1 0 -44360092 0 1 -19244064 

result:

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