Bzoj 4216 Pig sub-block mess

Source: Internet
Author: User

Test Instructions:Link Method:Block to save space. parsing:The point of this pit is that he has only 3 m of memory limit, if we open Longlong prefix and is dead. So consider narrowing the size of this long long array. Then think of the sub-block may be 15 for the size of the block, in fact, not a little more than a small, but the memory 15 is similar to it. Then record each block within the and, and then ask when the whole block directly take, not the whole block of violent enumeration, at most 30 points. So the time can be over, and then the memory is about 2.6MB, can be too. But there is a problem, do not hit the using namespace std; This run automatically applies 700kb of memory, too pit spicy! Code:
#include <cstdio>#include <cstring>#include <algorithm>#define N 500005#define M 33335#define Ktypedef Long LongllintA[n];ll Sum[m];intN,m,jd,blockl,blockr,cntblock,l,r;ll ans;voidCalcintLintR) {blockl=l>>4; Blockr=r>>4; ans+=sum[blockr-1]-SUM[BLOCKL]; for(intI=l;i>>4==blockl&&i>0&&i<=n;i++) {Ans+=a[i]; } for(intI=r;i>>4==blockr&&i>0&&i<=n;i--) {Ans+=a[i]; }}intMain () {scanf("%d%d%d", &AMP;N,&AMP;M,&AMP;JD); for(intI=1; i<=n;i++) {scanf("%d", &a[i]); Sum[i>>4]+=a[i]; } cntblock=n>>4; for(intI=1; i<=cntblock;i++) sum[i]+=sum[i-1]; for(intI=1; i<=m;i++) {if(ans<0) Ans=-ans;scanf("%d%d", &l,&r);if(JD) {l= (L^ans)%n+1; R= (R^ans)%n+1;if(L>r) L^=r^=l^=r; } ans=0; Calc (l,r);printf("%lld\n", ans); }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Bzoj 4216 Pig sub-block mess

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.