Add tags

Add tags to the following comment

memsetを使うようにしたところ,大幅に高速化しました。

 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
--- 5.cpp    Wed Jun 25 16:56:20 2008
+++ 5.cpp    Sat Jun 28 20:33:02 2008
@@ -5,6 +5,7 @@
 #include <queue>
 #include <utility>
 #include <cassert>
+#include <cstring> // memset()
 
 #define REP(i, b, e) for (size_t i = b; i < e; ++i)
 
@@ -24,7 +25,7 @@
 template <typename T>
 size_t find(const std::vector<T>& v, const T& value)
 {
-    std::vector<T>::const_iterator it = std::lower_bound(v.begin(), v.end(), value);
+    typename std::vector<T>::const_iterator it = std::lower_bound(v.begin(), v.end(), value);
 
     assert(it != v.end());
 
@@ -78,7 +79,7 @@
     const size_t xn = xs.size() - 1;
     const size_t yn = ys.size() - 1;
 
-    std::vector<std::vector<int> > map(xn, std::vector<int>(yn, true));
+    std::vector<std::vector<unsigned char> > map(xn, std::vector<unsigned char>(yn, 1));
 
     for (std::vector<rect>::const_iterator it = tapes.begin(); it != tapes.end(); ++it)
     {
@@ -87,9 +88,9 @@
         const size_t lower_yi = find(ys, it->bottom);
         const size_t upper_yi = find(ys, it->top);
 
-        REP(xi, lower_xi, upper_xi) REP(yi, lower_yi, upper_yi)
+        REP(xi, lower_xi, upper_xi)
         {
-            map[xi][yi] = false;
+            std::memset(&map[xi][lower_yi], 0, (upper_yi - lower_yi) * sizeof(unsigned char));
         }
     }

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...