QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291908 | #5704. Joker | whdywjd | 0 | 27ms | 10976kb | C++14 | 4.3kb | 2023-12-27 13:06:19 | 2023-12-27 13:06:19 |
Judging History
answer
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#define ll long long
#define _1 first
#define _2 second
#define _mp make_pair
#define _pb push_back
#define MAX_M 522222
using namespace std;
ll read(){ll x = 0;char c = 0, v = 0;do{c = getchar();if(c == '-')v = 1;} while(c < '0' || c > '9');do{x = (x << 3) + (x << 1) + c - '0';c = getchar();} while(c >= '0' && c <= '9');return v ? -x : x;}
template<size_t N>
struct vset
{
struct node
{
int id;
int x, y;
int fx, fy;
bool dx, dy;
} clr[N];
int tot;
int f[N];
bool d[N];
vset() { memset(f, 255, sizeof(f)), memset(d, 0, sizeof(d)); }
int fath(int x) { return f[x] < 0 ? x : fath(f[x]); }
bool col(int x)
{
bool cl = 0;
for(int i = x; i >= 0; i = f[i])
cl ^= d[i];
return cl;
}
bool check(int x, int y) { return fath(x) != fath(y) || col(x) != col(y); }
void merge(int x, int y, int id)
{
//return;
//printf("%d %d %d\n", x, y, id);
bool cx = col(x), cy = col(y);
x = fath(x), y = fath(y);
//return;
clr[++tot] = (node){id, x, y, f[x], f[y], d[x], d[y]};
//return;
if(x == y)
return;
if(f[x] > f[y])
swap(x, y);
if(cx == cy)
d[y] ^= 1;
f[x] += f[y];
f[y] = x;
}
inline int topid() { return clr[tot].id; }
void del()
{
int x = clr[tot].x, y = clr[tot].y;
f[x] = clr[tot].fx, f[y] = clr[tot].fy;
d[x] = clr[tot].dx, d[y] = clr[tot].dy;
tot--;
}
};
vset<MAX_M> st;
struct node { int u, v; };
int n, m, q;
node a[MAX_M];
int ans[MAX_M];
void dfs(int ql, int qr, int l, int r)
{
//printf("%d %d %d %d\n", ql, qr, l, r);
if(l == r)
{
for(int i = ql; i <= qr; i++)
ans[i] = l;
return;
}
int mid = (l + r) >> 1;
for(int i = r; i >= mid; i--)
{
if(!st.check(a[i].u, a[i].v))
{
while(st.topid() <= r && st.topid() >= mid)
st.del();
dfs(ql, qr, mid + 1, r);
while(st.topid() >= ql && st.topid() <= r)
st.del();
return;
}
st.merge(a[i].u, a[i].v, i);
}
//return;
for(int i = ql; i <= qr; i++)
{
//return;
if(!st.check(a[i].u, a[i].v))
{
//return;
while(st.topid() <= r && st.topid() >= mid)
st.del();
dfs(i, qr, mid + 1, r);
while(st.topid() < i && st.topid() >= ql)
st.del();
for(int j = r; j > mid; j--)
st.merge(a[j].u, a[j].v, j);
dfs(ql, i - 1, l, mid);
while(st.topid() >= ql && st.topid() <= r)
st.del();
return;
}
st.merge(a[i].u, a[i].v, i);
}
while(st.topid() >= ql && st.topid() <= r)
st.del();
for(int j = r; j > mid; j--)
st.merge(a[j].u, a[j].v, j);
dfs(ql, qr, l, mid);
while(st.topid() >= ql && st.topid() <= r)
st.del();
}
void MAIN()
{
n = read();
m = read();
q = read();
for(int i = 1; i <= m; i++)
a[i].u = read(), a[i].v = read();
for(int i = 0; i <= m; i++)
ans[i] = m + 2;
int lb = 0;
for(int i = 1; i <= m; i++)
{
if(!st.check(a[i].u, a[i].v))
break;
st.merge(a[i].u, a[i].v, i);
lb = i;
ans[i] = m + 1;
}
while(st.tot)
st.del();
dfs(1, lb, 1, m);
ans[0] = m + 1;
for(int i = m; i; i--)
{
if(!st.check(a[i].u, a[i].v))
break;
st.merge(a[i].u, a[i].v, i);
ans[0] = i;
}
while(st.tot)
st.del();
/*for(int i = 0; i <= m; i++)
printf("%d ", ans[i]);
printf("\n");*/
for(int i = 1; i <= q; i++)
{
int l = read() - 1;
int r = read() + 1;
if(r >= ans[l])
printf("NO\n");
else
printf("YES\n");
}
}
void CLEAR()
{
;
}
void EXP()
{
;
}
int main()
{
EXP();
int T = 1;
while(T--)
MAIN(), CLEAR();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3976kb
input:
6 8 2 1 3 1 5 1 6 2 5 2 6 3 4 3 5 5 6 4 8 4 7
output:
NO NO
result:
wrong answer 2nd lines differ - expected: 'YES', found: 'NO'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Runtime Error
Test #55:
score: 25
Accepted
time: 27ms
memory: 10976kb
input:
100000 199997 200000 79109 44896 79109 66117 66117 91800 91800 24387 24387 74514 48558 74514 48558 37561 37561 76920 79598 76920 79598 69196 69196 79004 49065 79004 70038 49065 15497 70038 15497 67507 25073 67507 25073 41762 41762 71848 71848 32073 32073 43754 72852 43754 41209 72852 68112 41209 629...
output:
NO NO YES NO NO NO NO NO NO NO NO NO NO YES NO YES NO NO NO NO NO YES NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO YES NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO YES NO NO YES NO NO YES NO NO NO YES NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO YES NO NO NO NO YES ...
result:
ok 200000 lines
Test #56:
score: -25
Runtime Error
input:
200000 200000 200000 156700 169748 169748 15408 158166 15408 117779 158166 2384 169748 4408 156700 117779 33510 90442 4408 4408 162134 117779 171528 90442 38746 33510 152759 171528 184558 162134 8761 154354 171528 23832 171528 23832 68341 98972 152759 80275 98972 98972 67486 67486 31710 31710 127052...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #2:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%