Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The speed is not being determined by the computation—most of the time the program takes to run is consumed by i/o.</p> <p>Add <a href="http://www.cplusplus.com/reference/clibrary/cstdio/setvbuf/" rel="nofollow noreferrer">setvbuf</a> calls before the first <code>scanf</code> for a significant improvement:</p> <pre><code>setvbuf(stdin, NULL, _IOFBF, 32768); setvbuf(stdout, NULL, _IOFBF, 32768); </code></pre> <p>-- edit --</p> <p>The alleged <em>magic numbers</em> are the new buffer size. By default, FILE uses a buffer of 512 bytes. Increasing this size decreases the number of times that the C++ runtime library has to issue a read or write call to the operating system, which is by far the most expensive operation in your algorithm.</p> <p>By keeping the buffer size a multiple of 512, that eliminates buffer fragmentation. Whether the size should be <code>1024*10</code> or <code>1024*1024</code> depends on the system it is intended to run on. For 16 bit systems, a buffer size larger than 32K or 64K generally causes difficulty in allocating the buffer, and maybe managing it. For any larger system, make it as large as useful—depending on available memory and what else it will be competing against.</p> <p>Lacking any known memory contention, choose sizes for the buffers at about the size of the associated files. That is, if the input file is 250K, use that as the buffer size. There is definitely a diminishing return as the buffer size increases. For the 250K example, a 100K buffer would require three reads, while a default 512 byte buffer requires 500 reads. Further increasing the buffer size so only one read is needed is unlikely to make a significant performance improvement over three reads.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload