· G - Smaller Sum · CF2009G2 Yunli's Subarray Queries (hard version) · CF2009G. Yunli's Subarray Queries 题解 · Codeforces Round 971 (Div. 4) 阅读排行: · 开发的设计和重构,为开发效率服务 · 从零开始开发一个 MCP Server! · Ai满嘴顺口溜,想考研?浪费我几个小时 · 从问...
问到区间异或和首先想到前缀和,定义sum[ i ] 为1 ~ i 的异或值 对于每个r,查找有多少sum[ i ] & sum[ r ] >=k,首先想到01字典树,从高位像低位贪心。如果该位有异或值大于K的情况,如x=1,k=0,那么先加上cnt[son [ p1 ] ](因为该位已经大于了,后面不用再讨论了),然后让p = son[ p0] (让...
C1. Good Subarrays (Easy Version) This is the easy version of this problem. In this version, we do not have queries. Note that we have multiple test cases in this version. You can make hacks only if both versions of the problem are solved. An arraybbof lengthmmis good if for alli...
918. Maximum Sum Circular Subarray # 题目# Given a circular array C of integers represented by A, find the maximum possible sum of a non-empty subarray of C. Here, a circular array means the end of the array connects to the beginning of the array. (Formally, C[i] = A[i] when 0...
For each test, the first line consists of two integers N and Q, denoting the length of the array and the number of queries, respectively. N positive integers are listed in the second line, followed by Q lines each containing two integers L,R for a query. ...
"Similarly, if we changed "sum" into "gcd" the problem would still be solvable in time. (I can elaborate if you are interested)." Thanks →Reply adamant 9 years ago,#^| ←Rev.2→+58 There can be onlydifferent gcd values among suffixes of an array (due to Euclide's algorithm comple...
{//单点更新49for(inti=cur;i<=N;i+=lowbit(i))50treeArr[i]+=num;//由叶子节点向上更新树状数组51return;52}5354intQuery(intcur){//区间查询 从右端点往左加二进制最低位1的55intsum=0;56for(inti=cur;i>0;i-=lowbit(i))57sum+=treeArr[i];58returnsum;59}6061voidSolve(){62memset(pos...
}intsum(intx){intret=0;while(x>0) { ret+=sumv[x]; x-=x&(-x); }returnret; }voidinit(){clr(mp,0);clr(sumv,0); }intmain(){while(scf("%d%d",&n,&m)==2&&n) {init();for(inti=1; i<=n; i++)scanf("%d",&arr[i]);rmq_init();//v表示区间的gcd.//处理出代表性...
intsum(intx) { intans = 0; while(x) { ans += c[x]; x -= x & (-x); } returnans; } voidinit() { MMF(c); MMF(vis); MMF(ans); for(inti = 1; i <= n; i++) { intx = a[i]; intp = i; for(intj = 0; j < gp[i-1].size(); j++) ...
(x); } inline int sum(int x) { if(!x)return 0ll; int res=0; while(x>0)res+=C[x],x-=lowbit(x); return res; } }; BIT T; template<typename T> inline void read(T &x) { T data=0,w=1; char ch=0; while(ch!='-'&&(ch<'0'...