题目大意:给你一串数字,多次询问区间内数字的种类数 题解:莫队 卡点:洛谷数据加强,开了个$O(2)$ C++ Code: #include <cstdio> #include <algorithm> #define bsz 710 #define maxn 500010 #define N 1000010 int ans[maxn]; int n, m; int s[maxn], cnt[N]; struct Query { int l, r, pos; inline bool…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1878 不带修改的莫队,用一个桶记录一下当前区间中每种颜色的数量就可以做到$O(1)$更新了. #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; int inline readint(){ int Num;char ch…
#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #include<math.h> using namespace std; ; int a[maxx]; int vis[maxx]; int ans[maxx]; int block; int res; struct node { int l,r; int id; friend bool ope…
洛谷的分块练习题 看到讨论中说分块莫队被卡就写了树状数组...(但感觉做法和莫队的思想有点像?) #include<bits/stdc++.h> using namespace std; const int N=5e5+7; const int M=1e6+7; int c[N],a[N],n,m; struct node{ int l,r,ans,id; }q[N]; bool cmp(node a,node b){//按r排序 return a.r==b.r?a.l<b.l:a.r&…