2019-8-3 test summary

A. Fibonacci

Is water, but did not see the nature,

You can get a part of its $ 70 + $, so water $ 80 to $ points.

Looking for a good law,

Each node on a number of minus $ fibonacci $ number is the number of its parent.

So every time it turned on.

That is simple, the details are important.

Ugly code:

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#define int long long
#define Maxn 300050
#define Reg register
#define abs(x) ((x)<0?(-1*(x)):(x))
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
using namespace std;
int m,num[Maxn],sup[Maxn],LCA;
int getf(int x,int y)
{
    if(x<y) swap(x,y);
    while(x>y)
    {
        int l1=lower_bound(num+1,num+59+1,x)-num;
        x=x-num[l1-1];
        if(x<y) swap(x,y);
    }
    return x;
}
signed main()
{
    scanf("%lld",&m);
    num[1]=1,num[2]=2;
    for(Reg int i=3;i<=59;++i) num[i]=num[i-1]+num[i-2];
    for(Reg int i=1,x,y;i<=m;++i)
    {
        scanf("%lld%lld",&x,&y);
        LCA=getf(x,y);
        printf("%lld\n",LCA);
    }
    return 0;
}
View Code

B. The number of colors

The word solution to a problem he said: advanced data structures to learn silly.

Do what team, what Chairman tree, tree line. .

As long as a $ vector $ on it.

$ $ Vector stored location with color.

Every binary search.

Modify the time because it is only $ x $ and $ x + 1 $ exchange, there is no change to the $ vector $ in the order of elements.

So no need to consider the sort.

Complexity $ O (nlogn) $.

Ugly code:

#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<vector>
#define int long long
#define Maxn 300050
#define Reg register
using namespace std;
int n,m,ans,A[Maxn];
vector<vector<int> > pos(Maxn);
signed main()
{
    scanf("%lld%lld",&n,&m);
    for(Reg int i=1;i<=n;++i)
    {
        scanf("%lld",&A[i]);
        pos[A[i]].push_back(i);
    }
    for(Reg int i=1,l,r,opt,c;i<=m;++i)
    {
        scanf("%lld",&opt);
        if(opt==1)
        {
            scanf("%lld%lld%lld",&l,&r,&c);
            int p1=upper_bound(pos[c].begin(),pos[c].end(),r)-pos[c].begin()-1;
            int p2=lower_bound(pos[c].begin(),pos[c].end(),l)-pos[c].begin();
            printf("%lld\n",p1-p2+1);
        }
        else
        {
            scanf("%lld",&c);
            if(c==n||A[c]==A[c+1]) continue;
            int p1=lower_bound(pos[A[c]].begin(),pos[A[c]].end(),c)-pos[A[c]].begin();
            int p2=lower_bound(pos[A[c+1]].begin(),pos[A[c+1]].end(),c+1)-pos[A[c+1]].begin();
            pos[A[c]][p1]=c+1,pos[A[c+1]][p2]=c;
            swap(A[c],A[c+1]);
        }
    }
    return 0;
}
View Code

C. Packet

 

to sum up:

Start to see $ T1 $, I feel no idea, did not find the law, it is skipped.

Then start to see $ T2 $, saw the title is definitely a data structure that.

I want to play a dynamic prescription segment tree, to see the data range of $ 3 \ times 10 ^ 5 $, then Gugu Gu.

This question test point very clearly written.

As a result, test point divide and conquer good use.

30 minutes before the violence Fenwick tree, according to the special nature of the back and then the other.

So water to $ 55 $ points.

After back to see $ T1 $, he made a $ dfs $, began to find the law.

Finally, it is still water in the $ 80 to $ points.

$ T3 $ send some points, we have got lucky. .

Otherwise it fell out.

So finally 80 + 55 + $ 32 = $ 167.

Nothing levels. . .

Guess you like

Origin www.cnblogs.com/Milk-Feng/p/11295347.html