BZOJ 4236 "JOIOJI" (prefix and + map)

Portal:

  [1]: BZOJ

  [2]: Luo Gu

 

•answer

  Define arrays a, b, c respectively represent 'J', 'O', the prefix 'I' and;

  To make the interval (L, R] satisfies the condition if and only if a [R] -a [L] = b [R] -b [L] = c [R] -c [L];

  那么,由 a[R]-a[L] = b[R]-b[L] ⇔ a[R]-b[R] = a[L]-b[L];

  同理,由 b[R]-b[L] = c[R]-c[L] ⇔ b[R]-c[R] = b[L]-c[L];

  After pretreatment before the a, b, c array;

  For position i, to find whether it contains satisfied before a i -b i = a j -b j && B i -C i = B j -C j position j, and j as small as possible;

  How to efficiently find it?

  使用 map<pair<int ,int > , int >;

  For previously treated location j, the A J -b J and B J -C J into the pair <int, int> each time to find out whether the presence (A I -b I , B I -C I ) i.e. can;

  If so, the answer to solving the current, on the contrary, it is added to the map;

•Code

 

Guess you like

Origin www.cnblogs.com/violet-acmer/p/11227967.html