답안 #520105

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
520105 2022-01-28T12:11:20 Z Killer2501 Joker (BOI20_joker) C++14
100 / 100
181 ms 13464 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 3e5+5;
const int M = 21;
const ll inf = 4e18;
const ll mod = 998244353;
int n, t, m, k, ans, tong, a[N], lab[N], d[N], b[N], c[N];
pii dp[N];
vector<int> vi;
string s;
struct node
{
    int x, vx, y, vy;
    node(){}
    node(int _x, int _vx, int _y, int _vy)
    {
        x = _x;
        vx = _vx;
        y = _y;
        vy = _vy;
    }
};
vector<node> q;
pii findp(int u)
{
    int bi = 0;
    while(lab[u] > 0)
    {
        bi ^= c[u];
        u = lab[u];
    }
    return {u, bi};
}
bool hop(int u, int v)
{
    pii x = findp(u), y = findp(v);
    if(x.fi == y.fi)
    {
        if(x.se == y.se)return false;
        return true;
    }
    q.pb(node(x.fi, lab[x.fi], y.fi, lab[y.fi]));
    if(lab[x.fi] > lab[y.fi])swap(x, y);
    lab[x.fi] += lab[y.fi];
    lab[y.fi] = x.fi;
    c[y.fi] = x.se^y.se^1;
    return true;
}
void rollback(int sz)
{
    while((int)q.size() > sz)
    {
        node u = q.back();
        q.pop_back();
        lab[u.x] = u.vx;
        lab[u.y] = u.vy;
    }
}
void cal(int l, int r, int opl, int opr)
{
    if(l > r)return;
    int mid = (l+r)>>1;
    int sz = q.size();
    bool ok = true;
    for(int i = max(l, 1); i <= mid; i ++)
    {
        if(!hop(a[i], b[i]))
        {
            ok = false;
            break;
        }
    }

    if(ok)
    {
        int sz1 = q.size();
        d[mid] = 0;
        for(int i = min(opr, m); i >= max(opl, mid+1); i --)
        {
            if(!hop(a[i], b[i]))
            {
                d[mid] = i;
                break;
            }
        }
        rollback(sz1);
        cal(mid+1, r, d[mid], opr);
    }
    //cout << mid <<" "<<d[mid]<<" "<<ok << '\n';
    rollback(sz);
    for(int i = d[mid]+1; i <= opr; i ++)hop(a[i], b[i]);
    cal(l, mid-1, opl, d[mid]);
    rollback(sz);

}
void sol()
{
    cin >> n >> m >> t;
    fill_n(lab, n+1, -1);
    for(int i = 1; i <= m; i ++)
    {
        cin >> a[i] >> b[i];
        d[i] = m+1;
    }
    cal(0, m, 1, m+1);
    while(t -- > 0)
    {
        int l, r;
        cin >> l >> r;
        if(d[l-1] >= r+1)cout << "YES" << '\n';
        else cout << "NO" << '\n';
    }
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    #define task "test"
    if(fopen(task".inp", "r"))
	{
		freopen(task".inp", "r", stdin);
		freopen(task".out", "w", stdout);
    }
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}

Compilation message

Joker.cpp: In function 'int main()':
Joker.cpp:130:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:131:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  131 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 480 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 2 ms 460 KB Output is correct
35 Correct 2 ms 460 KB Output is correct
36 Correct 2 ms 332 KB Output is correct
37 Correct 2 ms 460 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
41 Correct 1 ms 456 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 2 ms 332 KB Output is correct
45 Correct 2 ms 460 KB Output is correct
46 Correct 2 ms 460 KB Output is correct
47 Correct 2 ms 332 KB Output is correct
48 Correct 3 ms 460 KB Output is correct
49 Correct 3 ms 460 KB Output is correct
50 Correct 2 ms 460 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 2 ms 336 KB Output is correct
53 Correct 2 ms 452 KB Output is correct
54 Correct 2 ms 400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 118 ms 9752 KB Output is correct
4 Correct 123 ms 11592 KB Output is correct
5 Correct 124 ms 11824 KB Output is correct
6 Correct 98 ms 9788 KB Output is correct
7 Correct 119 ms 9824 KB Output is correct
8 Correct 114 ms 8224 KB Output is correct
9 Correct 128 ms 8972 KB Output is correct
10 Correct 179 ms 10324 KB Output is correct
11 Correct 161 ms 9496 KB Output is correct
12 Correct 134 ms 10556 KB Output is correct
13 Correct 124 ms 7740 KB Output is correct
14 Correct 116 ms 8884 KB Output is correct
15 Correct 164 ms 9992 KB Output is correct
16 Correct 181 ms 10712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 118 ms 9752 KB Output is correct
30 Correct 123 ms 11592 KB Output is correct
31 Correct 124 ms 11824 KB Output is correct
32 Correct 98 ms 9788 KB Output is correct
33 Correct 119 ms 9824 KB Output is correct
34 Correct 114 ms 8224 KB Output is correct
35 Correct 128 ms 8972 KB Output is correct
36 Correct 179 ms 10324 KB Output is correct
37 Correct 161 ms 9496 KB Output is correct
38 Correct 134 ms 10556 KB Output is correct
39 Correct 124 ms 7740 KB Output is correct
40 Correct 116 ms 8884 KB Output is correct
41 Correct 164 ms 9992 KB Output is correct
42 Correct 181 ms 10712 KB Output is correct
43 Correct 120 ms 10076 KB Output is correct
44 Correct 131 ms 12104 KB Output is correct
45 Correct 174 ms 12516 KB Output is correct
46 Correct 103 ms 10036 KB Output is correct
47 Correct 114 ms 10132 KB Output is correct
48 Correct 156 ms 9516 KB Output is correct
49 Correct 168 ms 10800 KB Output is correct
50 Correct 123 ms 9468 KB Output is correct
51 Correct 128 ms 10464 KB Output is correct
52 Correct 147 ms 11060 KB Output is correct
53 Correct 132 ms 8124 KB Output is correct
54 Correct 144 ms 9404 KB Output is correct
55 Correct 157 ms 10380 KB Output is correct
56 Correct 165 ms 10952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 480 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 2 ms 460 KB Output is correct
35 Correct 2 ms 460 KB Output is correct
36 Correct 2 ms 332 KB Output is correct
37 Correct 2 ms 460 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
41 Correct 1 ms 456 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 2 ms 332 KB Output is correct
45 Correct 2 ms 460 KB Output is correct
46 Correct 2 ms 460 KB Output is correct
47 Correct 2 ms 332 KB Output is correct
48 Correct 3 ms 460 KB Output is correct
49 Correct 3 ms 460 KB Output is correct
50 Correct 2 ms 460 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 2 ms 336 KB Output is correct
53 Correct 2 ms 452 KB Output is correct
54 Correct 2 ms 400 KB Output is correct
55 Correct 98 ms 7864 KB Output is correct
56 Correct 114 ms 10980 KB Output is correct
57 Correct 74 ms 10816 KB Output is correct
58 Correct 64 ms 7860 KB Output is correct
59 Correct 97 ms 7972 KB Output is correct
60 Correct 137 ms 8580 KB Output is correct
61 Correct 99 ms 7968 KB Output is correct
62 Correct 104 ms 8772 KB Output is correct
63 Correct 93 ms 6360 KB Output is correct
64 Correct 107 ms 8100 KB Output is correct
65 Correct 124 ms 8700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 480 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 2 ms 460 KB Output is correct
35 Correct 2 ms 460 KB Output is correct
36 Correct 2 ms 332 KB Output is correct
37 Correct 2 ms 460 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
41 Correct 1 ms 456 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 2 ms 332 KB Output is correct
45 Correct 2 ms 460 KB Output is correct
46 Correct 2 ms 460 KB Output is correct
47 Correct 2 ms 332 KB Output is correct
48 Correct 3 ms 460 KB Output is correct
49 Correct 3 ms 460 KB Output is correct
50 Correct 2 ms 460 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 2 ms 336 KB Output is correct
53 Correct 2 ms 452 KB Output is correct
54 Correct 2 ms 400 KB Output is correct
55 Correct 118 ms 9752 KB Output is correct
56 Correct 123 ms 11592 KB Output is correct
57 Correct 124 ms 11824 KB Output is correct
58 Correct 98 ms 9788 KB Output is correct
59 Correct 119 ms 9824 KB Output is correct
60 Correct 114 ms 8224 KB Output is correct
61 Correct 128 ms 8972 KB Output is correct
62 Correct 179 ms 10324 KB Output is correct
63 Correct 161 ms 9496 KB Output is correct
64 Correct 134 ms 10556 KB Output is correct
65 Correct 124 ms 7740 KB Output is correct
66 Correct 116 ms 8884 KB Output is correct
67 Correct 164 ms 9992 KB Output is correct
68 Correct 181 ms 10712 KB Output is correct
69 Correct 120 ms 10076 KB Output is correct
70 Correct 131 ms 12104 KB Output is correct
71 Correct 174 ms 12516 KB Output is correct
72 Correct 103 ms 10036 KB Output is correct
73 Correct 114 ms 10132 KB Output is correct
74 Correct 156 ms 9516 KB Output is correct
75 Correct 168 ms 10800 KB Output is correct
76 Correct 123 ms 9468 KB Output is correct
77 Correct 128 ms 10464 KB Output is correct
78 Correct 147 ms 11060 KB Output is correct
79 Correct 132 ms 8124 KB Output is correct
80 Correct 144 ms 9404 KB Output is correct
81 Correct 157 ms 10380 KB Output is correct
82 Correct 165 ms 10952 KB Output is correct
83 Correct 98 ms 7864 KB Output is correct
84 Correct 114 ms 10980 KB Output is correct
85 Correct 74 ms 10816 KB Output is correct
86 Correct 64 ms 7860 KB Output is correct
87 Correct 97 ms 7972 KB Output is correct
88 Correct 137 ms 8580 KB Output is correct
89 Correct 99 ms 7968 KB Output is correct
90 Correct 104 ms 8772 KB Output is correct
91 Correct 93 ms 6360 KB Output is correct
92 Correct 107 ms 8100 KB Output is correct
93 Correct 124 ms 8700 KB Output is correct
94 Correct 127 ms 10736 KB Output is correct
95 Correct 163 ms 13108 KB Output is correct
96 Correct 116 ms 12848 KB Output is correct
97 Correct 113 ms 10784 KB Output is correct
98 Correct 111 ms 10776 KB Output is correct
99 Correct 143 ms 9828 KB Output is correct
100 Correct 168 ms 11780 KB Output is correct
101 Correct 132 ms 10176 KB Output is correct
102 Correct 170 ms 11192 KB Output is correct
103 Correct 156 ms 11892 KB Output is correct
104 Correct 129 ms 9276 KB Output is correct
105 Correct 175 ms 10788 KB Output is correct
106 Correct 174 ms 11544 KB Output is correct
107 Correct 117 ms 13464 KB Output is correct
108 Correct 128 ms 10580 KB Output is correct
109 Correct 125 ms 10552 KB Output is correct
110 Correct 137 ms 10516 KB Output is correct
111 Correct 129 ms 10560 KB Output is correct
112 Correct 122 ms 10552 KB Output is correct
113 Correct 121 ms 10552 KB Output is correct
114 Correct 121 ms 10556 KB Output is correct
115 Correct 142 ms 10500 KB Output is correct
116 Correct 123 ms 10548 KB Output is correct