✅
P7912 100pts 队列 (used to be using vector, TLE)
This commit is contained in:
		| @@ -28,4 +28,6 @@ add_executable(Playground | ||||
|         csp-decode/main.cc | ||||
|         palin/main.cc | ||||
|         csp-backpack/main.cc | ||||
|         csp-awarding/main.cc) | ||||
|         csp-awarding/main.cc | ||||
|         holiday-plan/main.cc | ||||
|         bears-fruit-basket/main.cc) | ||||
|   | ||||
							
								
								
									
										2
									
								
								bears-fruit-basket/data.in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								bears-fruit-basket/data.in
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| 12 | ||||
| 1 1 0 0 1 1 1 0 1 1 0 0 | ||||
							
								
								
									
										68
									
								
								bears-fruit-basket/main.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								bears-fruit-basket/main.cc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,68 @@ | ||||
| #include <iostream> | ||||
| #include <vector> | ||||
| #include <queue> | ||||
|  | ||||
| using namespace std; | ||||
|  | ||||
| struct fruit { | ||||
|     int type; | ||||
|     int start; | ||||
|     int end; | ||||
|  | ||||
|     fruit(int t, int start, int end) { | ||||
|         this->type = t; | ||||
|         this->start = start; | ||||
|         this->end = end; | ||||
|     } | ||||
| }; | ||||
|  | ||||
| bool took[200000 + 5], fruits[200000 + 5]; | ||||
|  | ||||
| int main() { | ||||
|     int n; | ||||
|     queue<fruit> blocks, pending_blocks; | ||||
|     cin >> n; | ||||
|     for (int i = 1; i <= n; i++) { | ||||
|         cin >> fruits[i]; | ||||
|     } | ||||
|     fruits[n + 1] = !fruits[n]; // Make the last block can be handled | ||||
|     for (int ptr = 2, lead = 1; ptr <= n + 1; ptr++) { | ||||
|         if (fruits[ptr] != fruits[ptr - 1]) { | ||||
|             blocks.emplace(fruits[ptr - 1], lead, ptr - 1); | ||||
|             lead = ptr; | ||||
|         } | ||||
|     } | ||||
|     // 1st -> 1 1 0 0 1 1 1 0 1 1 0 0 | ||||
|     //        x   x   x   x x   x | ||||
|     // 2nd ->   1   0   1     1   0 0 | ||||
|     int remain = n; | ||||
|     while (remain) { | ||||
|         while (!blocks.empty()) { | ||||
|             auto front = blocks.front(); | ||||
|             blocks.pop(); | ||||
|             while (took[front.start] && front.start <= front.end) front.start++; | ||||
|             if (front.start > front.end) continue; | ||||
|             printf("%d ", front.start); | ||||
|             remain--; | ||||
|             took[front.start] = true; | ||||
|             if (front.end == front.start) continue; | ||||
|             front.start++; | ||||
|             pending_blocks.push(front); | ||||
|         } | ||||
|         printf("\n"); | ||||
|         while (!pending_blocks.empty()) { | ||||
|             auto front = pending_blocks.front(); | ||||
|             pending_blocks.pop(); | ||||
|             while (!pending_blocks.empty()) { | ||||
|                 auto back = pending_blocks.front(); | ||||
|                 if (front.type == back.type) { | ||||
|                     front.end = back.end; | ||||
|                     pending_blocks.pop(); | ||||
|                 } else { | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
|             blocks.push(front); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										7
									
								
								csp-backpack/data.in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								csp-backpack/data.in
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| 6 1 100 | ||||
| 50 | ||||
| 20 | ||||
| 25 | ||||
| 20 | ||||
| 25 | ||||
| 50 | ||||
							
								
								
									
										9
									
								
								holiday-plan/main.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								holiday-plan/main.cc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| #include <iostream> | ||||
|  | ||||
| using namespace std; | ||||
|  | ||||
| int main() { | ||||
|     int n, m, k; | ||||
|     cin >> n >> m >> k; | ||||
|  | ||||
| } | ||||
| @@ -1,38 +1,38 @@ | ||||
| // The question want me to impl a sort by my self | ||||
| // But absolutely not | ||||
|  | ||||
| #include <iostream> | ||||
|  | ||||
| using namespace std; | ||||
|  | ||||
| const int N = 10005; | ||||
|  | ||||
| pair<int, int> arr[N]; | ||||
| int b[N]; | ||||
|  | ||||
| int main() { | ||||
|     int n, Q; | ||||
|     cin >> n >> Q; | ||||
|     int arr[n + 5]; | ||||
|  | ||||
|     int n, m; | ||||
|     scanf("%d%d", &n, &m); | ||||
|     for (int i = 1; i <= n; i++) { | ||||
|         cin >> arr[i]; | ||||
|         scanf("%d", &arr[i].first); | ||||
|         arr[i].second = i; | ||||
|     } | ||||
|  | ||||
|     for (int i = 0; i < Q; i++) { | ||||
|         int op; | ||||
|         cin >> op; | ||||
|     sort(arr + 1, arr + n + 1); | ||||
|     for (int i = 1; i <= n; i++) b[arr[i].second] = i; | ||||
|     while (m--) { | ||||
|         int op, x, y; | ||||
|         scanf("%d", &op); | ||||
|         if (op == 1) { | ||||
|             int x, v; | ||||
|             cin >> x >> v; | ||||
|             arr[x] = v; | ||||
|             scanf("%d%d", &x, &y); | ||||
|             arr[b[x]].first = y; | ||||
|             for (int i = 1; i < n; i++) { | ||||
|                 if (arr[i] > arr[i + 1]) swap(arr[i], arr[i + 1]); | ||||
|             } | ||||
|             for (int i = n - 1; i >= 1; i--) { | ||||
|                 if (arr[i] > arr[i + 1]) swap(arr[i], arr[i + 1]); | ||||
|             } | ||||
|             for (int i = 1; i <= n; i++) b[arr[i].second] = i; | ||||
|         } else { | ||||
|             int xn; | ||||
|             cin >> xn; | ||||
|             int it = arr[xn]; | ||||
|             int pos = n; | ||||
|             for (int j = 1; j < xn; j++) { | ||||
|                 if (arr[j] > it) pos--; | ||||
|             } | ||||
|             for (int j = xn + 1; j <= n; j++) { | ||||
|                 if (arr[j] >= it) pos--; | ||||
|             } | ||||
|             cout << pos << endl; | ||||
|             scanf("%d", &x); | ||||
|             printf("%d\n", b[x]); | ||||
|         } | ||||
|     } | ||||
|     return 0; | ||||
| } | ||||
| @@ -4,7 +4,7 @@ using namespace std; | ||||
|  | ||||
| #define mx 100100 | ||||
| int sum = 0; | ||||
| int a[10][10]; | ||||
| int arr[10][10]; | ||||
| inline int read() { | ||||
|   char c = getchar(); | ||||
|   if (c == '.') | ||||
| @@ -84,7 +84,7 @@ struct dancing_link { | ||||
|         v = (ansk[i]) % 9; | ||||
|         if (v == 0) | ||||
|           v = 9; | ||||
|         a[x][y] = v; | ||||
|           arr[x][y] = v; | ||||
|       } | ||||
|       return 1; | ||||
|     } | ||||
| @@ -112,7 +112,7 @@ int main() { | ||||
|   int o; | ||||
|   for (int i = 0; i <= 8; i++) { | ||||
|     for (int j = 0; j <= 8; j++) { | ||||
|       a[i][j] = x = read(); | ||||
|         arr[i][j] = x = read(); | ||||
|       for (int k = 1; k <= 9; k++) { | ||||
|         if (x != k && x != 0) | ||||
|           continue; | ||||
| @@ -127,7 +127,7 @@ int main() { | ||||
|   dlx.dance(0); | ||||
|   for (int i = 0; i <= 8; i++) { | ||||
|     for (int j = 0; j <= 8; j++) | ||||
|       printf("%d", a[i][j]); | ||||
|       printf("%d", arr[i][j]); | ||||
|     printf("\n"); | ||||
|   } | ||||
|   return 0; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user