HZOJ number of colors

At a glance tree cover tree ah, I may be a data structure to learn silly ......

Mo is supposed to learn about the team advanced things.

Above that thing I did not play, so there is no code, and it should not be difficult to understand.

So much even if the balance of the tree, but the tree is still very good line play.

Correct answer 3:

Chairman of the tree ah, in fact, do not need to add a tree-like array, because each change affects only the two, violent modify on the line.

Correct answer 4:

Block (violence but is running so fast).

The following is a real positive solutions:

Rabbits in a first color keyword, keyword ranking position to the second, to find the number of colors within a certain range by half rabbit.

As for changes, just need to find two rabbits, to swap its position, because two rabbits are adjacent, and thus would not undermine orderly.

 

 1 #include<algorithm>
 2 #include<iostream>
 3 #include<utility>
 4 #include<cstdio>
 5 #include<vector>
 6 #define LL long long
 7 #define int LL
 8 #define MAXN 300010
 9 using namespace std;
10 int n,m,b[MAXN];
11 const int INF=0;
12 pair<int,int> a[MAXN];
13 inline int read();
14 signed main()
15 {
16 //    freopen("in.txt","r",stdin);
17 
18     n=read(),m=read();
19     for(int i=1;i<=n;i++)a[i].first=read(),a[i].second=i,b[i]=a[i].first;//a[i]=read();
20     sort(a+1,a+n+1);
21     int op,x,l,r,c;
22     for(int i=1;i<=m;i++)
23     {
24         op=read();
25         if(op==1)
26         {
27             l=read(),r=read(),c=read();
28             int len1=(upper_bound(a+1,a+n+1,make_pair(c,r))-a),len2=(lower_bound(a+1,a+n+1,make_pair(c,l))-a);
29             printf("%lld\n",len1-len2);
30         }
31         else
32         {
33             x=read();    
34             if(b[x]==b[x+1])continue;
35             int tem1=lower_bound(a+1,a+n+1,make_pair(b[x],x))-a,tem2=lower_bound(a+1,a+n+1,make_pair(b[x+1],x+1))-a;
36             swap(a[tem1].second,a[tem2].second);swap(b[x],b[x+1]);
37         }
38     }
39 }
40 inline int read()
41 {
42     int s=0,f=1;char a=getchar();
43     while(a<'0'||a>'9'){if(a=='-')f=-1;a=getchar();}
44     while(a>='0'&&a<='9'){s=s*10+a-'0';a=getchar();}
45     return s*f;
46 }
View Code

 

Guess you like

Origin www.cnblogs.com/Al-Ca/p/11296094.html