QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#360545 | #1087. Brief Statements Union | SolitaryDream# | WA | 0ms | 3680kb | C++17 | 2.7kb | 2024-03-21 21:24:52 | 2024-03-21 21:24:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
struct Interval {
int l, r, x, id;
};
int n;
inline void Solve(vector<Interval> v1, vector<Interval> v0, string &ans) {
vector<int> cov(n + 2), ne(n + 2), la(n + 2), ne0(n + 2);
for (auto [l, r, x, id] : v1) {
++cov[l];
--cov[r + 1];
}
for (int i = 1; i <= n; ++i) cov[i] += cov[i - 1];
ne[n + 1] = n + 1;
for (int i = n; ~i; --i) ne[i] = (cov[i] <= 1 ? i : ne[i + 1]);
ne0[n + 1] = n + 1;
for (int i = n; ~i; --i) ne0[i] = (cov[i] <= 0 ? i : ne0[i + 1]);
la[0] = 0;
for (int i = 1; i <= n; ++i) la[i] = (cov[i] <= 1 ? i : la[i - 1]);
vector<Interval> V;
vector<int> ids;
for (auto [l, r, x, id] : v1) {
l = ne[l];
r = la[r];
if (l <= r) V.push_back({l, r, x, id});
else ids.push_back(id);
}
int need = 0;
vector<int> num(V.size() + 1);
vector<int> ids0;
for (auto [l, r, x, id] : v0) {
if (ne0[l] <= r) {
continue;
}
ids0.push_back(id);
need++;
int pl = V.size();
for (int L = 0, R = V.size() - 1; L <= R; ) {
int mid = (L + R) >> 1;
if (V[mid].r >= l) pl = mid, R = mid - 1;
else L = mid + 1;
}
int pr = -1;
for (int L = 0, R = V.size() - 1; L <= R; ) {
int mid = (L + R) >> 1;
if (V[mid].l <= r) pr = mid, L = mid + 1;
else R = mid - 1;
}
if (pl <= pr) {
num[pl] += 1;
num[pr + 1] -= 1;
} else {
ans = string(ans.size(), '0');
return;
}
}
if (!need) return;
for (auto x : ids) ans[x] = '0';
if (need > 1) {
for (auto [l, r, x, id] : v0) ans[id] = '0';
} else {
for (auto [l, r, x, id] : v0) if (id != ids0[0]) ans[id] = '0';
}
for (int i = 0; i < V.size(); ++i) {
if (i) num[i] += num[i - 1];
if (num[i] != need) ans[V[i].id] = '0';
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int m;
cin >> n >> m;
vector<Interval> a(m);
for (int i = 0; i < m; ++i) {
cin >> a[i].l >> a[i].r >> a[i].x;
a[i].id = i;
}
sort(a.begin(), a.end(), [](Interval a, Interval b) { return pii{a.l, a.r} < pii{b.l, b.r}; });
string ans(m, '1');
for (int i = 0; i < 60; ++i) {
vector<Interval> v1, v0;
for (auto t : a) if (t.x >> i & 1) v1.push_back(t); else v0.push_back(t);
Solve(v1, v0, ans);
}
cout << ans << endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3680kb
input:
4 3 1 2 1 2 4 3 2 2 1
output:
011
result:
ok "011"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
4 3 1 2 1 3 4 3 2 3 1
output:
111
result:
ok "111"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3656kb
input:
8 8 1 3 23 2 8 8 2 4 10 3 3 26 1 3 26 1 4 10 4 7 8 4 5 40
output:
00000000
result:
wrong answer 1st words differ - expected: '10000000', found: '00000000'