Submission #284126

# Submission time Handle Problem Language Result Execution time Memory
284126 2020-08-26T21:59:09 Z duality Joker (BOI20_joker) C++11
100 / 100
330 ms 12644 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int u[200000],v[200000];
int ll[200000];
pii parent[200000];
int size[200000];
pii find(int n) {
    if (parent[n].first != n) {
        pii p = find(parent[n].first);
        return mp(p.first,p.second^parent[n].second);
    }
    else return parent[n];
}
vpii added;
int addEdge(int u,int v) {
    int w = 1;
    pii pu = find(u),pv = find(v);
    w ^= pu.second^pv.second;
    u = pu.first,v = pv.first;
    if (u == v) {
        if (w == 1) return 0;
    }
    else {
        if (size[u] > size[v]) swap(u,v);
        parent[u] = mp(v,w),size[v] += size[u];
        added.pb(mp(u,v));
    }
    return 1;
}
int findAns(int l,int r,int s,int e,int b) {
    if (l > r) return 0;
    else if (!b) {
        fill(ll+l,ll+r+1,s);
        return 0;
    }

    int i;
    int m = (l+r) / 2;
    int bb = b,p1 = added.size();
    for (i = r; i > m; i--) bb &= addEdge(u[i],v[i]);
    int bbb = bb,p2 = added.size();
    i = s+1;
    while ((i <= e) && (i <= m) && bbb) bbb &= addEdge(u[i],v[i]),i++;
    ll[m] = i-1;
    while (added.size() > p2) {
        parent[added.back().first] = mp(added.back().first,0);
        size[added.back().second] -= size[added.back().first];
        added.pop_back();
    }
    bb &= addEdge(u[m],v[m]);
    findAns(l,m-1,s,ll[m],bb);
    while (added.size() > p1) {
        parent[added.back().first] = mp(added.back().first,0);
        size[added.back().second] -= size[added.back().first];
        added.pop_back();
    }
    bb = b;
    for (i = s+1; i <= ll[m]; i++) bb &= addEdge(u[i],v[i]);
    findAns(m+1,r,ll[m],e,bb);
    return 0;
}
int main() {
    int i;
    int N,M,Q;
    scanf("%d %d %d",&N,&M,&Q);
    for (i = 0; i < M; i++) scanf("%d %d",&u[i],&v[i]),u[i]--,v[i]--;
    for (i = 0; i < N; i++) parent[i] = mp(i,0),size[i] = 1;
    findAns(0,M-1,-1,M-1,1);

    int l,r;
    for (i = 0; i < Q; i++) {
        scanf("%d %d",&l,&r);
        l--,r--;
        printf((l <= ll[r]) ? "NO\n":"YES\n");
    }

    return 0;
}

Compilation message

Joker.cpp: In function 'int findAns(int, int, int, int, int)':
Joker.cpp:100:25: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  100 |     while (added.size() > p2) {
      |            ~~~~~~~~~~~~~^~~~
Joker.cpp:107:25: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  107 |     while (added.size() > p1) {
      |            ~~~~~~~~~~~~~^~~~
Joker.cpp: In function 'int main()':
Joker.cpp:120:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  120 |     scanf("%d %d %d",&N,&M,&Q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
Joker.cpp:121:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  121 |     for (i = 0; i < M; i++) scanf("%d %d",&u[i],&v[i]),u[i]--,v[i]--;
      |                             ~~~~~^~~~~~~~~~~~~~~~~~~~~
Joker.cpp:127:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  127 |         scanf("%d %d",&l,&r);
      |         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 380 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 288 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 376 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 376 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 376 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 376 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 380 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 288 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 376 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 376 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 376 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 376 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 2 ms 512 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 392 KB Output is correct
49 Correct 2 ms 512 KB Output is correct
50 Correct 2 ms 512 KB Output is correct
51 Correct 3 ms 384 KB Output is correct
52 Correct 3 ms 512 KB Output is correct
53 Correct 3 ms 512 KB Output is correct
54 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 212 ms 9456 KB Output is correct
4 Correct 330 ms 10940 KB Output is correct
5 Correct 171 ms 11268 KB Output is correct
6 Correct 162 ms 9448 KB Output is correct
7 Correct 170 ms 9448 KB Output is correct
8 Correct 168 ms 8048 KB Output is correct
9 Correct 179 ms 8808 KB Output is correct
10 Correct 261 ms 10660 KB Output is correct
11 Correct 198 ms 9324 KB Output is correct
12 Correct 210 ms 10724 KB Output is correct
13 Correct 148 ms 7668 KB Output is correct
14 Correct 169 ms 8560 KB Output is correct
15 Correct 223 ms 10044 KB Output is correct
16 Correct 266 ms 11104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 380 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 288 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 376 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 376 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 376 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 376 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 212 ms 9456 KB Output is correct
30 Correct 330 ms 10940 KB Output is correct
31 Correct 171 ms 11268 KB Output is correct
32 Correct 162 ms 9448 KB Output is correct
33 Correct 170 ms 9448 KB Output is correct
34 Correct 168 ms 8048 KB Output is correct
35 Correct 179 ms 8808 KB Output is correct
36 Correct 261 ms 10660 KB Output is correct
37 Correct 198 ms 9324 KB Output is correct
38 Correct 210 ms 10724 KB Output is correct
39 Correct 148 ms 7668 KB Output is correct
40 Correct 169 ms 8560 KB Output is correct
41 Correct 223 ms 10044 KB Output is correct
42 Correct 266 ms 11104 KB Output is correct
43 Correct 203 ms 9708 KB Output is correct
44 Correct 329 ms 11328 KB Output is correct
45 Correct 185 ms 11748 KB Output is correct
46 Correct 166 ms 9704 KB Output is correct
47 Correct 177 ms 9708 KB Output is correct
48 Correct 209 ms 9228 KB Output is correct
49 Correct 259 ms 11108 KB Output is correct
50 Correct 189 ms 9252 KB Output is correct
51 Correct 210 ms 10400 KB Output is correct
52 Correct 253 ms 11236 KB Output is correct
53 Correct 153 ms 8060 KB Output is correct
54 Correct 187 ms 9320 KB Output is correct
55 Correct 225 ms 10464 KB Output is correct
56 Correct 271 ms 11328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 380 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 288 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 376 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 376 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 376 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 376 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 2 ms 512 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 392 KB Output is correct
49 Correct 2 ms 512 KB Output is correct
50 Correct 2 ms 512 KB Output is correct
51 Correct 3 ms 384 KB Output is correct
52 Correct 3 ms 512 KB Output is correct
53 Correct 3 ms 512 KB Output is correct
54 Correct 3 ms 512 KB Output is correct
55 Correct 143 ms 7148 KB Output is correct
56 Correct 251 ms 9316 KB Output is correct
57 Correct 125 ms 9540 KB Output is correct
58 Correct 101 ms 7160 KB Output is correct
59 Correct 147 ms 6972 KB Output is correct
60 Correct 186 ms 8180 KB Output is correct
61 Correct 138 ms 7016 KB Output is correct
62 Correct 164 ms 8684 KB Output is correct
63 Correct 100 ms 5916 KB Output is correct
64 Correct 159 ms 7380 KB Output is correct
65 Correct 205 ms 8684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 380 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 288 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 376 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 376 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 376 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 376 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 2 ms 512 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 392 KB Output is correct
49 Correct 2 ms 512 KB Output is correct
50 Correct 2 ms 512 KB Output is correct
51 Correct 3 ms 384 KB Output is correct
52 Correct 3 ms 512 KB Output is correct
53 Correct 3 ms 512 KB Output is correct
54 Correct 3 ms 512 KB Output is correct
55 Correct 212 ms 9456 KB Output is correct
56 Correct 330 ms 10940 KB Output is correct
57 Correct 171 ms 11268 KB Output is correct
58 Correct 162 ms 9448 KB Output is correct
59 Correct 170 ms 9448 KB Output is correct
60 Correct 168 ms 8048 KB Output is correct
61 Correct 179 ms 8808 KB Output is correct
62 Correct 261 ms 10660 KB Output is correct
63 Correct 198 ms 9324 KB Output is correct
64 Correct 210 ms 10724 KB Output is correct
65 Correct 148 ms 7668 KB Output is correct
66 Correct 169 ms 8560 KB Output is correct
67 Correct 223 ms 10044 KB Output is correct
68 Correct 266 ms 11104 KB Output is correct
69 Correct 203 ms 9708 KB Output is correct
70 Correct 329 ms 11328 KB Output is correct
71 Correct 185 ms 11748 KB Output is correct
72 Correct 166 ms 9704 KB Output is correct
73 Correct 177 ms 9708 KB Output is correct
74 Correct 209 ms 9228 KB Output is correct
75 Correct 259 ms 11108 KB Output is correct
76 Correct 189 ms 9252 KB Output is correct
77 Correct 210 ms 10400 KB Output is correct
78 Correct 253 ms 11236 KB Output is correct
79 Correct 153 ms 8060 KB Output is correct
80 Correct 187 ms 9320 KB Output is correct
81 Correct 225 ms 10464 KB Output is correct
82 Correct 271 ms 11328 KB Output is correct
83 Correct 143 ms 7148 KB Output is correct
84 Correct 251 ms 9316 KB Output is correct
85 Correct 125 ms 9540 KB Output is correct
86 Correct 101 ms 7160 KB Output is correct
87 Correct 147 ms 6972 KB Output is correct
88 Correct 186 ms 8180 KB Output is correct
89 Correct 138 ms 7016 KB Output is correct
90 Correct 164 ms 8684 KB Output is correct
91 Correct 100 ms 5916 KB Output is correct
92 Correct 159 ms 7380 KB Output is correct
93 Correct 205 ms 8684 KB Output is correct
94 Correct 210 ms 10472 KB Output is correct
95 Correct 277 ms 12432 KB Output is correct
96 Correct 177 ms 12128 KB Output is correct
97 Correct 171 ms 10444 KB Output is correct
98 Correct 184 ms 10464 KB Output is correct
99 Correct 199 ms 9624 KB Output is correct
100 Correct 310 ms 12132 KB Output is correct
101 Correct 219 ms 9964 KB Output is correct
102 Correct 286 ms 11172 KB Output is correct
103 Correct 259 ms 11880 KB Output is correct
104 Correct 188 ms 9232 KB Output is correct
105 Correct 237 ms 10604 KB Output is correct
106 Correct 284 ms 11876 KB Output is correct
107 Correct 140 ms 12644 KB Output is correct
108 Correct 221 ms 10412 KB Output is correct
109 Correct 247 ms 10220 KB Output is correct
110 Correct 221 ms 10224 KB Output is correct
111 Correct 234 ms 10220 KB Output is correct
112 Correct 219 ms 10288 KB Output is correct
113 Correct 209 ms 10220 KB Output is correct
114 Correct 207 ms 10216 KB Output is correct
115 Correct 222 ms 10220 KB Output is correct
116 Correct 213 ms 10200 KB Output is correct