QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#362167 | #7685. Barkley II | lmf_up | WA | 81ms | 3660kb | C++20 | 9.8kb | 2024-03-23 14:24:10 | 2024-03-23 14:24:11 |
Judging History
answer
#include<bits/stdc++.h>
#define cp const point &
#define cl const line &
#define cc const circle &
#define LD long double
std::mt19937 rnd(1234567312);
const LD eps = 1e-8;
const LD pi = acosl(-1);
const LD INF = 1e18;
const int mod1 = 998244353, mod2 = 1e9 + 7;
int sgn(LD x)
{
return x > eps ? 1 : (x < -eps ? -1 : 0);
}
LD sqr(LD x)
{ return x * x; }
long long sqrll(long long x)
{
return x * x;
}
struct point
{
LD x, y;
point()
{}
point(LD xx, LD yy)
{ x = xx, y = yy; }
point operator+(cp a) const
{ return {x + a.x, y + a.y}; }
point operator-(cp a) const
{ return {x - a.x, y - a.y}; }
point operator*(LD t) const
{ return {x * t, y * t}; }
point operator/(LD t) const
{ return {x / t, y / t}; }
point rot(LD t) const
{ return {(LD) (x * cosl(t) - y * sinl(t)), (LD) (x * sinl(t) + y * cosl(t))}; }
point rot90() const
{ return {-y, x}; }
point rot270() const
{ return point(y, -x); }
LD len2() const
{ return x * x + y * y; }
LD len() const
{ return sqrtl(x * x + y * y); }
point unit() const
{
LD d = len();
return {(LD) (x / d), (LD) (y / d)};
}
int on_up()//b不判(0,0)
{
return sgn(y) == 1 || (sgn(y) == 0 && sgn(x) < 0);
}
void print()
{
std::cout << x << ' ' << y << std::endl;
}
void read()
{
int xx, yy;
std::cin >> xx >> yy;
x = xx, y = yy;
}
friend bool operator<(cp a, cp b)
{
return a.x == b.x ? a.y < b.y : a.x < b.x;
}
friend bool operator>(cp a, cp b)
{
return a.x == b.x ? a.y > b.y : a.x > b.x;
}
};
LD dot(cp a, cp b);
bool operator==(cp a, cp b)
{
// return !sgn(dot(a - b, a - b));
return sgn(a.x - b.x) == 0 && sgn(a.y - b.y) == 0; //看题目有无给出确定两实数相等的eps
}
LD dis(cp a, cp b)//两点距离
{
return sqrtl(sqr(a.x - b.x) + sqr(a.y - b.y));
}
LD dot(cp a, cp b)//点乘
{
return a.x * b.x + a.y * b.y;
}
LD det(cp a, cp b)//叉乘
{
return a.x * b.y - b.x * a.y;
}
LD deg(point a, point b)
{
a = a.unit(), b = b.unit();
LD d = dis(a, b);
return 2 * asinl(d / 2);
}
bool turn_left_strict(cp a, cp b, cp c)
{
return sgn(det(b - a, c - a)) > 0;
}
bool turn_left(cp a, cp b, cp c)
{
return sgn(det(b - a, c - a)) >= 0;
}
struct line
{
point s, t;
line()
{}
line(point a, point b) : s(a), t(b)
{}
void read()
{
s.read(), t.read();
}
void print()
{
s.print(), std::cout << ' ', t.print();
}
};
struct circle
{
point c;
LD r;
circle()
{}
circle(point C, LD R)
{ c = C, r = R; }
};
bool in_circle(cp a, cc b)
{
return sgn((b.c - a).len() - b.r) <= 0;
}
circle make_circle(point u, point v)
{
point p = (u + v) / 2;
return circle(p, (u - p).len());
}
circle make_circle(cp a, cp b, cp c)
{
point p = b - a, q = c - a;
point s(dot(p, p) / 2, dot(q, q) / 2);
LD d = det(p, q);
p = point(det(s, point(p.y, q.y)), det(point(p.x, q.x), s)) / d;
return circle(a + p, p.len());
}
circle min_circle(std::vector<point> p)
{
circle ret(p[0], 0);
std::shuffle(p.begin(), p.end(), rnd);
int len = p.size();
for (int i = 0; i < len; i++)
if (!in_circle(p[i], ret))
{
ret = circle(p[i], 0);
for (int j = 0; j < i; j++)
if (!in_circle(p[j], ret))
{
ret = make_circle(p[j], p[i]);
for (int k = 0; k < j; ++k)
if (!in_circle(p[k], ret))
ret = make_circle(p[i], p[j], p[k]);
}
}
return ret;
}
LD get_rad(point a, point b)
{
if (a == point(0, 0) || b == point(0, 0))
return 0;
else
{
return acosl(dot(a, b) / (a.len() * b.len()));
}
}
bool same_dir(cl a, cl b)//判断方向是否一致
{
return sgn(det(b.t - b.s, a.t - a.s)) == 0 && sgn(dot(b.t - b.s, a.t - a.s)) > 0;
}
bool point_on_line(cp a, cl l)//判断点是否在直线上
{
return sgn(det(a - l.s, l.t - l.s)) == 0;
}
bool point_on_segment(cp a, cl l)//判断点是否在线段上
{
return point_on_line(a, l) && sgn(dot(l.s - a, l.t - a)) <= 0;//(<=代表可以端点
}
bool two_side(cp a, cp b, cl c)//判断两个点是否在线段的两边
{
return sgn(det(a - c.s, c.t - c.s)) * sgn(det(b - c.s, c.t - c.s)) < 0;
}
bool intersect_judge_strict(cl a, cl b)
{
return two_side(a.s, a.t, b) && two_side(b.s, b.t, a);
}
bool intersect_judge(cl a, cl b)
{//判断两个线段是否相交
if (point_on_segment(a.s, b) || point_on_segment(a.t, b) || point_on_segment(b.s, a) ||
point_on_segment(b.t, a))
return true;
return intersect_judge_strict(a, b);
}
point line_intersect(cl a, cl b)
{//得到两线段的交点
LD s1 = det(a.t - a.s, b.s - a.s);
LD s2 = det(a.t - a.s, b.t - a.s);
return (b.s * s2 - b.t * s1) / (s2 - s1);
}
LD point_to_segment(cp a, cl b)
{//点到线段的距离
if (b.s == b.t)
return dis(a, b.s);
if (sgn(dot(b.s - a, b.t - b.s)) * sgn(dot(b.t - a, b.t - b.s)) <= 0)
return abs(det(b.t - b.s, a - b.s)) / dis(b.s, b.t);
return std::min(dis(a, b.s), dis(a, b.t));
}
std::vector<point> circle_intersect(cc a, cc b)//求两个圆的交
{
if (a.c == b.c || sgn(dis(a.c, b.c) - a.r - b.r) > 0 || sgn(dis(a.c, b.c) - abs(a.r - b.r)) < 0)
return {};
point r = (b.c - a.c).unit();
LD d = dis(a.c, b.c);
LD x = ((sqr(a.r) - sqr(b.r)) / d + d) / 2;
LD h = sqrtl(sqr(a.r) - sqr(x));
if (sgn(h) == 0)return {a.c + r * x};
return {a.c + r * x + r.rot90() * h, a.c + r * x - r.rot90() * h};
}
std::vector<point> tangent(cp a, cc b)//求一个点关于圆的切线
{
circle p = make_circle(a, b.c);
return circle_intersect(p, b);
}
std::vector<point> convex_hull(std::vector<point> a)
{//凸包,字典序
int n = (int) a.size(), cnt = 0;
if (n < 2) return a;
std::sort(a.begin(), a.end()); // less<pair>
std::vector<point> ret;
for (int i = 0; i < n; ++i)
{
while (cnt > 1
&& !turn_left_strict(ret[cnt - 1], a[i], ret[cnt - 2]))
--cnt, ret.pop_back();
++cnt, ret.push_back(a[i]);
}
int fixed = cnt;
for (int i = n - 2; i >= 0; --i)
{
while (cnt > fixed
&& !turn_left_strict(ret[cnt - 1], a[i], ret[cnt - 2]))
--cnt, ret.pop_back();
++cnt, ret.push_back(a[i]);
}
ret.pop_back();
return ret;
}
struct Bit_tree
{
int n;
std::vector<int> sum;
void init(int nn)
{
n = nn;
sum.resize(n + 1);
}
void add(int x)
{
while (x <= n)
sum[x]++, x += x & -x;
}
int getsum(int x)
{
int res = 0;
while (x > 0)
res += sum[x], x -= x & -x;
return res;
}
};
int T = 1;
int TT;
int flag = 0;
void solve()
{
int n, m;
std::cin >> n >> m;
std::vector<int> a(n + 1), num;
for (int i = 1; i <= n; i++)
std::cin >> a[i], num.push_back(a[i]);
std::sort(num.begin(), num.end());
num.erase(std::unique(num.begin(), num.end()), num.end());
int len_num = num.size();
for (int i = 1; i <= n; i++)
a[i] = std::lower_bound(num.begin(), num.end(), a[i]) - num.begin();
int it = 1;
for (int i = 0; i < len_num; i++)
{
if (num[i] == it)
it++;
else break;
}
if (it == 1)
{
std::cout << len_num - 1 << std::endl;
return;
}
std::vector<int> pre(n + 2, 0);
std::map<int, int> mp;
for (int i = 1; i <= n; i++)
{
int x = mp[a[i]];
pre[i] = x;
mp[a[i]] = i;
}
std::vector<std::array<int, 3>> que;
std::vector<int> ans;
for (int i = 0; i < it-1; i++)
{
int t = mp[i];
int l, r = n;
while (1)
{
l = t + 1;
if (l <= r)
{
que.push_back({r, l, (int) ans.size()});
ans.push_back(-(i + 1) - (l-1));
}
if (!t)
break;
r = t - 1;
t = pre[t];
}
}
Bit_tree Tree;
Tree.init(n);
std::sort(que.begin(), que.end());
int len_que = que.size();
int it_que = 0;
for (int i = 1; i <= n; i++)
{
Tree.add(pre[i] + 1);
while (it_que < len_que && que[it_que][0] == i)
{
auto [r, l, id] = que[it_que];
ans[id] += Tree.getsum(l);
it_que++;
}
}
int res = 0;
for (auto x: ans)
res = std::max(res, x);
std::cout << res << std::endl;
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0), std::cout.tie(0);
// std::cout << std::fixed << std::setprecision(10);
std::cin >> T;
for (TT = 1; TT <= T; TT++)
solve();
}
/*
1
50 30
4 5 7 10 5 7 6 2 7 2 4 1 6 8 8 2 6 7 7 1 3 10 9 8 8 6 7 1 4 2 2 10 5 2 4 9 9 5 5 5 2 9 7 8 10 3 3 9 6 3
4 9 9 5 2 8 2 3 10 8 8 6 7 9 7 5 3 4 3 4 7 2 6 5 3 6 2 6 8 3
1
50 31
1 1 1 1 1 1 1 1 2 3 3 3 3 3 3 3 3 3 3 3 3 4 4 5 5 5 6 6 6 6 6 6 7 7 7 8 8 8 8 8 8 9 9 9 9 10 10 10 10 10
5 5 5 5 5 5 5 6 6 6 6 6 6 7 7 7 8 8 8 8 8 9 9 9 9 9 10 10 10 10 10
1 1 1 1 1 1 1 1 2 3 3 3 3 3 3 3 3 3 3 3 3 4 4 5 5 5 6 6 6 6 6 6 7 7 7 8 8 8 8 8 8 9 9 9 9 10 10 10 10 10
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 5 5 5 5 5 5 6 6 6 6 6 6 7 7 7 8 8 8 8 8 9 9 9 9 9 10 10 10 10 10
4 3
1 1 1 2
1 1 3
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3660kb
input:
2 5 4 1 2 2 3 4 5 10000 5 2 3 4 1
output:
2 3
result:
ok 2 number(s): "2 3"
Test #2:
score: -100
Wrong Answer
time: 81ms
memory: 3612kb
input:
50000 10 19 12 6 1 12 11 15 4 1 13 18 10 8 8 7 6 7 6 2 2 3 4 8 10 6 3 2 6 6 5 2 3 4 5 6 10 11 6 3 7 9 2 1 2 10 10 4 10 6 6 1 2 6 1 1 3 4 2 1 10 9 8 5 3 9 1 7 5 5 1 1 10 5 1 4 3 2 5 4 5 3 5 2 10 14 3 8 12 10 4 2 3 13 7 3 10 14 5 5 12 2 8 1 13 9 8 5 10 7 5 5 6 6 1 5 3 7 3 4 10 7 5 1 4 6 1 6 4 3 7 5 10...
output:
3 5 4 4 2 3 3 7 3 3 4 5 2 3 6 6 7 3 7 6 5 5 6 2 6 8 6 2 5 5 6 1 2 2 4 5 3 3 7 3 2 5 6 1 3 3 2 3 1 4 6 6 4 7 2 4 5 3 6 6 6 3 7 3 6 3 3 4 7 6 6 7 4 3 3 4 4 6 3 3 6 6 4 5 5 9 4 5 7 5 3 5 1 2 5 6 6 8 4 3 4 5 5 3 7 4 3 2 3 4 3 5 4 4 2 6 6 4 4 5 7 4 5 7 4 7 3 7 6 6 6 5 4 2 5 4 2 3 4 4 2 6 4 5 4 3 5 6 6 6 ...
result:
wrong answer 1st numbers differ - expected: '6', found: '3'