QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#634224 | #7752. The Only Way to the Destination | REN5511 | RE | 3ms | 13620kb | C++14 | 3.0kb | 2024-10-12 16:54:08 | 2024-10-12 16:54:11 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
int in[200000 + 1000];
int idx = 0;
struct node
{
int x1, x2,y;
};
vector<node>arr[200000 + 100];
vector<node>good[200000 + 100];
map<pair<int, pair<int, int>>, set<pair<int, pair<int, int>>>>edge;
bool cp(node a, node b) {
if (a.y != b.y) return a.y < b.y;
return a.x2 < b.x2;
}
int fd1(int tar, int y) {
int l = 0, r = good[y].size() - 1;
int ans = -1;
while (l <= r) {
int mid = (l + r) / 2;
if (good[y][mid].x2 >= tar) {
ans = mid;
r = mid - 1;
}
else {
l = mid + 1;
}
}
return ans;
}
int fd2(int tar, int y) {
int l = 0, r = good[y].size() - 1;
int ans = -1;
while (l <= r) {
int mid = (l + r) / 2;
if (good[y][mid].x1 <= tar) {
ans = mid;
l = mid + 1;
}
else {
r = mid - 1;
}
}
return ans;
}
//set<int>edge[100000 + 100];
int main()
{
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < k; i++) {
int x1, x2, y;
cin >> x1 >> x2 >> y;
if (y >= 2e5)continue;
arr[y].push_back({x1,x2,y});
}
if (m > 2e5) {
cout << "NO";
}
for (int i = 1; i <= m; i++) {
sort(arr[i].begin(), arr[i].end(), cp);
}
for (int i = 1; i <= m; i++) {
int now = 1;
for (auto j : arr[i]) {
if (j.x1-1 - now + 1 >= 1) {
good[i].push_back({ now,j.x1 - 1,i });
}
now = j.x2 + 1;
}
if (n - now + 1 >= 1) {
good[i].push_back({ now,n,i });
}
}
int in = 0;
for (int i = 1; i <= m; i++) {
for (auto tar : good[i]) {
int l = fd1(tar.x1,i-1), r = fd2(tar.x2,i-1);
if ((l != -1 || r != -1) && l <= r) {
for (int j = l; j <= r; j++) {
int top = max(tar.x1, good[i - 1][j].x1), bot = min(tar.x2, good[i - 1][j].x2);
if (bot-top + 1 >= 2)goto bad;
edge[{tar.x1, { tar.x2,i }}].insert({ good[i - 1][j].x1, {good[i - 1][j].x2,i - 1} });
}
}
l = fd1(tar.x1, i + 1); r = fd2(tar.x2, i + 1);
if ((l != -1 || r != -1) && l <= r) {
for (int j = l; j <= r; j++) {
int top = max(tar.x1, good[i + 1][j].x1), bot = min(tar.x2, good[i + 1][j].x2);
if (bot-top + 1 >= 2)goto bad;
edge[{tar.x1, { tar.x2,i }}].insert({ good[i + 1][j].x1, {good[i + 1][j].x2,i + 1} });
}
}
}
}
for (auto i : edge) {
for (auto tar : i.second) {
in++;
}
}
if (in == (edge.size() - 1) * 2) {
cout << "YES";
}
else {
bad:
cout << "NO";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 12932kb
input:
5 3 2 2 5 1 1 4 3
output:
YES
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 3ms
memory: 13296kb
input:
5 3 1 2 4 2
output:
NO
result:
ok answer is NO
Test #3:
score: 0
Accepted
time: 2ms
memory: 13620kb
input:
2 4 2 2 2 1 1 1 4
output:
NO
result:
ok answer is NO
Test #4:
score: -100
Runtime Error
input:
409455775 596220461 69036 72554058 85866426 497212608 54242898 110165840 236869995 68671059 127632371 324336242 39386477 208393446 248270338 151972182 327931056 231832 36658944 75335495 293646122 29512382 138875677 205628469 149151850 327396301 590717922 114980184 165064700 323939243 1771834 7016377...