Niestety, nie byliśmy w stanie w pełni poprawnie wyświetlić tego pliku, ponieważ nie jest zakodowany w UTF-8.
Możesz pobrać ten plik i spróbować otworzyć go samodzielnie.
#include<cstdio> #include<vector> #include<algorithm> #include<cstring> using namespace std; struct car{ int id; int x1; int w; }; int binaryTree[200000]; int M = 1 << 16; vector<car> before; vector<car> after; bool cmp( car const& a, car const& b ) { return a.x1 < b.x1; } void insert( int n, int w ) { int v = n + M; binaryTree[v] = max( binaryTree[v], w ); while (v != 1) { v /= 2; binaryTree[v] = max( binaryTree[ 2 * v ], binaryTree[2 * v + 1] ); } } int query( int a, int b ) { int va = M + a, vb = M + b; /* Skrajne przedzia�y do rozk�adu. */ int wyn = binaryTree[va]; if (va != vb) wyn = max( wyn, binaryTree[ vb ] ); /* Spacer a� do momentu spotkania. */ while (va / 2 != vb / 2) { if (va % 2 == 0) wyn = max( wyn, binaryTree[va + 1] ); /* prawa bombka na lewej �cie�ce */ if (vb % 2 == 1) wyn = max( wyn, binaryTree[vb - 1] ); /* lewa bombka na prawej �cie�ce */ va /= 2; vb /= 2; } return wyn; } int main() { int testCases; scanf( "%d", &testCases ); for( int q = 0; q < testCases; ++q ) { before.clear(); after.clear(); memset( binaryTree, 0, sizeof(binaryTree) ); int n; int w; scanf( "%d%d", &n, &w ); for( int i = 0; i < n; i++ ) { car a1; int x1,x2,y1,y2; scanf( "%d%d%d%d", &x1, &y1, &x2, &y2 ); a1.x1 = min( x1, x2); a1.w = abs( y2 - y1 ); a1.id = i; before.push_back( a1 ); } for( int i = 0; i < n; i++ ) { car a1; int x1,x2,y1,y2; scanf( "%d%d%d%d", &x1, &y1, &x2, &y2 ); a1.x1 = min( x1, x2); a1.w = abs( y2 - y1 ); a1.id = i; after.push_back( a1 ); } sort( before.begin(), before.end(), cmp ); for( int i = 0; i < before.size(); i++ ) { after[ before[i].id ].id = i; before[i].id = i; } sort( after.begin(), after.end(), cmp ); bool end = false; for( int i = 0; i < after.size(); i++ ) { int res = query( after[i].id, n - 1 ); if( res + after[i].w > w) { end = true; //printf( "%d, %d\n", after[i].id, after[i].w ); break; } insert( after[i].id, after[i].w ); } if( end ) printf( "NIE\n" ); else printf( "TAK\n" ); } 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 | #include<cstdio> #include<vector> #include<algorithm> #include<cstring> using namespace std; struct car{ int id; int x1; int w; }; int binaryTree[200000]; int M = 1 << 16; vector<car> before; vector<car> after; bool cmp( car const& a, car const& b ) { return a.x1 < b.x1; } void insert( int n, int w ) { int v = n + M; binaryTree[v] = max( binaryTree[v], w ); while (v != 1) { v /= 2; binaryTree[v] = max( binaryTree[ 2 * v ], binaryTree[2 * v + 1] ); } } int query( int a, int b ) { int va = M + a, vb = M + b; /* Skrajne przedzia�y do rozk�adu. */ int wyn = binaryTree[va]; if (va != vb) wyn = max( wyn, binaryTree[ vb ] ); /* Spacer a� do momentu spotkania. */ while (va / 2 != vb / 2) { if (va % 2 == 0) wyn = max( wyn, binaryTree[va + 1] ); /* prawa bombka na lewej �cie�ce */ if (vb % 2 == 1) wyn = max( wyn, binaryTree[vb - 1] ); /* lewa bombka na prawej �cie�ce */ va /= 2; vb /= 2; } return wyn; } int main() { int testCases; scanf( "%d", &testCases ); for( int q = 0; q < testCases; ++q ) { before.clear(); after.clear(); memset( binaryTree, 0, sizeof(binaryTree) ); int n; int w; scanf( "%d%d", &n, &w ); for( int i = 0; i < n; i++ ) { car a1; int x1,x2,y1,y2; scanf( "%d%d%d%d", &x1, &y1, &x2, &y2 ); a1.x1 = min( x1, x2); a1.w = abs( y2 - y1 ); a1.id = i; before.push_back( a1 ); } for( int i = 0; i < n; i++ ) { car a1; int x1,x2,y1,y2; scanf( "%d%d%d%d", &x1, &y1, &x2, &y2 ); a1.x1 = min( x1, x2); a1.w = abs( y2 - y1 ); a1.id = i; after.push_back( a1 ); } sort( before.begin(), before.end(), cmp ); for( int i = 0; i < before.size(); i++ ) { after[ before[i].id ].id = i; before[i].id = i; } sort( after.begin(), after.end(), cmp ); bool end = false; for( int i = 0; i < after.size(); i++ ) { int res = query( after[i].id, n - 1 ); if( res + after[i].w > w) { end = true; //printf( "%d, %d\n", after[i].id, after[i].w ); break; } insert( after[i].id, after[i].w ); } if( end ) printf( "NIE\n" ); else printf( "TAK\n" ); } return 0; } |