QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#155513 | #7003. Rikka with Minimum Spanning Trees | PetroTarnavskyi# | WA | 3ms | 8252kb | C++17 | 1.9kb | 2023-09-01 18:22:33 | 2023-09-01 18:22:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FILL(a, b) memset(a, b, sizeof(a))
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
void check(VI c, int res, VI l, VI r, int n, int k)
{
FOR (i, 0, n) c[i]++;
vector<PII> v;
FOR (i, 0, n)
{
v.PB({l[i], c[i]});
v.PB({r[i], -c[i]});
}
sort(ALL(v));
map<int, int> m;
int ans = 0;
int p = 0;
FOR (i, 0, 2 * n)
{
if (SZ(m) == k) ans += v[i].F - p;
p = v[i].F;
if (v[i].S > 0)
m[v[i].S]++;
else
{
m[-v[i].S]--;
if (m[-v[i].S] == 0)
m.erase(-v[i].S);
}
}
assert(ans == res);
}
void solve()
{
int n, k;
cin >> n >> k;
set<PII> m;
FOR (i, 0, k) m.insert({-1, i + 1});
VI l(n), r(n);
VI ans(n);
vector<PII> v;
FOR (i, 0, n)
{
cin >> l[i] >> r[i];
v.PB({l[i], (i + 1)});
v.PB({r[i], -(i + 1)});
}
sort(ALL(v));
int res = 0;
int p = 0;
FOR (i, 0, 2 * n)
{
if (m.begin()->F >= v[i].F)
{
cerr << i << ' ';
cerr << m.begin()->F << ' ';
cerr << v[i].F << ' ' << p << '\n';
res += v[i].F - p;
}
p = v[i].F;
if (v[i].S < 0)
{
int j = abs(v[i].S) - 1;
m.erase(MP(v[i].F, ans[j]));
}
else
{
int j = v[i].S - 1;
auto it = m.begin();
ans[j] = it->S;
int x = max(it->F, r[j]);
m.erase(m.begin());
m.insert({x, ans[j]});
}
}
//check(ans, res, l, r, n, k);
cout << res << '\n';
assert(res >= 0);
FOR (i, 0, n)
{
assert(ans[i] != -1);
if (i) cout << ' ';
cout << ans[i];
}
cout << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 8252kb
input:
1 2 100000 123456789 987654321
output:
0 2 1
result:
wrong answer 1st lines differ - expected: '575673759', found: '0'