답안 #415012

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
415012 2021-05-31T12:27:56 Z Ruxandra985 Joker (BOI20_joker) C++14
100 / 100
496 ms 13360 KB
#include <bits/stdc++.h>
#define DIMN 400010
using namespace std;
int tt[DIMN];
int sz[DIMN] , opt[DIMN];
int n , m , where;
pair <int , int> mch[DIMN];
vector <int> s;
vector <int> v;

int root (int x){
    while (tt[x] != x)
        x = tt[x];
    return x;
}

inline void unite (int x, int y){
    int radx = root(x), rady = root(y);
    if (radx == rady)
        return;
    if (sz[radx] < sz[rady])
        swap (radx,rady);

    s.push_back(rady); /// stiva pt undo
    sz[radx] += sz[rady];
    tt[rady] = radx;
}

inline int unite_init (int x , int y){
    int radx = root(x) , radnx , rady = root(y) , radny;

    if (radx == rady)
        return 0;

    radnx = root(n + x);
    radny = root(n + y);

    unite(radx , radny);
    unite(rady , radnx);

    return 1;


}

void solve(int st, int dr, int l, int r) {
    int mid = (st + dr)/2 , i , poz , x , y , init , init2;

    if (mid <= where){
        if (mid + 1 <= dr)
            solve(mid + 1 , dr , l , r);
        return;
    }

    init = s.size();

    for (i = min(dr , m) ; i >= mid ; i--){
        x = mch[i].first;
        y = mch[i].second;

        if (!unite_init(x , y))
            break;
    }

    if (i >= mid){ /// nu se poate cu toate
        where = i;



        while (s.size() != init){

            y = s.back();
            s.pop_back();
            sz[tt[y]] -= sz[y];
            tt[y] = y;

        }

        /// te duci doar in dreapta
        if (mid + 1 <= dr)
            solve(mid + 1 , dr , l , r);



        return;

    }



    init2 = s.size();

    poz = l;
    for (i = l + 1 ; i <= r && i < mid ; i++){

        x = mch[i].first;
        y = mch[i].second;

        if (!unite_init(x , y))
            break;
        poz = i;

    }
    opt[mid] = poz;

    while (s.size() != init2){

        y = s.back();
        s.pop_back();
        sz[tt[y]] -= sz[y];
        tt[y] = y;

    }

    if (st <= mid - 1)
        solve (st , mid - 1 , l , poz);

    while (s.size() != init){

        y = s.back();
        s.pop_back();
        sz[tt[y]] -= sz[y];
        tt[y] = y;

    }

    if (mid + 1 <= dr){

        for (i = l + 1 ; i <= poz ; i++){
            x = mch[i].first;
            y = mch[i].second;
            unite_init (x , y);
            //v.push_back(i);

        }

        solve(mid + 1 , dr , poz , r);

        while (s.size() != init){

            y = s.back();
            s.pop_back();
            sz[tt[y]] -= sz[y];
            tt[y] = y;

        }
    }
}

int main() {
    FILE *fin = stdin;
    FILE *fout = stdout;
    int q , i , l , r;
    fscanf (fin,"%d%d%d",&n,&m,&q);

    for (i = 1; i <= m; ++i) {
        fscanf (fin,"%d%d",&mch[i].first,&mch[i].second);
    }

    for (i = 1; i <= 2 * n ; ++i){
        tt[i] = i;
        sz[i] = 1;
    }
    solve(1, m + 1 , 0 , m);
    for (;q;q--) {
        fscanf (fin,"%d%d",&l,&r);
        if (opt[r + 1] >= l - 1 && r + 1 > where)
            fprintf (fout,"NO\n");
        else fprintf (fout,"YES\n");
    }
    return 0;
}

Compilation message

Joker.cpp: In function 'void solve(int, int, int, int)':
Joker.cpp:70:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   70 |         while (s.size() != init){
      |                ~~~~~~~~~^~~~~~~
Joker.cpp:106:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  106 |     while (s.size() != init2){
      |            ~~~~~~~~~^~~~~~~~
Joker.cpp:118:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  118 |     while (s.size() != init){
      |            ~~~~~~~~~^~~~~~~
Joker.cpp:139:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  139 |         while (s.size() != init){
      |                ~~~~~~~~~^~~~~~~
Joker.cpp: In function 'int main()':
Joker.cpp:154:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  154 |     fscanf (fin,"%d%d%d",&n,&m,&q);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:157:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  157 |         fscanf (fin,"%d%d",&mch[i].first,&mch[i].second);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:166:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  166 |         fscanf (fin,"%d%d",&l,&r);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 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 2 ms 300 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 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 332 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 ms 204 KB Output is correct
28 Correct 1 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 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 2 ms 300 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 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 332 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 ms 204 KB Output is correct
28 Correct 1 ms 296 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 3 ms 332 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 3 ms 332 KB Output is correct
35 Correct 4 ms 332 KB Output is correct
36 Correct 3 ms 332 KB Output is correct
37 Correct 3 ms 332 KB Output is correct
38 Correct 3 ms 332 KB Output is correct
39 Correct 2 ms 332 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 3 ms 308 KB Output is correct
42 Correct 3 ms 332 KB Output is correct
43 Correct 3 ms 332 KB Output is correct
44 Correct 3 ms 332 KB Output is correct
45 Correct 3 ms 332 KB Output is correct
46 Correct 3 ms 332 KB Output is correct
47 Correct 3 ms 332 KB Output is correct
48 Correct 3 ms 332 KB Output is correct
49 Correct 4 ms 332 KB Output is correct
50 Correct 3 ms 332 KB Output is correct
51 Correct 3 ms 332 KB Output is correct
52 Correct 3 ms 312 KB Output is correct
53 Correct 3 ms 332 KB Output is correct
54 Correct 4 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 239 ms 6844 KB Output is correct
4 Correct 496 ms 8108 KB Output is correct
5 Correct 183 ms 6960 KB Output is correct
6 Correct 203 ms 5248 KB Output is correct
7 Correct 235 ms 5288 KB Output is correct
8 Correct 228 ms 5460 KB Output is correct
9 Correct 252 ms 8796 KB Output is correct
10 Correct 392 ms 10636 KB Output is correct
11 Correct 255 ms 9164 KB Output is correct
12 Correct 316 ms 10664 KB Output is correct
13 Correct 157 ms 7304 KB Output is correct
14 Correct 224 ms 8384 KB Output is correct
15 Correct 309 ms 9912 KB Output is correct
16 Correct 391 ms 11004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 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 2 ms 300 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 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 332 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 ms 204 KB Output is correct
28 Correct 1 ms 296 KB Output is correct
29 Correct 239 ms 6844 KB Output is correct
30 Correct 496 ms 8108 KB Output is correct
31 Correct 183 ms 6960 KB Output is correct
32 Correct 203 ms 5248 KB Output is correct
33 Correct 235 ms 5288 KB Output is correct
34 Correct 228 ms 5460 KB Output is correct
35 Correct 252 ms 8796 KB Output is correct
36 Correct 392 ms 10636 KB Output is correct
37 Correct 255 ms 9164 KB Output is correct
38 Correct 316 ms 10664 KB Output is correct
39 Correct 157 ms 7304 KB Output is correct
40 Correct 224 ms 8384 KB Output is correct
41 Correct 309 ms 9912 KB Output is correct
42 Correct 391 ms 11004 KB Output is correct
43 Correct 248 ms 9648 KB Output is correct
44 Correct 480 ms 12036 KB Output is correct
45 Correct 327 ms 12392 KB Output is correct
46 Correct 219 ms 9652 KB Output is correct
47 Correct 230 ms 9648 KB Output is correct
48 Correct 287 ms 9228 KB Output is correct
49 Correct 375 ms 11112 KB Output is correct
50 Correct 234 ms 9012 KB Output is correct
51 Correct 307 ms 10420 KB Output is correct
52 Correct 311 ms 11372 KB Output is correct
53 Correct 178 ms 7608 KB Output is correct
54 Correct 246 ms 9064 KB Output is correct
55 Correct 324 ms 10404 KB Output is correct
56 Correct 433 ms 11304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 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 2 ms 300 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 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 332 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 ms 204 KB Output is correct
28 Correct 1 ms 296 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 3 ms 332 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 3 ms 332 KB Output is correct
35 Correct 4 ms 332 KB Output is correct
36 Correct 3 ms 332 KB Output is correct
37 Correct 3 ms 332 KB Output is correct
38 Correct 3 ms 332 KB Output is correct
39 Correct 2 ms 332 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 3 ms 308 KB Output is correct
42 Correct 3 ms 332 KB Output is correct
43 Correct 3 ms 332 KB Output is correct
44 Correct 3 ms 332 KB Output is correct
45 Correct 3 ms 332 KB Output is correct
46 Correct 3 ms 332 KB Output is correct
47 Correct 3 ms 332 KB Output is correct
48 Correct 3 ms 332 KB Output is correct
49 Correct 4 ms 332 KB Output is correct
50 Correct 3 ms 332 KB Output is correct
51 Correct 3 ms 332 KB Output is correct
52 Correct 3 ms 312 KB Output is correct
53 Correct 3 ms 332 KB Output is correct
54 Correct 4 ms 332 KB Output is correct
55 Correct 197 ms 7156 KB Output is correct
56 Correct 393 ms 9948 KB Output is correct
57 Correct 129 ms 9472 KB Output is correct
58 Correct 173 ms 6972 KB Output is correct
59 Correct 219 ms 6900 KB Output is correct
60 Correct 299 ms 8140 KB Output is correct
61 Correct 209 ms 6884 KB Output is correct
62 Correct 271 ms 8648 KB Output is correct
63 Correct 163 ms 5556 KB Output is correct
64 Correct 268 ms 7316 KB Output is correct
65 Correct 352 ms 8520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 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 2 ms 300 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 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 332 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 ms 204 KB Output is correct
28 Correct 1 ms 296 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 3 ms 332 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 3 ms 332 KB Output is correct
35 Correct 4 ms 332 KB Output is correct
36 Correct 3 ms 332 KB Output is correct
37 Correct 3 ms 332 KB Output is correct
38 Correct 3 ms 332 KB Output is correct
39 Correct 2 ms 332 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 3 ms 308 KB Output is correct
42 Correct 3 ms 332 KB Output is correct
43 Correct 3 ms 332 KB Output is correct
44 Correct 3 ms 332 KB Output is correct
45 Correct 3 ms 332 KB Output is correct
46 Correct 3 ms 332 KB Output is correct
47 Correct 3 ms 332 KB Output is correct
48 Correct 3 ms 332 KB Output is correct
49 Correct 4 ms 332 KB Output is correct
50 Correct 3 ms 332 KB Output is correct
51 Correct 3 ms 332 KB Output is correct
52 Correct 3 ms 312 KB Output is correct
53 Correct 3 ms 332 KB Output is correct
54 Correct 4 ms 332 KB Output is correct
55 Correct 239 ms 6844 KB Output is correct
56 Correct 496 ms 8108 KB Output is correct
57 Correct 183 ms 6960 KB Output is correct
58 Correct 203 ms 5248 KB Output is correct
59 Correct 235 ms 5288 KB Output is correct
60 Correct 228 ms 5460 KB Output is correct
61 Correct 252 ms 8796 KB Output is correct
62 Correct 392 ms 10636 KB Output is correct
63 Correct 255 ms 9164 KB Output is correct
64 Correct 316 ms 10664 KB Output is correct
65 Correct 157 ms 7304 KB Output is correct
66 Correct 224 ms 8384 KB Output is correct
67 Correct 309 ms 9912 KB Output is correct
68 Correct 391 ms 11004 KB Output is correct
69 Correct 248 ms 9648 KB Output is correct
70 Correct 480 ms 12036 KB Output is correct
71 Correct 327 ms 12392 KB Output is correct
72 Correct 219 ms 9652 KB Output is correct
73 Correct 230 ms 9648 KB Output is correct
74 Correct 287 ms 9228 KB Output is correct
75 Correct 375 ms 11112 KB Output is correct
76 Correct 234 ms 9012 KB Output is correct
77 Correct 307 ms 10420 KB Output is correct
78 Correct 311 ms 11372 KB Output is correct
79 Correct 178 ms 7608 KB Output is correct
80 Correct 246 ms 9064 KB Output is correct
81 Correct 324 ms 10404 KB Output is correct
82 Correct 433 ms 11304 KB Output is correct
83 Correct 197 ms 7156 KB Output is correct
84 Correct 393 ms 9948 KB Output is correct
85 Correct 129 ms 9472 KB Output is correct
86 Correct 173 ms 6972 KB Output is correct
87 Correct 219 ms 6900 KB Output is correct
88 Correct 299 ms 8140 KB Output is correct
89 Correct 209 ms 6884 KB Output is correct
90 Correct 271 ms 8648 KB Output is correct
91 Correct 163 ms 5556 KB Output is correct
92 Correct 268 ms 7316 KB Output is correct
93 Correct 352 ms 8520 KB Output is correct
94 Correct 253 ms 10272 KB Output is correct
95 Correct 423 ms 12772 KB Output is correct
96 Correct 168 ms 12076 KB Output is correct
97 Correct 249 ms 10280 KB Output is correct
98 Correct 248 ms 10320 KB Output is correct
99 Correct 273 ms 9380 KB Output is correct
100 Correct 359 ms 12320 KB Output is correct
101 Correct 248 ms 9860 KB Output is correct
102 Correct 287 ms 11072 KB Output is correct
103 Correct 340 ms 12280 KB Output is correct
104 Correct 209 ms 8920 KB Output is correct
105 Correct 318 ms 10612 KB Output is correct
106 Correct 370 ms 11712 KB Output is correct
107 Correct 179 ms 13360 KB Output is correct
108 Correct 254 ms 10076 KB Output is correct
109 Correct 267 ms 10104 KB Output is correct
110 Correct 250 ms 10156 KB Output is correct
111 Correct 260 ms 10132 KB Output is correct
112 Correct 253 ms 10184 KB Output is correct
113 Correct 264 ms 10168 KB Output is correct
114 Correct 240 ms 10112 KB Output is correct
115 Correct 248 ms 10136 KB Output is correct
116 Correct 248 ms 10124 KB Output is correct