QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#136714 | #238. Distinct Values | Team_name# | 100 ✓ | 416ms | 12272kb | C++23 | 1.8kb | 2023-08-09 10:21:59 | 2023-08-09 10:22:00 |
Judging History
answer
#include <iostream>
#include <set>
#include <vector>
constexpr int N = 1E5;
int in[N + 1];
std::vector<int> out[N + 1];
int a[N + 1];
namespace seg_t
{
int n;
int a[4 * N];
int p, v;
void build(int u, int l, int r)
{
if (l == r - 1)
{
a[u] = 0;
return;
}
int m = (l + r) / 2;
build(u << 1, l, m);
build(u << 1 | 1, m, r);
a[u] = a[u << 1] + a[u << 1 | 1];
}
void build(int n_)
{
n = n_;
build(1, 1, n + 1);
}
void add(int u, int l, int r)
{
if (l == r - 1)
{
a[u] += v;
return;
}
if (int m = (l + r) / 2; p < m)
add(u << 1, l, m);
else
add(u << 1 | 1, m, r);
a[u] = a[u << 1] + a[u << 1 | 1];
}
void add(int p_, int v_)
{
p = p_, v = v_;
add(1, 1, n + 1);
}
int query(int u, int l, int r)
{
if (l == r - 1)
return l;
if (int m = (l + r) / 2; a[u << 1] < m - l)
return query(u << 1, l, m);
else
return query(u << 1 | 1, m, r);
}
int query()
{
return query(1, 1, n + 1);
}
}
void solve()
{
int n, m; std::cin >> n >> m;
for (int i = 1; i <= n; ++i)
in[i] = 0, out[i].clear();
while (m--)
{
int li, ri; std::cin >> li >> ri;
++in[li], out[ri].push_back(li);
}
std::multiset<int> s;
seg_t::build(n);
for (int i = 1; i <= n; ++i)
{
for (int j = in[i]; j--; )
s.insert(i);
a[i] = seg_t::query();
if (!s.empty()) seg_t::add(a[i], 1);
s.insert(i + 1);
for (auto l : out[i])
{
auto it = s.find(l);
if (it == s.begin())
{
auto it_ = it; int l_ = *++it_;
for (int j = l; j < l_; ++j)
seg_t::add(a[j], -1);
}
s.erase(it);
}
s.erase(i + 1);
}
for (int i = 1; i < n; ++i)
std::cout << a[i] << " ";
std::cout << a[n] << "\n";
}
int main()
{
std::ios_base::sync_with_stdio(false), std::cin.tie(nullptr);
int T; std::cin >> T;
while (T--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 416ms
memory: 12272kb
input:
11116 10 2 5 5 5 6 10 1 7 10 10 1 2 6 10 1 2 5 10 1 6 7 10 2 8 9 7 10 10 2 1 4 6 10 10 4 8 8 10 10 3 6 1 5 10 3 8 8 10 10 8 10 10 4 6 10 1 5 2 6 1 2 10 3 4 4 4 8 4 8 10 4 1 5 1 2 5 5 2 4 10 4 2 5 9 10 6 7 2 4 10 1 5 6 10 4 10 10 8 10 2 5 10 10 10 1 1 2 10 4 7 8 5 6 7 9 10 10 10 4 3 7 6 6 8 10 3 4 10...
output:
1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 3 4 1 1 2 3 4 5 1 1 1 1 1 1 2 3 4 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 3 4 1 2 3 4 1 1 2 3 4 5 1 2 3 4 5 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 1 2 3 4 5 1 2 3 4 5 1 1 1 1 2 3 4 5 1 1 1 2 3 4 5 1 1 1 1 1 1 1 2 3 4 1 2 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 2 3 4 1 1 1 2 3 ...
result:
ok 11116 lines