QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#225018 | #6633. Exam Requirements | Lysus | RE | 0ms | 13736kb | C++20 | 2.2kb | 2023-10-23 20:56:41 | 2023-10-23 20:56:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
int n, m, b[N], maxx;
struct Node {
int L, R, id;
}a[N];
int Idx, root;
int col[N], dfn[N], low[N], vis[N], cnt;
stack<int> s;
struct Edge {
int nxt, to;
}edge[N << 2];
int head[N], tot;
inline void add(int x, int y) {
edge[++tot].to = y;
edge[tot].nxt = head[x];
head[x] = tot;
x ^= 1, y ^= 1;
swap(x, y);
edge[++tot].to = y;
edge[tot].nxt = head[x];
head[x] = tot;
}
int tr[N << 2];
int lowbit(int x) {return x & (-x);}
void query(int x, int k) {
while(x) {
if(tr[x]) add(k << 1 | 1, tr[x]);
x -= lowbit(x);
}
}
void update(int x, int i) {
while (x <= maxx) {
Idx += 2;
add(Idx, i << 1);
if (tr[x]) add(Idx, tr[x]);
tr[x] = Idx;
x += lowbit(x);
}
}
void tarjan(int u) {
dfn[u] = low[u] = ++cnt;
vis[u] = 1;
s.push(u);
for(int i = head[u]; i; i = edge[i].nxt) {
int v = edge[i].to;
if(!dfn[v]) {
tarjan(v);
low[u] = min(low[u], low[v]);
}
else if(vis[v]) low[u] = min(low[u], dfn[v]);
}
if(dfn[u] == low[u]) {
int v = -1;
col[0] ++ ;
while(v != u) {
v = s.top(); s.pop();
vis[v] = 0;
col[v] = col[0];
}
}
}
void solve() {
cin >> n >> m;
for(int i = 1; i <= n; ++i) {
cin >> a[i].L >> a[i].R;
a[i].id = i;
b[++maxx] = a[i].L;
}
sort(a + 1, a + n + 1, [&](Node x, Node y) -> bool {
return x.L < y.L;
});
sort(b + 1, b + maxx + 1);
maxx = unique(b + 1, b + maxx + 1) - b - 1;
for (int i = 1; i <= maxx; i++) tr[i] = 0;
Idx = 2 * n;
for(int i = 1; i <= n; ++i) {
a[i].L = lower_bound(b + 1, b + maxx + 1, a[i].L) - b;
a[i].R = lower_bound(b + 1, b + maxx + 1, a[i].R) - b - 1;
query(a[i].R, a[i].id);
update(a[i].L, a[i].id);
}
for(int i = 1; i <= m; ++i) {
int x, y; cin >> x >> y;
add(x << 1, y << 1 | 1);
}
for(int i = 1; i <= Idx; ++ i) if(!dfn[i]) tarjan(i);
for(int i = 2; i <= Idx; ++i) {
if(col[i] == col[i ^ 1]) {
puts("NO");
return ;
}
}
puts("YES");
for(int i = 0; i <= Idx; ++i) col[i] = low[i] = dfn[i] = head[i] = 0;
tot = Idx = cnt = 0;
}
int main () {
ios::sync_with_stdio(false);
cin.tie(0);
int T; cin >> T;
while(T -- ) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 13736kb
input:
2 3 1 1 5 2 7 10 11 2 1 3 3 1 5 2 7 5 7 1 2 2 3 3 1
output:
YES NO
result:
ok 2 lines
Test #2:
score: -100
Runtime Error
input:
1 100000 100000 15084647 15220430 217541056 217598054 222963701 223110976 71224450 71340221 320463268 320631387 334861459 334924668 328950591 329083669 178996498 178996584 428529461 428605033 405428435 405504132 197936687 197947412 9058562 9190197 169407597 169474101 297518153 297590927 31471874 316...