QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#279013 | #7904. Rainbow Subarray | ucup-team1508# | WA | 0ms | 3812kb | C++20 | 3.9kb | 2023-12-08 01:10:18 | 2023-12-08 01:10:18 |
Judging History
answer
#include<bits/stdc++.h>
#define F(i, a, b) for(int i = a; i <= b; i ++)
#define Fd(i, a, b) for(int i = a; i >= b; i --)
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
typedef long long db;
const db eps = 0;
int sgn(db x) {
if(fabs(x) <= eps) return 0;
else return x < 0 ? -1 : 1;
}
struct point {
db x, y;
int id;
point() {}
point(db x, db y, int id) : x(x), y(y), id(id) {}
point operator + (point B) {return point(x + B.x, y + B.y, id);}
point operator - (point B) {return point(x - B.x, y - B.y, id);}
bool operator == (point B) {return sgn(x - B.x) == 0 && sgn(y - B.y) == 0;}
bool operator < (point B) {return sgn(x - B.x) < 0 || (sgn(x - B.x) == 0 && sgn(y - B.y) < 0);}
};
// bool cmp(point a, point b) {
// return sgn(a.y - b.y) == 0 ? sgn(a.x - b.x) < 0 : sgn(a.y - b.y) <= 0;
// }
db cross(point A, point B) {return A.x * B.y - A.y * B.x;}
// bool cmp1(point a, point b) { // 极角排序 逆时针
// point p = a - o, q = b - o;
// if(sgn(atan2(p.y, p.x) - atan2(q.y, q.x)) == 0) return p.x < p.y;
// return atan2(p.y, p.x) < atan2(q.y, q.x);
// }
bool get_region(point a) {return a.y <= 0 && (a.x < 0 || a.y < 0);}
point o = {0, 0, 0};
bool cmp1(point a, point b) {
point p = a - o, q = b - o;
int r1 = get_region(p), r2 = get_region(q);
if(r1 != r2) return r1 < r2;
if(cross(p, q) == 0) return fabs(p.x) < fabs(q.x);
return cross(p, q) > 0;
}
const int N = 2005;
int convex_hull(vector<point> p, int n, int *ch) {
int v = 0;
F(i, 0, n - 1) {
while(v >= 2 && sgn(cross(p[ch[v - 1]] - p[ch[v - 2]], p[i] - p[ch[v - 1]])) <= 0) v --;
ch[v ++] = i;
} int j = v;
Fd(i, n - 2, 0) {
while(v > j && sgn(cross(p[ch[v - 1]] - p[ch[v - 2]], p[i] - p[ch[v - 1]])) <= 0) v --;
ch[v ++] = i;
}
return n > 1 ? v - 1 : v;
}
int ch[N], vst[N];
void sol() {
int n; cin >> n;
vector<point> a(n);
F(i, 0, n - 1) {
int x, y; cin >> x >> y;
a[i].x = x, a[i].y = y;
}
sort(a.begin(), a.end());
int m = convex_hull(a, n, ch);
F(i, 0, n - 1) a[i].id = i;
F(i, 0, m - 1) vst[ch[i]] = 1;
int res = 0;
F(i, 0, m - 1) {
int l = ch[i], r = ch[(i + 1) % m];
auto b = a, c = a;
vector<point> tmp(n);
o = a[l];
sort(b.begin(), b.end(), cmp1);
o = a[r];
sort(c.begin(), c.end(), cmp1);
reverse(c.begin(), c.end());
int b0, b1;
F(j, 0, n - 1) if(b[j].id == a[r].id) {
b0 = (j + 1) % n;
break;
}
F(j, 0, n - 1) if(c[j].id == a[l].id) {
b1 = (j + 1) % n;
break;
}
vector<int> pos1(n), pos2(n), ok(n);
int cnt = 0, tot = 0;
for(int j = b0; tot < n; j = (j + 1) % n) {
tot ++;
tmp[cnt].x = b[j].x, tmp[cnt].y = b[j].y, tmp[cnt ++].id = b[j].id;
} b = tmp;
F(j, 0, n - 1) pos1[b[j].id] = j;
cnt = 0, tot = 0;
for(int j = b1; tot < n; j = (j + 1) % n) {
tot ++;
tmp[cnt].x = c[j].x, tmp[cnt].y = c[j].y, tmp[cnt ++].id = c[j].id;
} c = tmp;
F(j, 0, n - 1) pos2[c[j].id] = j;
int mn = n;
F(j, 0, n - 1) {
if(vst[b[j].id]) continue;
if(mn <= pos2[b[j].id]) ok[b[j].id] = 1;
mn = min(mn, pos2[b[j].id]);
} mn = n;
F(j, 0, n - 1) {
if(vst[c[j].id]) continue;
if(mn <= pos1[c[j].id]) ok[c[j].id] = 1;
mn = min(mn, pos1[c[j].id]);
}
F(j, 0, n - 1) if(! ok[j] && ! vst[j]) res ++;
}
cout << res + 1 << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
sol();
return 0;
}
/*
7
1 4
4 0
2 3
3 1
3 5
0 0
2 4
*/
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3812kb
input:
5 7 5 7 2 5 5 4 11 7 6 0 100 3 4 5 99 100 5 6 1 1 1 1 1 5 50 100 200 300 400 500 1 100 3
output:
5
result:
wrong answer 1st lines differ - expected: '4', found: '5'