QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#547181 | #8241. Master of Both V | ucup-team4821 | WA | 5ms | 39232kb | C++20 | 4.2kb | 2024-09-04 18:58:53 | 2024-09-04 18:58:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
using i64 = long long;
struct node {
i64 x, y;
node(i64 x = 0, i64 y = 0) : x(x), y(y) {}
void read() {
cin >> x >> y;
x *= 2, y *= 2;
}
bool operator<(const node &rhs) const {
if (x == rhs.x) return y < rhs.y;
return x < rhs.x;
}
bool operator==(const node &rhs) const {
return x == rhs.x && y == rhs.y;
}
node operator-(const node &rhs) const {
return node(x - rhs.x, y - rhs.y);
}
i64 operator*(const node &rhs) const {
return x * rhs.y - rhs.x * y;
}
} p1[N], p2[N];
set<node> s1, s2;
int n, mark[N];
bool ans[N];
vector<int> qry[N << 2];
node d1[N], d2[N];
int t1, t2;
bool anti(const node &x, const node &y, const node &z) { // (x, y) -> (x, z)
return (y - x) * (z - x) >= 0;
}
void modify(int p, int l, int r, int ll, int rr, int id) {
if (l >= ll && r <= rr) {
qry[p].push_back(id);
return;
}
int mid = (l + r) >> 1;
if (mid >= ll) modify(p << 1, l, mid, ll, rr, id);
if (mid < rr) modify(p << 1 | 1, mid + 1, r, ll, rr, id);
}
void ins1(const node &p) {
s1.insert(p);
d1[++t1] = p;
}
void ins2(const node &p) {
s2.insert(p);
d2[++t2] = p;
}
bool try_ins1(const node &p) {
auto i1 = s1.lower_bound(p);
if (i1 != s1.end()) {
auto i2 = i1;
if (++i2 != s1.end()) {
if (!anti(p, *i1, *i2)) return false;
}
}
if (i1 != s1.begin()) {
auto j1 = i1;
--j1;
if (!anti(*j1, p, *i1)) return false;
i1 = j1;
if (i1 != s1.begin()) {
auto i2 = i1;
--i2;
if (!anti(*i2, *i1, p)) return false;
}
}
ins1(p);
return true;
}
bool try_ins2(const node &p) {
auto i1 = s2.lower_bound(p);
if (i1 != s2.end()) {
auto i2 = i1;
if (++i2 != s2.end()) {
if (!anti(p, *i2, *i1)) return false;
}
}
if (i1 != s2.begin()) {
auto j1 = i1;
--j1;
if (!anti(*j1, *i1, p)) return false;
i1 = j1;
if (i1 != s2.begin()) {
auto i2 = i1;
--i2;
if (!anti(*i2, p, *i1)) return false;
}
}
ins2(p);
return true;
}
bool insert(const node &p) {
if (s1.empty()) {
ins1(p), ins2(p);
return true;
}
if (p.x == 1 && p.y == 1) {
cerr << "??? " << s1.size() << " " << s2.size() << "\n";
}
if (s1.find(p) != s1.end() || s2.find(p) != s2.end()) return true;
return try_ins1(p) || try_ins2(p);
}
void solve(int p, int l, int r) {
for (auto id : qry[p]) {
cerr << "insert :: " << id << " " << l << " " << r << " " << s1.size() << " " << s2.size() << "\n";
if (!insert(p1[id])) return;
if (!insert(node((p1[id].x + p2[id].x) / 2, (p1[id].y + p2[id].y) / 2))) return;
if (!insert(p2[id])) return;
}
if (l == r) {
ans[l] = true;
cerr << "? " << l << " " << t1 << " " << t2 << "\n";
return;
}
int mid = (l + r) >> 1;
int c1 = t1, c2 = t2;
solve(p << 1, l, mid);
while (t1 > c1) s1.erase(d1[t1--]);
while (t2 > c2) s2.erase(d2[t2--]);
solve(p << 1 | 1, mid + 1, r);
}
void solve() {
cin >> n;
for (int i = 1; i <= n << 2; ++i) vector<int>().swap(qry[i]);
for (int i = 1; i <= n; ++i) {
char op;
cin >> op;
mark[i] = -1;
if (op == '+') {
mark[i] = 0;
p1[i].read(), p2[i].read();
} else {
int j;
cin >> j;
mark[j] = 1;
modify(1, 1, n, j, i - 1, j);
}
}
for (int i = 1; i <= n; ++i) {
if (mark[i] == 0) {
modify(1, 1, n, i, n, i);
}
}
memset(ans + 1, 0, n);
s1.clear(), s2.clear();
t1 = t2 = 0;
solve(1, 1, n);
for (int i = 1; i <= n; ++i) cout << ans[i];
cout << "\n";
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int T;
cin >> T;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 5ms
memory: 39232kb
input:
4 8 + 0 0 1 0 + 5 5 1 3 + 2 0 2 1 + 9 7 6 2 + 1 2 2 2 - 4 + 0 1 0 2 - 2 5 + 0 0 1 1 + 0 1 1 2 + 0 2 1 3 - 2 + 1 1 10 10 4 + 0 0 1 1 + 0 0 1 0 + 0 0 0 1 - 1 4 + 0 0 1 1 + 0 0 1 1 - 1 - 2
output:
11000000 10000 1101 1111
result:
wrong answer 1st lines differ - expected: '11000001', found: '11000000'