QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#291892#5704. Jokerwhdywjd0 21ms15696kbC++143.6kb2023-12-27 12:50:192023-12-27 12:50:19

Judging History

你现在查看的是最新测评结果

  • [2023-12-27 12:50:19]
  • 评测
  • 测评结果:0
  • 用时:21ms
  • 内存:15696kb
  • [2023-12-27 12:50:19]
  • 提交

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);
            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);
            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);
}

void MAIN()
{
    n = read();
    m = read();
    q = read();
    for(int i = 1; i <= m; i++)
        a[i].u = read(), a[i].v = read();
    dfs(1, m, 1, m);
    /*for(int i = 1; i <= m; i++)
    	printf("%d ", ans[i]);*/
    for(int i = 1; i <= q; i++)
    {
        int l = read();
        int r = read();
        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: 6
Accepted
time: 0ms
memory: 3960kb

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
YES

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 3960kb

input:

2 1 1
1 2
1 1

output:

NO

result:

ok single line: 'NO'

Test #3:

score: -6
Wrong Answer
time: 1ms
memory: 4024kb

input:

4 6 6
4 3
1 4
1 3
2 1
3 2
2 4
3 3
6 6
4 5
3 4
1 2
5 6

output:

YES
NO
YES
YES
YES
NO

result:

wrong answer 2nd lines differ - expected: 'YES', found: 'NO'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #55:

score: 0
Wrong Answer
time: 21ms
memory: 15696kb

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
YES
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:

wrong answer 9th lines differ - expected: 'NO', found: 'YES'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%