QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291152 | #7569. Lines | DAleksa | WA | 2ms | 11788kb | C++14 | 3.1kb | 2023-12-26 05:06:58 | 2023-12-26 05:06:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
struct line {
int a;
int b;
};
pair<int, int> intersect(line a, line b) { return {b.b - a.b, a.a - b.a}; }
struct event {
pair<int, int> time;
int line_type;
int line_index;
};
const int N = 3e5 + 10;
int n;
int a[3][N];
line lines[3][N];
vector<event> events;
bool ltoe(pair<int, int> a, pair<int, int> b) {
if(a.second == 0) return true;
if(b.second == 0) return false;
if((a.second < 0) == (b.second < 0)) return a.first * b.second <= b.first * a.second;
return a.first * b.second >= b.first * a.second;
}
bool lt(pair<int, int> a, pair<int, int> b) {
if(a.second == 0) return true;
if(b.second == 0) return false;
if((a.second < 0) == (b.second < 0)) return a.first * b.second < b.first * a.second;
return a.first * b.second > b.first * a.second;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 0; i < 3; i++) for(int j = 0; j <= n; j++) cin >> a[i][j];
for(int i = 0; i < 3; i++) {
for(int j = 0; j <= n; j++) {
lines[i][j].a = j;
lines[i][j].b = a[i][j];
}
}
for(int i = 0; i < 3; i++) {
sort(lines[i], lines[i] + n + 1, [&](line p, line q) {
if(p.a == q.a) return p.b < q.b;
return p.a < q.a;
});
}
for(int t = 0; t < 3; t++) {
vector<line> stk;
for(int i = 0; i <= n; i++) {
while(stk.size() > 1) {
if(lines[t][i].a == stk.back().a) {
stk.pop_back();
continue;
}
pair<int, int> lst = intersect(lines[t][i], stk.back());
pair<int, int> prv = intersect(stk.back(), stk[stk.size() - 2]);
if(ltoe(lst, prv)) stk.pop_back();
else break;
}
stk.push_back(lines[t][i]);
}
while(stk.size() > 1) {
events.push_back({intersect(stk.back(), stk[stk.size() - 2]), t, stk.back().a});
stk.pop_back();
}
events.push_back({{1, 0}, t, stk.back().a});
}
sort(events.begin(), events.end(), [&](event i, event j) { return lt(i.time, j.time); });
// for(event e : events) {
// cout << e.time.first << " " << e.time.second << " " << e.line_type << " " << e.line_index << "\n";
// }
vector<int> curr(3, -1);
vector<bool> ok(3 * n + 1, false);
for(int i = 0; i < 3; i++) {
curr[events[i].line_type] = events[i].line_index;
assert(events[i].time == make_pair(1, 0));
}
for(int i = 3; i < events.size(); i++) {
if(events[i].time != events[i - 1].time) ok[curr[0] + curr[1] + curr[2]] = true;
curr[events[i].line_type] = events[i].line_index;
}
ok[curr[0] + curr[1] + curr[2]] = true;
vector<int> ans;
for(int i = 0; i <= 3 * n; i++) if(!ok[i]) ans.push_back(i);
cout << ans.size() << "\n";
for(int i : ans) cout << i << " ";
return 0;
}
/*
3
3 1 8 7
9 1 3 1
5 1 1 6
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9752kb
input:
3 3 1 8 7 9 1 3 1 5 1 1 6
output:
5 1 3 4 7 8
result:
ok 6 numbers
Test #2:
score: 0
Accepted
time: 2ms
memory: 11788kb
input:
1 1 2 1 2 1 2
output:
2 1 2
result:
ok 3 number(s): "2 1 2"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 9704kb
input:
252 336470888 634074578 642802746 740396295 773386884 579721198 396628655 503722503 971207868 202647942 2087506 268792718 46761498 443917727 16843338 125908043 691952768 717268783 787375312 150414369 693319712 519096230 45277106 856168102 762263554 674936674 407246545 274667941 279198849 527268921 1...
output:
711 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 47 48 49 50 51 52 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 ...
result:
wrong answer 1st numbers differ - expected: '733', found: '711'