#include <stdio.h> #include <string.h> #include <unordered_map> // brzydki kod, brzydki nawet bez zadnych optymalizacji! const int SIZE = 1000; struct recType { unsigned long long int x1, x2; //1, x2, y2; }; struct rangeType { unsigned long long int start, end; unsigned long long int type; }; struct pair { unsigned long long int key, value; }; /*pair m[1000*1000*10]; int mc = 0; void reset() { mc = 0; } unsigned long long int set(unsigned long long int a, unsigned long long int b, int add) { printf("s %llu %llu %llu \n", a , b, add); for(int i = 0; i < mc; i++) { if(m[i].key == a) { m[i].value = add ? m[i].value+b : b; return m[i].value; } } printf("none\n"); m[mc].key = a; m[mc].value = b; mc++; return b; } unsigned long long int get(unsigned long long int a) { for(int i = 0; i < mc; i++) { if(m[i].key == a) { return m[i].value; } } return 0; }*/ rangeType ranges[501*SIZE*3]; int cnt; void ar(unsigned long long int s, unsigned long long int e, unsigned long long int t) { ranges[cnt].start = s; ranges[cnt].end = e; ranges[cnt].type = t; cnt++; } unsigned long long int n; std::unordered_map<unsigned long long int, unsigned long long int> val; std::unordered_map<unsigned long long int, unsigned long long int> map; unsigned long long int type = 1; unsigned long long is(unsigned long long k) { if (map.find(k) == map.end()) { map[k] = type++; } return map[k]; } unsigned long long int one_dim(recType t[]) { type = 1; for(int i = 0; i < n; i++) { // printf(" i = %d, t=%p \n", i, (void *) t); unsigned long long int l = t[i].x1, p = t[i].x2; // printf(" x = %llu %llu \n", l, p); int loopEnd = cnt; map.clear(); for(int j = 0; j < loopEnd; j++) { unsigned long long int rs = ranges[j].start; unsigned long long int re = ranges[j].end; unsigned long long int rt = ranges[j].type; if (l <= rs && re <= p) { // w srodku ranges[j].type = is(rt); } else if (l <= rs && rs < p) { // lewy w, prawy poza: ranges[j].end = p; ranges[j].type = is(rt); ar(p, re, rt); // ranges[j].start = p; } else if (l < re && re <= p) { // prawy w, lewy poza: ar(rs, l, rt); ranges[j].start = l; ranges[j].type = is(rt); } else if (rs < l && p < re) { //nowy dokladnie w srodeczku starego ranges[j].end = l; ar(l, p, is(rt)); ar(p, re, rt); } } } unsigned long long int max = 0; val.clear(); for(int j = 0; j < cnt; j++) { if(val.find(ranges[j].type) == val.end()) { val[ranges[j].type] = 0; } val[ranges[j].type] = val[ranges[j].type] + (ranges[j].end - ranges[j].start); max = max > val[ranges[j].type] ? max : val[ranges[j].type]; // printf(" %d %llu %llu \n", j, ranges[j].end, val[ranges[j].type]); } return max; } int main() { unsigned long long int x, y , x1, y1, x2, y2; unsigned long long int ret = 0; recType recX[501*SIZE]; recType recY[501*SIZE]; scanf("%llu %llu %llu", &n, &x, &y); for(int i = 0; i < n; i++) { // std::unordered_map<unsigned long long int, unsigned long long int> map; scanf("%llu %llu %llu %llu", &x1, &y1, &x2, &y2); // unsigned long long l, p; recX[i].x1 = x1 < x2 ? x1 : x2; recX[i].x2 = x1 > x2 ? x1 : x2; recY[i].x1 = y1 < y2 ? y1 : y2; recY[i].x2 = y1 > y2 ? y1 : y2; /* printf(" x = %llu %llu \n", x1, x2); printf(" y = %llu %llu \n", y1, y2); unsigned long long int l = recY[i].x1, p = recY[i].x2; printf(" x = %llu %llu \n", l, p);*/ } cnt = 0; ar(0, x, 0); ret = one_dim(recX); cnt = 0; ar(0, y, 0); ret *= one_dim(recY); // ret = one_dim(recX); // if (l <= rs && re <= p) { // w srodku // ranges[j].type = type++; // } else if(rs == l && p < re) { // ar(rs, p, type++); // rangers[j].start = p; // } else if (rs < l && re == p) { // ar(l, p, type++); // ranges[j].end = l; // } else if (ranges[j].start < l) { // z lewej // ranges[cnt].start = l; ranges[cnt].end = ranges[j].end; ranges[cnt].type = type++; // ranges[j].end = l; // cnt++; // } else if () { // z prawej // obetnij i dodaj nowy // } // } // range[] // } // ret = max; /* reset(); for(int j = 0; j < cnt; j++) { printf("%d %d", j, ranges[j].end); int z = set(ranges[j].type, (ranges[j].end - ranges[j].start), 1); max = max > z ? max : z; } ret = max;*/ // if(val.find(ranges[j].type) == val.end()) { // val[(ranges[j].type)] = 0; // printf("add"); // int z = 1; // val[z] = 435; // printf("\n\n %d \n", val[z]); // printf("\n\n %d \n", val[1]); // printf("set%d %d %d", val[0], ranges[j].type, (val[(ranges[j].type)])); // } // printf("set%d ", val[ranges[j].type]); // val[ranges[j].type] = val[ranges[j].type] + (ranges[j].end - ranges[j].start); /* max = (max > val[ranges[j].type] ? max : val[ranges[j].type]);*/ // } // ret = max; printf("%llu", ret); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | #include <stdio.h> #include <string.h> #include <unordered_map> // brzydki kod, brzydki nawet bez zadnych optymalizacji! const int SIZE = 1000; struct recType { unsigned long long int x1, x2; //1, x2, y2; }; struct rangeType { unsigned long long int start, end; unsigned long long int type; }; struct pair { unsigned long long int key, value; }; /*pair m[1000*1000*10]; int mc = 0; void reset() { mc = 0; } unsigned long long int set(unsigned long long int a, unsigned long long int b, int add) { printf("s %llu %llu %llu \n", a , b, add); for(int i = 0; i < mc; i++) { if(m[i].key == a) { m[i].value = add ? m[i].value+b : b; return m[i].value; } } printf("none\n"); m[mc].key = a; m[mc].value = b; mc++; return b; } unsigned long long int get(unsigned long long int a) { for(int i = 0; i < mc; i++) { if(m[i].key == a) { return m[i].value; } } return 0; }*/ rangeType ranges[501*SIZE*3]; int cnt; void ar(unsigned long long int s, unsigned long long int e, unsigned long long int t) { ranges[cnt].start = s; ranges[cnt].end = e; ranges[cnt].type = t; cnt++; } unsigned long long int n; std::unordered_map<unsigned long long int, unsigned long long int> val; std::unordered_map<unsigned long long int, unsigned long long int> map; unsigned long long int type = 1; unsigned long long is(unsigned long long k) { if (map.find(k) == map.end()) { map[k] = type++; } return map[k]; } unsigned long long int one_dim(recType t[]) { type = 1; for(int i = 0; i < n; i++) { // printf(" i = %d, t=%p \n", i, (void *) t); unsigned long long int l = t[i].x1, p = t[i].x2; // printf(" x = %llu %llu \n", l, p); int loopEnd = cnt; map.clear(); for(int j = 0; j < loopEnd; j++) { unsigned long long int rs = ranges[j].start; unsigned long long int re = ranges[j].end; unsigned long long int rt = ranges[j].type; if (l <= rs && re <= p) { // w srodku ranges[j].type = is(rt); } else if (l <= rs && rs < p) { // lewy w, prawy poza: ranges[j].end = p; ranges[j].type = is(rt); ar(p, re, rt); // ranges[j].start = p; } else if (l < re && re <= p) { // prawy w, lewy poza: ar(rs, l, rt); ranges[j].start = l; ranges[j].type = is(rt); } else if (rs < l && p < re) { //nowy dokladnie w srodeczku starego ranges[j].end = l; ar(l, p, is(rt)); ar(p, re, rt); } } } unsigned long long int max = 0; val.clear(); for(int j = 0; j < cnt; j++) { if(val.find(ranges[j].type) == val.end()) { val[ranges[j].type] = 0; } val[ranges[j].type] = val[ranges[j].type] + (ranges[j].end - ranges[j].start); max = max > val[ranges[j].type] ? max : val[ranges[j].type]; // printf(" %d %llu %llu \n", j, ranges[j].end, val[ranges[j].type]); } return max; } int main() { unsigned long long int x, y , x1, y1, x2, y2; unsigned long long int ret = 0; recType recX[501*SIZE]; recType recY[501*SIZE]; scanf("%llu %llu %llu", &n, &x, &y); for(int i = 0; i < n; i++) { // std::unordered_map<unsigned long long int, unsigned long long int> map; scanf("%llu %llu %llu %llu", &x1, &y1, &x2, &y2); // unsigned long long l, p; recX[i].x1 = x1 < x2 ? x1 : x2; recX[i].x2 = x1 > x2 ? x1 : x2; recY[i].x1 = y1 < y2 ? y1 : y2; recY[i].x2 = y1 > y2 ? y1 : y2; /* printf(" x = %llu %llu \n", x1, x2); printf(" y = %llu %llu \n", y1, y2); unsigned long long int l = recY[i].x1, p = recY[i].x2; printf(" x = %llu %llu \n", l, p);*/ } cnt = 0; ar(0, x, 0); ret = one_dim(recX); cnt = 0; ar(0, y, 0); ret *= one_dim(recY); // ret = one_dim(recX); // if (l <= rs && re <= p) { // w srodku // ranges[j].type = type++; // } else if(rs == l && p < re) { // ar(rs, p, type++); // rangers[j].start = p; // } else if (rs < l && re == p) { // ar(l, p, type++); // ranges[j].end = l; // } else if (ranges[j].start < l) { // z lewej // ranges[cnt].start = l; ranges[cnt].end = ranges[j].end; ranges[cnt].type = type++; // ranges[j].end = l; // cnt++; // } else if () { // z prawej // obetnij i dodaj nowy // } // } // range[] // } // ret = max; /* reset(); for(int j = 0; j < cnt; j++) { printf("%d %d", j, ranges[j].end); int z = set(ranges[j].type, (ranges[j].end - ranges[j].start), 1); max = max > z ? max : z; } ret = max;*/ // if(val.find(ranges[j].type) == val.end()) { // val[(ranges[j].type)] = 0; // printf("add"); // int z = 1; // val[z] = 435; // printf("\n\n %d \n", val[z]); // printf("\n\n %d \n", val[1]); // printf("set%d %d %d", val[0], ranges[j].type, (val[(ranges[j].type)])); // } // printf("set%d ", val[ranges[j].type]); // val[ranges[j].type] = val[ranges[j].type] + (ranges[j].end - ranges[j].start); /* max = (max > val[ranges[j].type] ? max : val[ranges[j].type]);*/ // } // ret = max; printf("%llu", ret); return 0; } |