BZOJ2738 matrix multiplication

Source: Internet
Author: User

Divine question ...

First we have to think about ... From small to large to join the number of matrices, and then see each number of contributions to each query, but the complexity of the wrong

Second, we can two points ah! Add the first half of the small number, plus the second half of the number, to see if each question in the first half has been answered (seemingly called the overall two points?) )

Then, in order not to add a space, I wrote something like a fast-line ... It's just sxbk the border.

Finally, BZ's evaluation Kei Jiao t^t, the same procedure the day before to turn to WA, today AC ...

1 /**************************************************************2 problem:27383 User:rausen4 language:c++5 result:accepted6 time:10192 Ms7 memory:6436 KB8 ****************************************************************/9  Ten#include <cstdio> One#include <algorithm> A   - using namespacestd; - Const intN =505; the Const intCnt_q = 6e4 +5; -   -InlineintRead () { -     intx =0; +     CharCH =GetChar (); -      while(Ch <'0'||'9'<ch) +CH =GetChar (); A      while('0'<= CH && Ch <='9') { atx = x *Ten+ CH-'0'; -CH =GetChar (); -     } -     returnx; - } -   in structData { -     intx, Y, V; to data () {} +Dataint_x,int_y,int_v): X (_x), Y (_y), V (_v) {} -       theInlineBOOL operator< (ConstData &a)Const { *         returnV <A.V; $     }Panax Notoginseng} a[n * N +5]; -   the structQuery { +     intx1, x2, y1, y2, K, id; A       theInlinevoidRead_in (inti) { +X1 = Read (), y1 = Read (), x2 = Read (), y2 =read (); -K = Read (), id =i; $     } $ } Q[cnt_q]; -   - intN, Bit[n][n], ans[cnt_q], now; the   - #defineLowbit (x) (x & x)WuyiInlinevoidBit_modify (intXintYintd) { the     intI, J; -      for(i = x; i <= n; i + =lowbit (i)) Wu          for(j = y; J <= N; j + =Lowbit (j)) -BIT[I][J] + =D; About } $   -InlineintBit_query (intXinty) { -     intI, j, res =0; -      for(i = x; i; I-=lowbit (i)) A          for(j = y; j; J-=Lowbit (j)) +Res + =Bit[i][j]; the     returnRes; - } $ #undefLowbit the   theInlineBOOLCheckinti) { the     intTMP = Bit_query (q[i].x2, Q[i].y2) + bit_query (q[i].x1-1, Q[i].y1-1) the-Bit_query (q[i].x2, Q[i].y1-1)-Bit_query (Q[i].x1-1, q[i].y2); -     returnQ[I].K <=tmp; in } the   the voidWorkintLintRintLintR) { About     if(L > R)return; the     if(L = =r) { the         inti; the          for(i = L; I <= R; + +)i) +Ans[q[i].id] =l; -         return; the     }Bayi     intMID = L + R >>1, i = L, j =R; the      while(Now! = N * N && a[now +1].V <=mid) the++now, Bit_modify (a[now].x, A[NOW].Y,1); -      while(Now && a[now].v >mid) -Bit_modify (a[now].x, A[NOW].Y,-1), --Now ; the           the      while(I <=j) { the          while(I <= J && Check (i)) + +i; the          while(I <= J &&!check (j))--J; -         if(I <j) { the swap (Q[i], q[j]); the++i,--J; the         }94     } the Work (L, Mid, L, j); theWork (Mid +1, R, I, r); the }98   About #defineW (x, y) (x-1) * n + y - intMain () {101     intQ, I, j, mx =0;102n = Read (), Q =read ();103      for(i =1; I <= N; ++i)104          for(j =1; J <= N; ++j) { theA[w (I, j)] =data (I, J, read ());106MX =max (MX, a[w (i, J)].v);107         }108Sort (A +1, A + N * n +1);109      for(i =1; I <= Q; ++i) the q[i].read_in (i);111Work0Mx1, Q); the      for(i =1; I <= Q; ++i)113printf"%d\n", Ans[i]); the     return 0; the}
View Code

(P.S. Kneeling for the great God to explain the difference between the whole dichotomy and CDQ, although I will not = =b)

BZOJ2738 matrix multiplication

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.