08-04 NOIP simulation tests 12

It is too recent wave of

A. Fibonacci (fibonacci)

Soon also found a lot of character, but the more I thought, the brain does not know where to think, has not found an entry point (to engage in their own ignorant ratio). Then analog tag called up only 50 minutes, only 60 minutes long long open.

In fact, you will be able to find a breakthrough from the meaning of the questions, since looking lca, we just find the node number son relationship with his father, with the most bare-up marked, you can continue to turn up son from a maximum of 60 layers, can not multiplication processing array (actually can not take a space).

Then consider this father-son relationship, in fact, I tmd also found that when violence was built figure, but I did not think to do something with it. First i was born in the j-th rabbit $ num = fib [i-1] + j $, while $ 1 \ leq j \ leq fib [i-2] $, very good point is that j is its father, transpose num-fib method [i-1], then we have to find the father from the son was j =. $ \ Theta (60 ^ 2m) $ bit extreme.

Just find num less than the first FIB, monotone, direct two. $ \ Theta (60log60 m) $

Then we save space and time to build the map, happily got 100 points, good results (dancing .gif).

 1 #include<cstdio>
 2 #include<cmath>
 3 #include<algorithm>
 4 #define ll long long
 5 #define reg register
 6 #define F(i,a,b) for(register int (i)=(a);(i)<=(b);++(i))
 7 using namespace std;
 8 ll read();
 9 int m;
10 ll fib[66];
11 inline ll ef(ll x)
12 {
13     int l=1,r=62,mid;
14     while(l<r)
15     {
16         mid=(l+r)>>1;
17         if(fib[mid]>=x) r=mid;
18         else l=mid+1;
19     }
20     return fib[l-1];
21 }
22 int main()
23 {
24 //    freopen("data.in","r",stdin);
25     m=read();
26     ll x,y;
27     fib[0]=fib[1]=1;
28     F(i,2,62) fib[i]=fib[i-1]+fib[i-2];
29     F(i,1,m)
30     {
31         x=read(); y=read();
32         while(x!=y)
33         {
34             if(x>y) x^=y^=x^=y;
35             y-=ef(y);
36         }
37         printf("%lld\n",x);
38     }
39     return 0;
40 }
41 ll read()
42 {
43     ll x=0;
44     char tc=getchar();
45     while(tc<'0'||tc>'9') tc=getchar();
46     while(tc>='0'&&tc<='9') x=x*10+tc-48,tc=getchar();
47     return x;
48 }
View Code

Turned out to be less open long long TLE Well

B. The number of colors

I may be stupid to learn advanced data structures. . .

Test when a look, this is not Mo team? With or repair? I can not ah!

Then still own a YY to modify the boundaries on both sides of each sort of inquiry TLE Mo team, then kick think this board than T fly, the worst case is to ask - modify - Inquiry - modify - Inquiry - modify - Inquiry - modify then died, only 30 points.

Algorithm can actually get 70: Tree set Tree (Fenwick tree sets Chairman of the tree) (lnc), with the real Mo repair team (wd), block (whs) plus two special properties assigned to 90 (of others )hand

100% algorithm:

A algorithm: vector smart people algorithm (sdfz_dky)

Query: open vector for each color, due to the number of elements must not burst memory. col [i] [k], the position of the element is ranked prosequence (k + 1) th color rabbit where i, maintenance COL [i] ordered, then the difference can be divided to give two answers.

Review: If the color swap positions are not adjacent, a method becomes ineffective. Because it is adjacent positions, after an exchange of their relative size of the other positions it is constant. Binding algorithm a, that I just in col [a [x]] and col [a [x + 1]] dichotomous found subscript [] at col x x + 1 corresponding to the position, and to exchange their position, found no COL changes [] monotonicity, thereby eliminating the complexity of the internal nlogn complete exchange.

Then he got 75 points, good results?

Less Laid determination: If a [x] == a [x + 1] it can not be modified, will destroy monotonicity.

Algorithms II: Chairman of the tree (pa)

Two found each modification changes only the Chairman of the tree (soon forget how to write, and review!). Then violent change two trees, conventional query.

 1 #include<cstdio>
 2 #include<vector>
 3 #include<algorithm>
 4 #define reg register
 5 #define F(i,a,b) for(register int (i)=(a);(i)<=(b);++(i))
 6 using namespace std;
 7 int read();
 8 const int N=300005;
 9 int n,m;
10 int a[N];
11 vector<int> col[N];
12 int main()
13 {
14     n=read(); m=read();
15     F(i,1,n)
16     {
17         a[i]=read();
18         col[a[i]].push_back(i);
19     }
20     int opt,l,r,c;
21     F(i,1,m)
22     {
23         opt=read();
24         if(opt==1)
25         {
26             l=read();
27             r=read();
28             c=read();
29             int sum1=upper_bound(col[c].begin(),col[c].end(),l-1)-col[c].begin()-1;
30             int sum2=upper_bound(col[c].begin(),col[c].end(),r)-col[c].begin()-1;
31             printf("%d\n",sum2-sum1);
32         }
33         else
34         {
35             c=read();
36             if(a[c]==a[c+1]) continue;
37             int x1=lower_bound(col[a[c]].begin(),col[a[c]].end(),c)-col[a[c]].begin();
38             int x2=lower_bound(col[a[c+1]].begin(),col[a[c+1]].end(),c+1)-col[a[c+1]].begin();
39             col[a[c]][x1]=c+1;
40             col[a[c+1]][x2]=c;
41             swap(a[c],a[c+1]);
42         }
43     }
44     return 0;
45 }
46 int read()
47 {
48     int x=0;
49     char tc=getchar();
50     while(tc<'0'||tc>'9') tc=getchar();
51     while(tc>='0'&&tc<='9') x=x*10+tc-48,tc=getchar();
52     return x;
53 }
View Code

 

 

C. Packet

When the examination think k == $ 1 is \ Theta (n ^ 2) $ greedy. Reverse scan is set to open until there is a conflict.

The confusion is common reverse lexicographically smallest first update back guarantee, but the impact of previous answer to answer the biggest priority update later may lead to the front is not excellent.

Indeed greed is right: behind the front, the front had not only make the front of the left point to the contradiction between the right point reduction, so the left end point will not be back. In other words, the answer will not be worse.

Then T will still fall three big points.

Predicates:? $ A + b x ^ 2 $ that we were to enumerate b, verification x, but the number of b. We can turn to enumerate x, we enumerate only a maximum amount of 512, then x ^ 2-a to see whether there have been b

Unfinished. . . .

Guess you like

Origin www.cnblogs.com/hzoi-yzh/p/11297126.html