题解 P1972 【[SDOI2009]HH的项链】
Xeonacid
2017-12-29 22:24:14
O(NM)模拟。
主站大概率可AC。
大牛分站完全可AC。
评测记录:
```cpp
#include<bits/extc++.h>
using namespace std;
int N,M,a[50010]; //原数组
bool vis[50010]; //判重数组
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); //针对iostream的小优化,帮助卡常
cin>>N;
for(register int i=1;i<=N;++i)
cin>>a[i];
int L,R,ans;
cin>>M;
while(M--){
memset(vis,0,sizeof vis),ans=0; //每次询问前清零
cin>>L>>R;
for(register int i=L;i<=R;++i)
if(!vis[a[i]])vis[a[i]]=1,++ans; //模拟,非重复更新答案。
cout<<ans<<\n';
}
}
https://www.luogu.org/record/show?rid=5175815
https://www.luogu.org/record/show?rid=5175925
https://daniu.luogu.org/record/show?rid=5175934
```