Range Minimum Query (RMQ) Write a program which manipulates a sequence A = {a0,a1,...,an−1} with the following operations: find(s,t): report the mimimum element in as,as+1,...,at. update(i,x): change ai to x. Note that the initial values of ai (i=0,1…
Range Modular Queries 题意 给出一个数列,q个查询,问查询区间内有几个数 a[i] % x == y. 分析 其实裸的分块就能过了,跑的还特别快. 这里分块的作用就是排序. 在x较小时可以暴力打表,x较大时枚举显得更加高效. code #include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 4e4 + 10; const int BLOCK = 200; int…
int rangeMinQuery(int segTree[], int qlow, int qhigh, int low, int high, int pos) { if (qlow <= low && qhigh >= high) return segTree[pos]; if (qlow > high || qhigh < low) return maxVal; int mid = (low + high) / 2; return min(rangeMinQu…
C - Attention 枚举,计算前缀和即可 代码 #include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define space putchar(' ') #define enter putchar('\n') #define mp make_pair #define pb push_back #define MAXN 300005 //#define iv…