luogu_P3937 Changing

https://www.luogu.org/problem/P3937

Title Description

There are n- n-lamp arranged in a ring are sequentially numbered clockwise . 1 \ n-cdots . 1 n-. Initial time of 0 0 of the initial time i On i Off lamp a_i A i given, 0 0 for off, . 1 1 denotes light. The next time each lamp blinking lamp depending on which direction the next clockwise lamp current time blinking. If the two lights the same state, then the next time the lamp is off, otherwise the lights.

Find the time T T of k state k lamp.

Input Format

The first row, three integers are n-, T, K n- , T , K.

Second row, a total of n- n-integers, respectively, 0 0 or . 1 1 representing a_i A I .

Output Format

A total line, a number, 0 0 or . 1 1 representing the time T T of k state k lamp.

Sample input and output

Input # 1
4 2 1
1 0 1 0
Output # 1
0

Description / Tips

For 25 \% 2 . 5 % of the data, there . 1 \ Leq T, K \ n-Leq \ Leq 1000 . 1 T , K n- . 1 0 0 0.

For 60 \% . 6 0 % of the data, there . 1 \ Leq T, K \ n-Leq \ ^ Leq 10. 5 . 1 T , K n- . 1 0 . 5.

For 100 \% . 1 0 0 % of the data, there . 1 \ Leq T, K \ n-Leq \ Leq. 3 * 10 ^. 6 . 1 T , K n- . 3 * . 1 0 . 6.


 

Find the next rule, we found N (log (N) / log (2)) approaches

Assume k = 1, we see the answer to this one

0  time, ans = a1

time, ans = a1 ^ a2

time, ANS = A1 ^ A2 ^ A3 ^ A2 = A1 ^ A3

time, ans = a1 ^ a2 ^ a3 ^ a4

时刻, = a1 's ^ by ans ^ A2 ^ A2 ^ 3a , 3a , ^ ^ Forum a4 ^ A5 = Forum a4 a1 's ^ A5

5 ......................................................................................

............................................................................................

...................................................................................................

8 time, ans = ............................................. = ............................................ A1 ^ A9


Such log (N) / log (2 ) to come out, and does not in fact T

Multiplication and similar at the Method LCA

#include<iostream>
#include<cstdio>

#define ri register int
#define u int

namespace opt {

    inline u in() {
        u x(0),f(1);
        char s(getchar());
        while(s<'0'||s>'9') {
            if(s=='-') f=-1;
            s=getchar();
        }
        while(s>='0'&&s<='9') {
            x=(x<<1)+(x<<3)+s-'0';
            s=getchar();
        }
        return x*f;
    }

}

using opt::in;

#include<cmath>
#include<algorithm>

#define NN 3000005

namespace mainstay {

    u N,T,K,a[NN<<1];

    inline void solve() {
        while(~scanf("%d%d%d",&N,&T,&K)) {
            for(ri i(1); i<=N; ++i) a[i]=a[i+N]=in();
            u ans(a[K]);
            while(T) {
                u k(std::log(T)/std::log(2));
                u p(std::pow(2,k));
                ans^=a[K+p];
                for(ri i(1); i<=N; ++i) a[i]^=a[i+p];
                for(ri i(1); i<=N; ++i) a[i+N]=a[i];
                T-=std::pow(2,k);
            }
            printf("%d\n",ans);
        }
    }

}

int main() {

    //freopen("TLE.in","r",stdin);
    //freopen("TLE.out","w",stdout);
    std::ios::sync_with_stdio(false);
    mainstay::solve();

}

 

Guess you like

Origin www.cnblogs.com/ling-zhi/p/11774108.html