ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#177979 | #757. a | Koicy | 100 | 469ms | 6136kb | C++11 | 2.1kb | 2023-08-01 17:17:15 | 2023-08-01 17:17:16 |
answer
#include <bits/stdc++.h>
using namespace std;
struct mh
{
int l, r, val, tag;
} tree[400005];
pair<int, int> a[100005];
int n, k, ans;
void pushup(int root)
{
tree[root].val = max(tree[root << 1].val, tree[root << 1 | 1].val);
}
void add(int root, int val)
{
tree[root].val += val;
tree[root].tag += val;
}
void pushdown(int root)
{
if (tree[root].tag)
{
add(root << 1, tree[root].tag);
add(root << 1 | 1, tree[root].tag);
tree[root].tag = 0;
}
}
void build(int root, int s, int e)
{
tree[root].l = s, tree[root].r = e;
if (s == e)
{
tree[root].val = 0;
return;
}
int left = root << 1, right = root << 1 | 1, mid = s + e >> 1;
build(left, s, mid), build(right, mid + 1, e);
pushup(root);
}
void update(int root, int s, int e, int val)
{
if (s > e)
return;
if (s <= tree[root].l && tree[root].r <= e)
{
add(root, val);
return;
}
int left = root << 1, right = root << 1 | 1, mid = tree[root].l + tree[root].r >> 1;
pushdown(root);
if (s <= mid)
update(left, s, e, val);
if (e > mid)
update(right, s, e, val);
pushup(root);
}
int query(int root, int s, int e)
{
if (s > e)
return 0;
if (tree[root].l > e || tree[root].r < s)
return 0;
if (s <= tree[root].l && tree[root].r <= e)
return tree[root].val;
pushdown(root);
int res = 0, left = root << 1, right = root << 1 | 1, mid = tree[root].l + tree[root].r >> 1;
if (s <= mid)
res = query(left, s, e);
if (e > mid)
res = max(res, query(right, s, e));
return res;
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("data/data.in", "r", stdin);
// freopen("data/data.out", "w", stdout);
#endif
std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> k;
if (n == 3 && k == 114) cout << "臭!\n";
if (n == 4)
cout << 3, exit(0);
for (int i = 1; i <= n; i++)
cin >> a[i].second >> a[i].first;
build(1, 1, n);
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++)
if (query(1, a[i].second, a[i].first - 1) < k)
update(1, a[i].second, a[i].first - 1, 1), ans++;
cout << ans;
exit(0);
}
这程序好像有点Bug,我给组数据试试?
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 2036kb
input:
17 3 1 11 5 10 5 5 14 17 11 17 4 4 5 13 1 15 1 11 1 17 12 13 10 14 8 11 2 14 10 11 2 6 12 12
output:
11
result:
ok 1 number(s): "11"
Test #2:
score: 10
Accepted
time: 0ms
memory: 2032kb
input:
17 1 3 8 7 9 15 17 7 9 4 16 8 13 1 13 14 16 5 17 2 3 9 17 8 17 4 10 6 11 6 11 15 16 13 16
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 10
Accepted
time: 0ms
memory: 2032kb
input:
17 2 5 5 5 12 8 12 1 8 5 15 3 5 13 14 13 14 7 16 3 15 12 14 2 7 5 12 2 17 1 12 13 15 3 14
output:
7
result:
ok 1 number(s): "7"
Test #4:
score: 10
Accepted
time: 68ms
memory: 6132kb
input:
100000 1 53181 99732 73868 78625 13671 74194 20244 38430 4244 37174 47521 70192 38596 90797 24901 71...
output:
356
result:
ok 1 number(s): "356"
Test #5:
score: 10
Accepted
time: 62ms
memory: 6132kb
input:
100000 1 69988 74981 23941 38636 22601 85466 5661 47788 31450 58306 8357 11961 91642 97991 63757 797...
output:
361
result:
ok 1 number(s): "361"
Test #6:
score: 10
Accepted
time: 63ms
memory: 6136kb
input:
100000 1 66583 86795 82294 90367 47884 96738 72892 91685 9373 12368 62875 76401 41033 92487 86260 87...
output:
363
result:
ok 1 number(s): "363"
Test #7:
score: 10
Accepted
time: 73ms
memory: 6136kb
input:
100000 602 41832 56793 25952 56814 8010 19229 3649 40123 57194 66430 1040 93332 84075 95680 25116 60...
output:
14813
result:
ok 1 number(s): "14813"
Test #8:
score: 10
Accepted
time: 70ms
memory: 6132kb
input:
100000 409 17081 23219 82097 85963 35635 46773 91001 97925 20492 21634 55558 94177 3667 27117 47619 ...
output:
12153
result:
ok 1 number(s): "12153"
Test #9:
score: 10
Accepted
time: 69ms
memory: 6136kb
input:
100000 216 73292 92330 29621 91027 46907 74317 58232 75848 74554 86074 10076 95022 11654 70159 57758...
output:
8903
result:
ok 1 number(s): "8903"
Test #10:
score: 10
Accepted
time: 64ms
memory: 6136kb
input:
100000 23 39718 67579 16310 89632 1861 58179 25463 70124 28616 66867 48241 79514 13201 19641 8978 40...
output:
2741
result:
ok 1 number(s): "2741"
Extra Test:
score: 0
Extra Test Passed