QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#291911#5704. Jokerwhdywjd0 11ms12936kbC++144.7kb2023-12-27 13:13:462023-12-27 13:13:46

Judging History

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

  • [2023-12-27 13:13:46]
  • 评测
  • 测评结果:0
  • 用时:11ms
  • 内存:12936kb
  • [2023-12-27 13:13:46]
  • 提交

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(ql > qr)
        return;
    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(!a[i].u)
            continue;
        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--)
                if(a[j].u)
                    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--)
        if(a[j].u)
            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();
    st.merge(a[m].u, a[m].v, m);
    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;
    }
    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;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 6
Accepted
time: 1ms
memory: 5056kb

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: 4536kb

input:

2 1 1
1 2
1 1

output:

NO

result:

ok single line: 'NO'

Test #3:

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

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

result:

ok 6 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 4136kb

input:

3 3 6
1 2
2 3
3 1
1 1
1 2
1 3
2 2
2 3
3 3

output:

NO
NO
NO
NO
NO
NO

result:

ok 6 lines

Test #5:

score: 0
Accepted
time: 0ms
memory: 5384kb

input:

4 2 1
2 3
1 4
1 2

output:

NO

result:

ok single line: 'NO'

Test #6:

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

input:

5 7 28
1 2
2 3
3 4
4 5
1 3
2 4
3 5
3 4
4 6
2 4
4 5
5 6
5 7
6 6
7 7
1 4
1 5
1 6
2 5
2 6
2 7
4 7
3 5
3 6
3 7
6 7
4 4
1 7
2 2
5 5
1 1
1 2
1 3
3 3
2 3

output:

YES
NO
NO
YES
YES
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
YES
YES
YES
YES
NO
YES
YES

result:

ok 28 lines

Test #7:

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

input:

200 100 200
69 122
135 163
115 132
191 194
120 177
36 157
76 178
43 184
50 83
112 190
65 97
66 164
117 183
74 171
93 136
110 133
79 194
93 159
144 157
46 144
130 136
83 131
16 49
17 173
91 139
113 136
61 167
4 39
61 76
10 55
48 118
30 40
101 132
111 123
46 143
2 78
40 58
109 198
50 158
36 105
94 100...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok 200 lines

Test #8:

score: -6
Wrong Answer
time: 0ms
memory: 4028kb

input:

200 180 200
93 196
44 163
35 88
132 184
82 127
96 189
69 93
80 178
133 153
28 180
37 49
48 52
67 114
104 121
72 195
105 149
111 186
27 108
2 96
22 163
53 173
111 128
96 142
119 185
71 123
42 129
72 173
102 160
90 133
7 125
28 136
81 123
63 146
80 129
123 190
50 161
62 175
18 45
64 87
48 91
24 200
45...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YE...

result:

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

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Runtime Error

Test #55:

score: 25
Accepted
time: 11ms
memory: 12936kb

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%