Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)

Binary Session, FST has also been a problem.

A, sign, question is intended that a given a, b, c

f(0)=a,f(1)=b,f(n)=f(n-1)^f(n-2)

Seeking f (n)

Simplifying somewhat to see that f (x) is the cycle appear in a, b, a ^ b

In为 a ^ b ^ a = b, a ^ b ^ b = a

Code:

#include <bits/stdc++.h>
#define int long long
#define sc(a) scanf("%lld",&a)
#define scc(a,b) scanf("%lld %lld",&a,&b)
#define sccc(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define schar(a) scanf("%c",&a)
#define pr(a) printf("%lld",a)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define re(i,a,b) for(int i=a;i<=b;++i)
#define rfo(i,a,b) for(int i=a;i>b;--i)
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define prn() printf("\n")
#define prs() printf(" ")
#define mkp make_pair
#define pii pair<int,int>
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define fst first
#define snd second
#define frt front()
#define bak back()
#define mem0(a) memset(a,0,sizeof(a))
#define memmx(a) memset(a,0x3f3f,sizeof(a))
#define memmn(a) memset(a,-0x3f3f,sizeof(a))
#define debug
#define db double
#define yyes cout<<"YES"<<endl;
#define nno cout<<"NO"<<endl;
using namespace std;
typedef vector<int> vei;
typedef vector<pii> vep;
typedef map<int,int> mpii;
typedef map<char,int> mpci;
typedef map<string,int> mpsi;
typedef deque<int> deqi;
typedef deque<char> deqc;
typedef priority_queue<int> mxpq;
typedef priority_queue<int,vector<int>,greater<int> > mnpq;
typedef priority_queue<pii> mxpqii;
typedef priority_queue<pii,vector<pii>,greater<pii> > mnpqii;
const int maxn=500005;
const int inf=0x3f3f3f3f3f3f3f3f;
const int MOD=100000007;
const db eps=1e-10;
int qpow(int a,int b){int tmp=a%MOD,ans=1;while(b){if(b&1){ans*=tmp,ans%=MOD;}tmp*=tmp,tmp%=MOD,b>>=1;}return ans;}
int lowbit(int x){return x&-x;}
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
int mmax(int a,int b,int c){return max(a,max(b,c));}
int mmin(int a,int b,int c){return min(a,min(b,c));}
void mod(int &a){a+=MOD;a%=MOD;}
bool chk(int now){}
int half(int l,int r){while(l<=r){int m=(l+r)/2;if(chk(m))r=m-1;else l=m+1;}return l;}
int ll(int p){return p<<1;}
int rr(int p){return p<<1|1;}
int mm(int l,int r){return (l+r)/2;}
int lg(int x){if(x==0) return 1;return (int)log2(x)+1;}
bool smleql(db a,db b){if(a<b||fabs(a-b)<=eps)return true;return false;}
db len(db a,db b,db c,db d){return sqrt((a-c)*(a-c)+(b-d)*(b-d));}
bool isp(int x){if(x==1)return false;if(x==2)return true;for(int i=2;i*i<=x;++i)if(x%i==0)return false;return true;}

int t,a,b,n;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>t;
    while(t--){
        cin>>a>>b>>n;
        if(n==0) cout<<a<<endl;
        else if(n==1) cout<<b<<endl;
        else{
            int k=n%3;
            if(k==0) cout<<a<<endl;
            else if(k==1) cout<<b<<endl;
            else cout<<(a^b)<<endl;
        }
    }
    return 0;
}

B, the FST is a question, the question is intended to select a [l, r] continuum it omitted, so that the remaining digital pairwise identical, no output 0 can be omitted

Problem consecutive sub-segment of my foot on the borrowing, assuming [l, r] interval is the interval I to be deleted, and continuously reduced in the case of determining r l, and to find the smallest range.

Beginning after a few pp, thought for a moment and found to be deleted began a period ending continuum case is not taken into account, add a little judgment passed pp.

Later, looking for a half-day a little small hack, finally let me turn to:

8
1 2 3 4 2 6 5 4

Obviously it should be removed on the fourth and fifth 2,4, but I output 3, debug, it was found [l, r] section simply do not traverse to the fourth and fifth place up.

See Positive solutions found O (n ^ 2logn) to the effect that only a prefix and a suffix left after deleting the sub-interval period, their length may be 0

Then the enumeration did not repeat prefix length, the longest not find any duplicate numbers suffix, you can live with map maintenance, before attention suffix are empty subscript details

Code:

#include <bits/stdc++.h>
#define int long long
#define sc(a) scanf("%lld",&a)
#define scc(a,b) scanf("%lld %lld",&a,&b)
#define sccc(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define schar(a) scanf("%c",&a)
#define pr(a) printf("%lld",a)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define re(i,a,b) for(int i=a;i<=b;++i)
#define rfo(i,a,b) for(int i=a;i>b;--i)
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define prn() printf("\n")
#define prs() printf(" ")
#define mkp make_pair
#define pii pair<int,int>
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define fst first
#define snd second
#define frt front()
#define bak back()
#define mem0(a) memset(a,0,sizeof(a))
#define memmx(a) memset(a,0x3f3f,sizeof(a))
#define memmn(a) memset(a,-0x3f3f,sizeof(a))
#define debug
#define db double
#define yyes cout<<"YES"<<endl;
#define nno cout<<"NO"<<endl;
using namespace std;
typedef vector<int> vei;
typedef vector<pii> vep;
typedef map<int,int> mpii;
typedef map<char,int> mpci;
typedef map<string,int> mpsi;
typedef deque<int> deqi;
typedef deque<char> deqc;
typedef priority_queue<int> mxpq;
typedef priority_queue<int,vector<int>,greater<int> > mnpq;
typedef priority_queue<pii> mxpqii;
typedef priority_queue<pii,vector<pii>,greater<pii> > mnpqii;
const int maxn=500005;
const int inf=0x3f3f3f3f3f3f3f3f;
const int MOD=100000007;
const db eps=1e-10;
int qpow(int a,int b){int tmp=a%MOD,ans=1;while(b){if(b&1){ans*=tmp,ans%=MOD;}tmp*=tmp,tmp%=MOD,b>>=1;}return ans;}
int lowbit(int x){return x&-x;}
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
int mmax(int a,int b,int c){return max(a,max(b,c));}
int mmin(int a,int b,int c){return min(a,min(b,c));}
void mod(int &a){a+=MOD;a%=MOD;}
bool chk(int now){}
int half(int l,int r){while(l<=r){int m=(l+r)/2;if(chk(m))r=m-1;else l=m+1;}return l;}
int ll(int p){return p<<1;}
int rr(int p){return p<<1|1;}
int mm(int l,int r){return (l+r)/2;}
int lg(int x){if(x==0) return 1;return (int)log2(x)+1;}
bool smleql(db a,db b){if(a<b||fabs(a-b)<=eps)return true;return false;}
db len(db a,db b,db c,db d){return sqrt((a-c)*(a-c)+(b-d)*(b-d));}
bool isp(int x){if(x==1)return false;if(x==2)return true;for(int i=2;i*i<=x;++i)if(x%i==0)return false;return true;}
 
int n,a[maxn];
mpii mp;
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n;
    re(i,1,n) cin>>a[i];
    int ans=n-1;
    re(i,1,n){
        bool can=1;
        mp.clear();
        re(j,1,i-1){
            mp[a[j]]++;
            if(mp[a[j]]==2){
                can=0;
                break;
            }
        }
        int p=n+1;
        rre(j,n,i){
            mp[a[j]]++;
            if(mp[a[j]]==1) p=j;
            else break;
        }
        if(can) ans=min(ans,p-i);
    }
    cout<<ans;
    return 0;
}
/*
6
2 2 3 3 4 2
8
1 2 3 4 2 6 5 4
10
7 6 5 4 3 2 1 7 7 7
*/

C, a given n, n is a multiple of 4 to ensure that, constructs a matrix of n * n, so that the [0, n 2-1 ^] among each number occurs only once in each row and each column of the matrix and exclusive OR the same

First guess conclusion, the ranks of the XOR and are 0

When the game ly solution to the four groups of four, I did not quite understand, after the game to discuss with zyf long time and finally we get to know.

First just find a 4 * 4 matrix to meet the conditions, I use the following:

This fact, used the following conclusion, in which PS.

0   1   2   3

4   5   6   7

8   9   10   11

12   13   14   15

Consider such a thing:

a ^ b = (a + c ) ^ (b + c) what conditions?

The answer is c> a && c> b

In fact, if c> a, then a + c will only be made in the original binary bits 0 as a change, and after an even number of exclusive-OR and XOR becomes 0

Rei如: A ^ A = 0, A ^ A ^ A ^ A = 0

So the 4 x 4 matrix is ​​repeated every time you can add 16,32,48

The following function is used to get a point number is obtained, similar to the matrix of n rows and n columns, a [i] [j] in front of a total of i * n + j th element (i, j from 0)

True to the data structure of the final exam chant.

Code:

#include <bits/stdc++.h>
#define int long long
#define sc(a) scanf("%lld",&a)
#define scc(a,b) scanf("%lld %lld",&a,&b)
#define sccc(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define schar(a) scanf("%c",&a)
#define pr(a) printf("%lld",a)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define re(i,a,b) for(int i=a;i<=b;++i)
#define rfo(i,a,b) for(int i=a;i>b;--i)
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define prn() printf("\n")
#define prs() printf(" ")
#define mkp make_pair
#define pii pair<int,int>
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define fst first
#define snd second
#define frt front()
#define bak back()
#define mem0(a) memset(a,0,sizeof(a))
#define memmx(a) memset(a,0x3f3f,sizeof(a))
#define memmn(a) memset(a,-0x3f3f,sizeof(a))
#define debug
#define db double
#define yyes cout<<"YES"<<endl;
#define nno cout<<"NO"<<endl;
using namespace std;
typedef vector<int> vei;
typedef vector<pii> vep;
typedef map<int,int> mpii;
typedef map<char,int> mpci;
typedef map<string,int> mpsi;
typedef deque<int> deqi;
typedef deque<char> deqc;
typedef priority_queue<int> mxpq;
typedef priority_queue<int,vector<int>,greater<int> > mnpq;
typedef priority_queue<pii> mxpqii;
typedef priority_queue<pii,vector<pii>,greater<pii> > mnpqii;
const int maxn=500005;
const int inf=0x3f3f3f3f3f3f3f3f;
const int MOD=100000007;
const db eps=1e-10;
int qpow(int a,int b){int tmp=a%MOD,ans=1;while(b){if(b&1){ans*=tmp,ans%=MOD;}tmp*=tmp,tmp%=MOD,b>>=1;}return ans;}
int lowbit(int x){return x&-x;}
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
int mmax(int a,int b,int c){return max(a,max(b,c));}
int mmin(int a,int b,int c){return min(a,min(b,c));}
void mod(int &a){a+=MOD;a%=MOD;}
bool chk(int now){}
int half(int l,int r){while(l<=r){int m=(l+r)/2;if(chk(m))r=m-1;else l=m+1;}return l;}
int ll(int p){return p<<1;}
int rr(int p){return p<<1|1;}
int mm(int l,int r){return (l+r)/2;}
int lg(int x){if(x==0) return 1;return (int)log2(x)+1;}
bool smleql(db a,db b){if(a<b||fabs(a-b)<=eps)return true;return false;}
db len(db a,db b,db c,db d){return sqrt((a-c)*(a-c)+(b-d)*(b-d));}
bool isp(int x){if(x==1)return false;if(x==2)return true;for(int i=2;i*i<=x;++i)if(x%i==0)return false;return true;}

int n;
int ans[1005][1005];
int a[4][4]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};

void out(){
    fo(i,0,n){
        fo(j,0,n){
            cout<<ans[i][j]<<' ';
        }
        cout<<endl;
    }
}

int get(int i,int j){
    return (n/4)*(i/4)+(j/4);
}

void solve(){
    fo(i,0,n){
        fo(j,0,n){
            ans[i][j]=get(i,j)*16+a[i%4][j%4];
        }
    }
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n;
    solve();
    out();
    return 0;
}

PS: Hey learned from here a conclusion, a multiple number of consecutive 4 4 ​​and the start of the exclusive OR is 0

For example, 0,1,2,3 and 8,9,10,11

 

D, n is assumed here there is arranged a digital each position is pi, i represents Si until all numbers less than the sum of pi and a

Now given n and si, you want to rebuild pi, ensure solvability

Consider first position 1, assuming there is such an arrangement:

3   2   5   1   4

It si array is easy to find:

0   0   5   0   6

First, for 1, it corresponds to a certain position on the si is 0, because there will be no smaller than 1 digital and 1 for all numbers in the back of their si certainly not zero, which means the last 0 the position must be 1

In the above example, first find the position 1, and begin to rebuild pi:

*   *   *   1   *

Then the position on the si set to infinity, and all of the minus 1 si rear position, this step can maintain occupancy segment tree, as shown in FIG si:

0   0   5   inf   5

At this time, looking at position 2, it is clear that disappears after 1, 2 become the smallest number, the last position at this time is a 0 position 2, the above-described operation is repeated.

pi:*  2   *  1   *

si: 0-inf inf 3 2 3

Algorithm here has been very clear, to maintain the value of si live with tree line, from 1 to n back filling numbers.

The following question is how to find the location of the last logn 0, using the binary search tree line down to, every time look at whether the right is the minimum 0, if not, look to the left, so that will be able to find the right position 0.

The writing of biography written under the mark pot, I actually only only under the pass mark is equal to 0 at the time, later or less! A is equal to 0 to determine a multi-use ==

Code:

#include <bits/stdc++.h>
#define int long long
#define sc(a) scanf("%lld",&a)
#define scc(a,b) scanf("%lld %lld",&a,&b)
#define sccc(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define schar(a) scanf("%c",&a)
#define pr(a) printf("%lld",a)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define re(i,a,b) for(int i=a;i<=b;++i)
#define rfo(i,a,b) for(int i=a;i>b;--i)
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define prn() printf("\n")
#define prs() printf(" ")
#define mkp make_pair
#define pii pair<int,int>
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define fst first
#define snd second
#define frt front()
#define bak back()
#define mem0(a) memset(a,0,sizeof(a))
#define memmx(a) memset(a,0x3f3f,sizeof(a))
#define memmn(a) memset(a,-0x3f3f,sizeof(a))
#define debug
#define db double
#define yyes cout<<"YES"<<endl;
#define nno cout<<"NO"<<endl;
using namespace std;
typedef vector<int> vei;
typedef vector<pii> vep;
typedef map<int,int> mpii;
typedef map<char,int> mpci;
typedef map<string,int> mpsi;
typedef deque<int> deqi;
typedef deque<char> deqc;
typedef priority_queue<int> mxpq;
typedef priority_queue<int,vector<int>,greater<int> > mnpq;
typedef priority_queue<pii> mxpqii;
typedef priority_queue<pii,vector<pii>,greater<pii> > mnpqii;
const int maxn=1000005;
const int inf=0x3f3f3f3f3f3f3f3f;
const int MOD=100000007;
const db eps=1e-10;
int qpow(int a,int b){int tmp=a%MOD,ans=1;while(b){if(b&1){ans*=tmp,ans%=MOD;}tmp*=tmp,tmp%=MOD,b>>=1;}return ans;}
int lowbit(int x){return x&-x;}
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
int mmax(int a,int b,int c){return max(a,max(b,c));}
int mmin(int a,int b,int c){return min(a,min(b,c));}
void mod(int &a){a+=MOD;a%=MOD;}
bool chk(int now){}
int half(int l,int r){while(l<=r){int m=(l+r)/2;if(chk(m))r=m-1;else l=m+1;}return l;}
int ll(int p){return p<<1;}
int rr(int p){return p<<1|1;}
int mm(int l,int r){return (l+r)/2;}
int lg(int x){if(x==0) return 1;return (int)log2(x)+1;}
bool smleql(db a,db b){if(a<b||fabs(a-b)<=eps)return true;return false;}
db len(db a,db b,db c,db d){return sqrt((a-c)*(a-c)+(b-d)*(b-d));}
bool isp(int x){if(x==1)return false;if(x==2)return true;for(int i=2;i*i<=x;++i)if(x%i==0)return false;return true;}

int n,s[maxn],ans[maxn];
int tr[maxn],tag[maxn];

void up(int p){tr[p]=min(tr[ll(p)],tr[rr(p)]);}
void down(int p){
    if(tag[p]){
        tr[ll(p)]+=tag[p];
        tr[rr(p)]+=tag[p];
        tag[ll(p)]+=tag[p];
        tag[rr(p)]+=tag[p];
        tag[p]=0;
    }
}

void build(int p,int l,int r){
    if(l==r){
        tr[p]=s[l];
        return;
    }
    int m=mm(l,r);
    build(ll(p),l,m);
    build(rr(p),m+1,r);
    up(p);
}

int q(int p,int l,int r,int pos){
    if(l==r&&l==pos)
        return tr[p];
    int m=mm(l,r);
    down(p);
    int ans;
    if(pos<=m) ans=q(ll(p),l,m,pos);
    else ans=q(rr(p),m+1,r,pos);
    up(p);
    return ans;
}

void change(int p,int l,int r,int L,int R,int v){
    if(L<=l&&r<=R){
        tr[p]+=v;
        tag[p]+=v;
        return;
    }
    int m=mm(l,r);
    down(p);
    if(L<=m) change(ll(p),l,m,L,R,v);
    if(R>m) change(rr(p),m+1,r,L,R,v);
    up(p);
}

int pos(int p,int l,int r){
    if(l==r) return l;
    int res=-1;
    int m=mm(l,r);
    down(p);
    if(tr[rr(p)]==0)
        res=pos(rr(p),m+1,r);
    else
        res=pos(ll(p),l,m);
    up(p);
    return res;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n;
    re(i,1,n) cin>>s[i];
    memmx(tr);
    build(1,1,n);
    re(i,1,n){
        int p=pos(1,1,n);
//        re(j,1,n) cout<<q(1,1,n,j)<<" \n"[j==n];
        ans[p]=i;
        if(p!=n) change(1,1,n,p+1,n,-i);
        change(1,1,n,p,p,inf);
    }
    re(i,1,n) cout<<ans[i]<<' ';
    return 0;
}
/*
5
0 1 1 1 10
*/

 

Guess you like

Origin www.cnblogs.com/oneman233/p/11462735.html