BZOJ 2120 數顏色 暴力__BZOJ

來源:互聯網
上載者:User

題目大意:給定一個序列,提供兩種操作:

1.查詢[l,r]區間內有多少不同的數字

2.單點修改

n,m<=1W

樹套樹。主席樹。啥都不需要。這題暴力才2s,不要想複雜了。妥妥水過。

數字離散化一下。標記用時間戳記代替。675B秒切。不是一般爽。

。。。好吧如果覺得這樣沒啥意思可以試試樹狀數組套bitset 應該會快一些

總之50%達成 假期進度:66.7% 死ね

#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define M 10010using namespace std;int n,m,a[M],map[1001001],tot;int f[M+1000],T,ans;int main(){int i,j,x,y;char p[10];cin>>n>>m;for(i=1;i<=n;i++){scanf("%d",&x);if(!map[x])map[x]=++tot;a[i]=map[x];}for(i=1;i<=m;i++){scanf("%s%d%d",p,&x,&y);if(p[0]=='R'){if(!map[y])map[y]=++tot;a[x]=map[y];}else{ans=0;++T;for(j=x;j<=y;j++)if(f[ a[j] ]!=T)++ans,f[ a[j] ]=T;printf("%d\n",ans);}}}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.