답안 #300414

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
300414 2020-09-17T06:59:51 Z bacegen4o Joker (BOI20_joker) C
100 / 100
1018 ms 77204 KB
#pragma GCC optimize "-O3"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<assert.h>
#include<stdbool.h>
#include<limits.h>
inline int max(int a,int b){return a>b?a:b;}
#define swap(a,b) do{ __typeof(a) tp; tp=a; a=b; b=tp; }while(0)
#define pb(zpv, zvv) zpv.ptr = pushback(zpv.ptr, &zpv.sz, zvv)
#define resizeArray(ptr, type, size) ((type*)realloc(ptr, (size) * sizeof(type)))
int *pushback(int *array, int *size, int value) {
    int *output = resizeArray(array, int, *size + 1);
    output[(*size)++] = value;
    return output;
}
typedef struct{
	int*ptr;
	int sz;
}vec;
vec newVec() {
	vec rez;
	rez.ptr = NULL;
	rez.sz  = 0;
	return rez;
}
//////////////////////////
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
//typedef pair<int,int> pii;
//typedef vector<vector<int> > graph;
//const double pi = acos(-1.0);
#define oned(a, x1, x2) { cout << #a << ":"; for(int _i = (x1); _i < (x2); _i++){ cout << " " << a[_i]; } cout << endl; }
#define twod(a, x1, x2, y1, y2) { cout << #a << ":" << endl; for(int _i = (x1); _i < (x2); _i++){ for(int _j = (y1); _j < (y2); _j++){ cout << (_j > y1 ? " " : "") << a[_i][_j]; } cout << endl; } }
#define mp make_pair
#define fst first
#define snd second
enum{ MAXN = 200005};
int parent[MAXN<<1];
int Size[MAXN<<1];
int depth = 0;
int par[50][MAXN<<1];
int sz[50][MAXN<<1];
vec mem[50];
int last[MAXN];
int n, m, q, a[MAXN], b[MAXN], l[MAXN], r[MAXN];

void setParent(int v, int p){
    if(par[depth][v]==0) {
        par[depth][v] = parent[v];
        sz[depth][v] = Size[v];
        pb(mem[depth], v);
    }
    parent[v] = p;
}
int getParent(int v){
    while(parent[v] != v) {
        v = parent[v];
    }
    return v;
}
bool mergeSets(int u, int v){
    int pu = getParent(u<<1);
    int pv = getParent(v<<1);
    bool res;
    if((pu>>1) == (pv>>1)) {
        res = pu^pv;
    } 
    else {
        if(Size[pu] > Size[pv]) {
            swap(pu,pv);
        }
        setParent(pu, pv^1);
        Size[pv^1] += Size[pu];
        setParent(pu^1, pv);
        Size[pv] += Size[pu^1];
        res = true;
    }
    return res;
}
void record(){
    depth++;
}
void rollback(){
    for(int i = 0; i < (int)mem[depth].sz; i++){
        int v = mem[depth].ptr[i];
        Size[parent[v]] -= sz[depth][v];
        parent[v] = par[depth][v];
        Size[v] = sz[depth][v];
        par[depth][v] = 0;
    }
    mem[depth].sz=0;
    depth--;
}
void init(){
    for(int i = 2; i <= 2*n+1; i++) {
        parent[i] = i;
        Size[i] = 1;
    }
}
void rec(int L1, int L2, int R1, int R2){
    record();
    int LM = (L1+L2)/2;
    for(int i = L1; i < LM; i++) {
        mergeSets(a[i],b[i]);
    }
    record();
    for(int i = R2; i >= LM; i--) {
        if(!mergeSets(a[i],b[i])) {
            last[LM] = i;
            break;
        }
    }
    rollback();
    if(LM < L2) {
        mergeSets(a[LM],b[LM]);
        rec(LM+1,L2,max(LM+1,last[LM]),R2);
    }
    rollback();
    if(L1 < LM) {
        record();
        for(int i = R2; i > last[LM]; i--) {
            mergeSets(a[i],b[i]);
        }
        rec(L1,LM-1,R1,last[LM]);
        rollback();
    }
}
void solve(){
    init();
    int X = 1;
    while(X <= m) {
        if(!mergeSets(a[X],b[X])) {
            break;
        }
        X++;
    }
    init();
    for(int i = X+1; i <= m; i++) {
        last[i] = m+1;
    }
    if(X <= m) {
        rec(1,X,1,m);
    }
    for(int i = 1; i <= q; i++) {
        printf(last[l[i]] <= r[i] ? "NO\n" : "YES\n");
    }
}
int main(){
    while(scanf("%d %d %d", &n, &m, &q)==3){
        for(int i = 1; i <= m; i++){
            scanf("%d %d", a+i, b+i);
        }
        for(int i = 1; i <= q; i++){
            scanf("%d %d", l+i, r+i);
        }
        solve();
    }
    return 0;
}

Compilation message

Joker.c: In function 'main':
Joker.c:154:13: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  154 |             scanf("%d %d", a+i, b+i);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~
Joker.c:157:13: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  157 |             scanf("%d %d", l+i, r+i);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 416 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 488 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 416 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 488 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 3 ms 1024 KB Output is correct
31 Correct 3 ms 896 KB Output is correct
32 Correct 3 ms 768 KB Output is correct
33 Correct 2 ms 640 KB Output is correct
34 Correct 3 ms 1024 KB Output is correct
35 Correct 4 ms 1024 KB Output is correct
36 Correct 3 ms 768 KB Output is correct
37 Correct 5 ms 1024 KB Output is correct
38 Correct 2 ms 512 KB Output is correct
39 Correct 3 ms 1044 KB Output is correct
40 Correct 3 ms 768 KB Output is correct
41 Correct 3 ms 768 KB Output is correct
42 Correct 3 ms 768 KB Output is correct
43 Correct 3 ms 744 KB Output is correct
44 Correct 3 ms 768 KB Output is correct
45 Correct 3 ms 896 KB Output is correct
46 Correct 4 ms 1056 KB Output is correct
47 Correct 3 ms 768 KB Output is correct
48 Correct 3 ms 768 KB Output is correct
49 Correct 3 ms 896 KB Output is correct
50 Correct 4 ms 1024 KB Output is correct
51 Correct 3 ms 768 KB Output is correct
52 Correct 3 ms 768 KB Output is correct
53 Correct 3 ms 896 KB Output is correct
54 Correct 4 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 529 ms 34996 KB Output is correct
4 Correct 145 ms 12024 KB Output is correct
5 Correct 624 ms 66484 KB Output is correct
6 Correct 394 ms 38496 KB Output is correct
7 Correct 406 ms 39088 KB Output is correct
8 Correct 323 ms 25396 KB Output is correct
9 Correct 446 ms 38340 KB Output is correct
10 Correct 946 ms 70152 KB Output is correct
11 Correct 496 ms 38324 KB Output is correct
12 Correct 740 ms 64316 KB Output is correct
13 Correct 218 ms 12280 KB Output is correct
14 Correct 325 ms 25240 KB Output is correct
15 Correct 643 ms 51004 KB Output is correct
16 Correct 881 ms 70132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 416 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 488 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 529 ms 34996 KB Output is correct
30 Correct 145 ms 12024 KB Output is correct
31 Correct 624 ms 66484 KB Output is correct
32 Correct 394 ms 38496 KB Output is correct
33 Correct 406 ms 39088 KB Output is correct
34 Correct 323 ms 25396 KB Output is correct
35 Correct 446 ms 38340 KB Output is correct
36 Correct 946 ms 70152 KB Output is correct
37 Correct 496 ms 38324 KB Output is correct
38 Correct 740 ms 64316 KB Output is correct
39 Correct 218 ms 12280 KB Output is correct
40 Correct 325 ms 25240 KB Output is correct
41 Correct 643 ms 51004 KB Output is correct
42 Correct 881 ms 70132 KB Output is correct
43 Correct 522 ms 35088 KB Output is correct
44 Correct 155 ms 12184 KB Output is correct
45 Correct 1018 ms 77204 KB Output is correct
46 Correct 360 ms 39404 KB Output is correct
47 Correct 371 ms 38816 KB Output is correct
48 Correct 474 ms 38224 KB Output is correct
49 Correct 850 ms 70064 KB Output is correct
50 Correct 440 ms 31804 KB Output is correct
51 Correct 533 ms 50824 KB Output is correct
52 Correct 728 ms 69720 KB Output is correct
53 Correct 235 ms 12152 KB Output is correct
54 Correct 424 ms 32208 KB Output is correct
55 Correct 627 ms 50892 KB Output is correct
56 Correct 861 ms 69944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 416 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 488 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 3 ms 1024 KB Output is correct
31 Correct 3 ms 896 KB Output is correct
32 Correct 3 ms 768 KB Output is correct
33 Correct 2 ms 640 KB Output is correct
34 Correct 3 ms 1024 KB Output is correct
35 Correct 4 ms 1024 KB Output is correct
36 Correct 3 ms 768 KB Output is correct
37 Correct 5 ms 1024 KB Output is correct
38 Correct 2 ms 512 KB Output is correct
39 Correct 3 ms 1044 KB Output is correct
40 Correct 3 ms 768 KB Output is correct
41 Correct 3 ms 768 KB Output is correct
42 Correct 3 ms 768 KB Output is correct
43 Correct 3 ms 744 KB Output is correct
44 Correct 3 ms 768 KB Output is correct
45 Correct 3 ms 896 KB Output is correct
46 Correct 4 ms 1056 KB Output is correct
47 Correct 3 ms 768 KB Output is correct
48 Correct 3 ms 768 KB Output is correct
49 Correct 3 ms 896 KB Output is correct
50 Correct 4 ms 1024 KB Output is correct
51 Correct 3 ms 768 KB Output is correct
52 Correct 3 ms 768 KB Output is correct
53 Correct 3 ms 896 KB Output is correct
54 Correct 4 ms 1024 KB Output is correct
55 Correct 473 ms 32912 KB Output is correct
56 Correct 102 ms 9976 KB Output is correct
57 Correct 580 ms 65148 KB Output is correct
58 Correct 356 ms 36980 KB Output is correct
59 Correct 440 ms 35804 KB Output is correct
60 Correct 669 ms 55336 KB Output is correct
61 Correct 469 ms 36420 KB Output is correct
62 Correct 687 ms 62004 KB Output is correct
63 Correct 230 ms 16508 KB Output is correct
64 Correct 500 ms 42296 KB Output is correct
65 Correct 729 ms 61372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 416 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 488 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 3 ms 1024 KB Output is correct
31 Correct 3 ms 896 KB Output is correct
32 Correct 3 ms 768 KB Output is correct
33 Correct 2 ms 640 KB Output is correct
34 Correct 3 ms 1024 KB Output is correct
35 Correct 4 ms 1024 KB Output is correct
36 Correct 3 ms 768 KB Output is correct
37 Correct 5 ms 1024 KB Output is correct
38 Correct 2 ms 512 KB Output is correct
39 Correct 3 ms 1044 KB Output is correct
40 Correct 3 ms 768 KB Output is correct
41 Correct 3 ms 768 KB Output is correct
42 Correct 3 ms 768 KB Output is correct
43 Correct 3 ms 744 KB Output is correct
44 Correct 3 ms 768 KB Output is correct
45 Correct 3 ms 896 KB Output is correct
46 Correct 4 ms 1056 KB Output is correct
47 Correct 3 ms 768 KB Output is correct
48 Correct 3 ms 768 KB Output is correct
49 Correct 3 ms 896 KB Output is correct
50 Correct 4 ms 1024 KB Output is correct
51 Correct 3 ms 768 KB Output is correct
52 Correct 3 ms 768 KB Output is correct
53 Correct 3 ms 896 KB Output is correct
54 Correct 4 ms 1024 KB Output is correct
55 Correct 529 ms 34996 KB Output is correct
56 Correct 145 ms 12024 KB Output is correct
57 Correct 624 ms 66484 KB Output is correct
58 Correct 394 ms 38496 KB Output is correct
59 Correct 406 ms 39088 KB Output is correct
60 Correct 323 ms 25396 KB Output is correct
61 Correct 446 ms 38340 KB Output is correct
62 Correct 946 ms 70152 KB Output is correct
63 Correct 496 ms 38324 KB Output is correct
64 Correct 740 ms 64316 KB Output is correct
65 Correct 218 ms 12280 KB Output is correct
66 Correct 325 ms 25240 KB Output is correct
67 Correct 643 ms 51004 KB Output is correct
68 Correct 881 ms 70132 KB Output is correct
69 Correct 522 ms 35088 KB Output is correct
70 Correct 155 ms 12184 KB Output is correct
71 Correct 1018 ms 77204 KB Output is correct
72 Correct 360 ms 39404 KB Output is correct
73 Correct 371 ms 38816 KB Output is correct
74 Correct 474 ms 38224 KB Output is correct
75 Correct 850 ms 70064 KB Output is correct
76 Correct 440 ms 31804 KB Output is correct
77 Correct 533 ms 50824 KB Output is correct
78 Correct 728 ms 69720 KB Output is correct
79 Correct 235 ms 12152 KB Output is correct
80 Correct 424 ms 32208 KB Output is correct
81 Correct 627 ms 50892 KB Output is correct
82 Correct 861 ms 69944 KB Output is correct
83 Correct 473 ms 32912 KB Output is correct
84 Correct 102 ms 9976 KB Output is correct
85 Correct 580 ms 65148 KB Output is correct
86 Correct 356 ms 36980 KB Output is correct
87 Correct 440 ms 35804 KB Output is correct
88 Correct 669 ms 55336 KB Output is correct
89 Correct 469 ms 36420 KB Output is correct
90 Correct 687 ms 62004 KB Output is correct
91 Correct 230 ms 16508 KB Output is correct
92 Correct 500 ms 42296 KB Output is correct
93 Correct 729 ms 61372 KB Output is correct
94 Correct 524 ms 35088 KB Output is correct
95 Correct 937 ms 73660 KB Output is correct
96 Correct 607 ms 71712 KB Output is correct
97 Correct 385 ms 44724 KB Output is correct
98 Correct 401 ms 44584 KB Output is correct
99 Correct 363 ms 30588 KB Output is correct
100 Correct 733 ms 75196 KB Output is correct
101 Correct 442 ms 36848 KB Output is correct
102 Correct 616 ms 56072 KB Output is correct
103 Correct 818 ms 74948 KB Output is correct
104 Correct 313 ms 23764 KB Output is correct
105 Correct 560 ms 49964 KB Output is correct
106 Correct 780 ms 68576 KB Output is correct
107 Correct 297 ms 72040 KB Output is correct
108 Correct 530 ms 39952 KB Output is correct
109 Correct 523 ms 39984 KB Output is correct
110 Correct 526 ms 39952 KB Output is correct
111 Correct 524 ms 39952 KB Output is correct
112 Correct 536 ms 39820 KB Output is correct
113 Correct 525 ms 40060 KB Output is correct
114 Correct 525 ms 39824 KB Output is correct
115 Correct 547 ms 39824 KB Output is correct
116 Correct 551 ms 39856 KB Output is correct