容易想到区间转化成前缀和.这样每个询问有了二维坐标,莫队即可. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll long long #define N 50010 ')) c=getchar();retur…
莫队,每次询问的是两个区间,就把区间拆开,分开来算就好了. 借鉴了rank1大佬的玄学排询问的姿势. #include<bits/stdc++.h> #define N 50010 typedef long long ll; using namespace std; inline int read(){ ,x=;char ch; ;}'); +ch-'); return f*x; } int c1[N],c2[N],a[N],n,m,cnt; struct Query{ int l,r,id;…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5213 Lucky Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 763 Accepted Submission(s): 249 Problem Description WLD is always very lucky.His secret…
题目链接 /* 数列的最大值保证<=50000(k),可以直接用莫队.否则要离散化 */ #include<cmath> #include<cstdio> #include<cctype> #include<algorithm> using namespace std; const int N=5e4+5; int n,m,k,size,A[N],times[N]; long long ans[N],now; struct Ques { int l,r…
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3781 就是莫队,左端点分块排序,块内按右端点排序,然后直接做即可. 代码如下: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; typedef long long ll…
ref #include <algorithm> #include <iostream> #include <cstdio> #include <cmath> using namespace std; typedef long long ll; int ua, ub, uc, ud, n, m, a[50005], chu[50005], blc, bel[50005], cnt; ll ans[50005], tmp; struct Node{ int u…