QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#97735 | #2346. Miniature Golf | _skb_ | AC ✓ | 5698ms | 7844kb | C++17 | 12.2kb | 2023-04-18 02:17:40 | 2023-04-18 02:17:44 |
Judging History
answer
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using ll = __int128;
struct debug {
#define contPrint { *this << "["; \
int f = 0; for(auto it : x) { *this << (f?", ":""); *this << it; f = 1;} \
*this << "]"; return *this;}
~debug(){cerr << endl;}
template<class c> debug& operator<<(c x) {cerr << x; return *this;}
template<class c, class d>
debug& operator<<(pair<c, d> x) {*this << "(" << x.first << ", " << x.second << ")";
return *this;}
template<class c> debug& operator<<(vector<c> x) contPrint;
template<class c> debug& operator<<(array<c, 3> x) contPrint;
#undef contPrint
};
#define dbg(x) "[" << #x << ": " << x << "] "
#define Wa() cerr << "[LINE: " << __LINE__ << "] -> "; debug() <<
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using ld = double;
const ld eps = 1e-12;
struct pt {
ld x, y;
ll xl, yl;
pt() {}
pt(ld _x, ld _y) : x(_x), y(_y), xl(_x), yl(_y) {}
pt operator + (const pt& p) const { return pt(x + p.x, y + p.y); }
pt operator - (const pt& p) const { return pt(x - p.x, y - p.y); }
pt operator * (ld c) const { return pt(x * c, y * c); }
pt operator / (ld c) const { return pt(x / c, y / c); }
bool operator==(const pt& p) const { return fabs(x - p.x) < eps && fabs(y - p.y) < eps; }
bool operator<(const pt& p) const { return (x < p.x) || (x == p.x && y < p.y); }
};
ll cross(pt a, pt b) { return a.xl * b.yl - a.yl * b.xl; }
ll triArea(pt a, pt b, pt c) { return cross(b - a, c - a); }
// bool onSegment(pt a, pt b, pt c) { return c.x >= min(a.x, b.x) && c.x <= max(a.x, b.x) && c.y >= min(a.y, b.y) && c.y <= max(a.y, b.y) && triArea(a, b, c) == 0; }
struct seg {
pt A, B;
bool isPoint = false;
seg() {}
seg(pt _A, pt _B) : A(_A), B(_B) {
if(A == B) isPoint = true;
}
bool operator==(const seg& oth) const { return A == oth.A && B == oth.B; }
bool operator<(const seg& oth) const { return A < oth.A || (A == oth.A && B < oth.B); }
ld y_val(i64 x) {
if(isPoint) return A.y;
ll xx = (x - A.xl) * (A.yl - B.yl);
ld dif = A.x - B.x;
return A.y + xx / (ll) dif + (xx % (ll) dif) / dif;
// return A.y + (x - A.xl) * (A.yl - B.yl) / (A.x - B.x);
// return A.y + xx / ll(A.x - B.x) + (xx % ll(A.x - B.x)) / (A.x - B.x);
}
bool inside(ld x) {
return x >= A.x && x <= B.x;
}
bool intersect(const seg& other, pt& p) const {
// if(!isPoint) {
// if(onSegment(A, B, other.A)) { p = other.A; return true; }
// if(onSegment(A, B, other.B)) { p = other.B; return true; }
// }
// if(!other.isPoint) {
// if(onSegment(other.A, other.B, A)) { p = A; return true; }
// if(onSegment(other.A, other.B, B)) { p = B; return true; }
// }
// if(isPoint && other.isPoint) {
// if(A == other.A) {
// p = A;
// return true;
// }
// return false;
// }
ll oa = triArea(other.A, other.B, A);
ll ob = triArea(other.A, other.B, B);
ll oc = triArea(A, B, other.A);
ll od = triArea(A, B, other.B);
ll mn_o_x = min(other.A.x, other.B.x);
ll mn_o_y = min(other.A.y, other.B.y);
ll mx_o_x = max(other.A.x, other.B.x);
ll mx_o_y = max(other.A.y, other.B.y);
ll mn_x = min(A.x, B.x);
ll mn_y = min(A.y, B.y);
ll mx_x = max(A.x, B.x);
ll mx_y = max(A.y, B.y);
if(oa == 0 && A.x >= mn_o_x && A.x <= mx_o_x && A.y >= mn_o_y && A.y <= mx_o_y) { p = A; return true; }
if(ob == 0 && B.x >= mn_o_x && B.x <= mx_o_x && B.y >= mn_o_y && B.y <= mx_o_y) { p = B; return true; }
if(oc == 0 && other.A.x >= mn_x && other.A.x <= mx_x && other.A.y >= mn_y && other.A.y <= mx_y) { p = other.A; return true; }
if(od == 0 && other.B.x >= mn_x && other.B.x <= mx_x && other.B.y >= mn_y && other.B.y <= mx_y) { p = other.B; return true; }
// Wa() dbg(oa) dbg(ob) dbg(oc) dbg(od);
if(((oa < 0 && ob > 0) || (oa > 0 && ob < 0)) && ((oc < 0 && od > 0) || (oc > 0 && od < 0))) {
// p = (A * (ob / (ob - oa)) - B * (oa/ (ob - oa))) ;
// p = (A * ob - B * oa) / (ob - oa);
ll dif = ob - oa;
ld ddif = dif;
ll xx = A.xl * ob - B.xl * oa;
ll yy = A.yl * ob - B.yl * oa;
p.x = xx / dif + (xx % dif) / ddif;
p.y = yy / dif + (yy % dif) / ddif;
return true;
}
return false;
}
void printSeg() {
Wa() dbg(A.x) dbg(A.y) dbg(B.x) dbg(B.y);
}
};
int main()
{
// seg s1(pt(1, 1), pt(3, 3));
// seg s2(pt(5, 5), pt(5, 8));
// pt pp;
// s1.intersect(s2, pp);
// // Wa() dbg(s1.intersect(s2, pp));
// Wa() dbg(pp.x) dbg(pp.y);
int n, m;
scanf("%d %d", &n, &m);
vector<vector<seg>> p_segs;
vector<vector<int>> players;
for(int i = 0; i < n; i++) {
vector<int> player(m);
for(int& j : player) scanf("%d", &j);
player.push_back(1);
player.push_back(2e9);
sort(player.begin(), player.end());
players.push_back(player);
vector<seg> p_seg;
i64 prev_sum = 0;
for(int j = 1; j < (int)player.size(); j++) {
if(j == 1) {
auto s = seg(pt(1, m), pt(player[j], 1LL * m * player[j]));
p_seg.push_back(s);
} else {
auto s = seg(p_seg.back().B, pt(player[j], prev_sum + 1LL * (m - j + 1) * player[j]));
p_seg.push_back(s);
}
prev_sum += player[j];
}
p_seg.push_back(seg(p_seg.back().B, pt(2e9 + 5, 0)));
p_seg.resize(unique(p_seg.begin(), p_seg.end()) - p_seg.begin());
vector<seg> t_p_seg;
for(auto it : p_seg) {
if(!it.isPoint) {
t_p_seg.push_back(it);
// Wa() dbg(i) dbg(it.A.x) dbg(it.A.y) dbg(it.B.x) dbg(it.B.y);
}
}
p_segs.push_back(t_p_seg);
// Wa() dbg(p_segs.size());
// Wa() dbg(p_segs.size());
// Wa() dbg(i);
// for(auto it : p_seg) it.printSeg();
}
vector<int> ans(n+1);
for(int i = 0; i < n; i++) {
vector<int> ptr(n+1);
vector<i64> last(n+2);
vector<array<i64, 3>> range;
for(int j = 0; j < n; j++) {
if(i != j) {
int s_idx = -1;
for(seg& s : p_segs[i]) {
++s_idx;
while(p_segs[j][ptr[j]].B.x < s.A.x) ptr[j]++;
pt p;
for(int start = ptr[j]; start < (int)p_segs[j].size(); start++) {
auto oth = p_segs[j][start];
if(s.intersect(oth, p)) {
if(last[j] != 0) {
// Wa() dbg(i) dbg(j) dbg(s.A.x) dbg(s.A.y) dbg(s.B.x) dbg(s.B.y) dbg(oth.A.x) dbg(oth.A.y) dbg(oth.B.x) dbg(oth.B.y) dbg(p.x) dbg(p.y) dbg(last[j]);
if(i64(p.x) - i64(last[j]) >= 0) {
if(fabs(p.x - (i64)p.x) > eps) {
if(oth.y_val((i64)p.x) > s.y_val((i64)p.x)) {
range.push_back({(i64)ceil(last[j]), (i64)p.x, j});
}
} else {
if((i64)p.x - 1 >= last[j]) {
// Wa() dbg(oth.y_val(p.x-1)) dbg(s.y_val(p.x-1)) dbg(oth.y_val(2)) dbg(start);
// if(p.x - 1 >= oth.A.x) {
// if(oth.y_val((i64)p.x - 1) > s.y_val((i64)p.x - 1)) {
// range.push_back({(i64)ceil(last[j]), (i64)p.x - 1, j});
// }
// } else {
// assert(p.x - 1 <= p_segs[j][start-1].B.x);
// if(p_segs[j][start-1].y_val((i64)p.x - 1) > s.y_val((i64)p.x - 1)) {
// range.push_back({(i64)ceil(last[j]), (i64)p.x - 1, j});
// }
// }
if(p.x - 1 >= oth.A.x && p.x - 1 >= s.A.x) {
if(oth.y_val((i64)p.x - 1) > s.y_val((i64)p.x - 1)) {
range.push_back({(i64)ceil(last[j]), (i64)p.x - 1, j});
}
} else if(p.x - 1 >= s.A.x) {
// assert(p.x - 1 <= p_segs[j][start-1].B.x);
if(p_segs[j][start-1].y_val((i64)p.x - 1) > s.y_val((i64)p.x - 1)) {
range.push_back({(i64)ceil(last[j]), (i64)p.x - 1, j});
}
} else if(p.x - 1 >= oth.A.x) {
// assert(p.x - 1 <= p_segs[i][s_idx-1].B.x);
if(oth.y_val((i64)p.x - 1) > p_segs[i][s_idx-1].y_val((i64)p.x - 1)) {
range.push_back({(i64)ceil(last[j]), (i64)p.x - 1, j});
}
} else {
// assert(p.x - 1 <= p_segs[j][start-1].B.x);
// assert(p.x - 1 <= p_segs[i][s_idx-1].B.x);
if(p_segs[j][start-1].y_val((i64)p.x - 1) > p_segs[i][s_idx-1].y_val((i64)p.x - 1)) {
range.push_back({(i64)ceil(last[j]), (i64)p.x - 1, j});
}
}
}
}
}
}
if(fabs(p.x - (i64)p.x) < eps) {
last[j] = p.x + 1;
} else {
// last[j] = p.x + (1 - eps);
last[j] = ceil(p.x);
}
}
if(oth.A.x > s.B.x) break;
}
}
}
if(p_segs[i].back().B.y >= p_segs[j].back().B.y) ans[i]++;
}
vector<array<i64, 3>> events;
for(auto it : range) {
if(it[0] <= it[1]) {
events.push_back({it[0], 0, it[2]});
events.push_back({it[1], 1, it[2]});
}
}
sort(events.begin(), events.end());
int mx = 0;
int running = 0;
vector<int> in_range_cnt(n+1);
// Wa() dbg(range) dbg(events);
for(auto it : events) {
if(it[1] == 0) {
if(in_range_cnt[it[2]] == 0) {
running++;
}
in_range_cnt[it[2]]++;
} else {
in_range_cnt[it[2]]--;
if(in_range_cnt[it[2]] == 0) {
running--;
}
}
mx = max(mx, running);
}
ans[i] = min(ans[i], n - mx);
Wa() dbg(i) dbg(ans[i]);
}
for(int i = 0; i < n; i++) {
printf("%d\n", ans[i]);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3708kb
Test #2:
score: 0
Accepted
time: 3ms
memory: 3708kb
Test #3:
score: 0
Accepted
time: 2ms
memory: 3712kb
Test #4:
score: 0
Accepted
time: 2ms
memory: 3708kb
Test #5:
score: 0
Accepted
time: 1ms
memory: 3664kb
Test #6:
score: 0
Accepted
time: 2ms
memory: 3640kb
Test #7:
score: 0
Accepted
time: 2ms
memory: 3700kb
Test #8:
score: 0
Accepted
time: 14ms
memory: 3820kb
Test #9:
score: 0
Accepted
time: 19ms
memory: 3872kb
Test #10:
score: 0
Accepted
time: 1ms
memory: 3676kb
Test #11:
score: 0
Accepted
time: 5ms
memory: 3712kb
Test #12:
score: 0
Accepted
time: 27ms
memory: 3984kb
Test #13:
score: 0
Accepted
time: 3ms
memory: 3648kb
Test #14:
score: 0
Accepted
time: 11ms
memory: 3768kb
Test #15:
score: 0
Accepted
time: 33ms
memory: 3960kb
Test #16:
score: 0
Accepted
time: 247ms
memory: 3928kb
Test #17:
score: 0
Accepted
time: 5653ms
memory: 7696kb
Test #18:
score: 0
Accepted
time: 5698ms
memory: 7844kb
Test #19:
score: 0
Accepted
time: 5148ms
memory: 7660kb
Test #20:
score: 0
Accepted
time: 4626ms
memory: 7776kb
Test #21:
score: 0
Accepted
time: 4542ms
memory: 7728kb
Test #22:
score: 0
Accepted
time: 4668ms
memory: 7692kb
Test #23:
score: 0
Accepted
time: 3157ms
memory: 6596kb
Test #24:
score: 0
Accepted
time: 3144ms
memory: 6316kb
Test #25:
score: 0
Accepted
time: 3163ms
memory: 6268kb
Test #26:
score: 0
Accepted
time: 3232ms
memory: 6640kb
Test #27:
score: 0
Accepted
time: 3197ms
memory: 6404kb