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", &N,&M,&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