QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#459051 | #7753. Energy Distribution | 666ldc | WA | 0ms | 3584kb | C++20 | 2.9kb | 2024-06-29 21:42:44 | 2024-06-29 21:42:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define endl '\n'
#define int long long
typedef long double f128;
typedef long long i64;
typedef unsigned long long u64;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;
const i64 inf = 2e18;
//-------------------------------------------
struct node
{
int l, r, y;
};
void solve()
{
int n, m, k;
cin >> n >> m >> k;
vector<node> g;
vector<int> a;
for (int i = 1; i <= k; i++)
{
int l, r, y;
cin >> l >> r >> y;
a.push_back(y);
g.push_back({l, r, y});
}
g.push_back({1, n, 0});
g.push_back({1, n, m + 1});
a.push_back(m + 1);
sort(g.begin(), g.end(), [&](node a, node b)
{
if (a.y != b.y)
return a.y < b.y;
return a.l < b.l; });
sort(a.begin(), a.end());
a.erase(unique(a.begin(), a.end()), a.end());
int l = 1;
for (auto t : a)
{
if (t - l - 1 >= 2)
{
cout << "NO" << endl;
return;
}
l = t;
}
vector<pii> v[2];
vector<int> col[2];
int p = 0;
for (int i = 1; i <= m; i++)
{
int id = i % 2;
int l = 1;
v[id].clear();
for (; p < g.size(); p++)
{
if (g[p].y == i)
{
if (l < g[p].l)
v[id].push_back({l, g[p].l - 1});
l = g[p].r + 1;
}
else if (g[p + 1].y > i)
break;
}
if (l <= n)
v[id].push_back({l, n});
col[id].resize(v[id].size(), -1);
int id1 = 0;
for (int j = 0; j < v[id].size(); j++)
{
auto t = v[id][j];
while (id1 + 1 < v[id ^ 1].size() && v[id ^ 1][id1].y < t.x)
id1++;
while (id1 < v[id ^ 1].size())
{
//cerr << v[id ^ 1][id1].x << " " << v[id ^ 1][id1].y << " " << col[id][j] << endl;
if (col[id][j] == col[id ^ 1][id1])
{
cout << "NO" << endl;
return;
}
else
{
col[id][j] = col[id ^ 1][id1];
}
//if (id1 + 1 < v[id ^ 1].size() && v[id ^ 1][id1].y <= t.y)
id1++;
}
int mex = 0;
for (int j = 0; j < v[id].size(); j++)
{
while (mex == col[id][j])
mex++;
col[id][j] = mex;
}
}
}
cout << "YES" << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
// cin >> T;
for (int i = 1; i <= T; i++)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3584kb
input:
2 0 1 1 0
output:
NO
result:
wrong output format Expected double, but "NO" found