Train Car Selection "CF1137E" / dance sequence "NOIP more than 2019 school entrance exam."

The meaning of problems

A given sequence, the initial length of the sequence is n, each of the sequence number 0.
Operation m times, three operations:
. 1 k is added at the beginning of the sequence numbers k 0
2 k k added to the end of the sequence numbers 0
. 3 BS to all sequence number with b + s * (i-1 ) [i is the numerical position in the sequence]
you need to output the smallest number in size and position in the sequence after each operation, if a plurality of the smallest number, output a forward-most


Thinking

It is a CF for the first title.

Positive Solutions of totally did not expect, but due to the time the exam is random data, so you can use fucks cut method.

Violence is essentially simple, the complexity is amortized \ (O (m) \) (although the card may be to \ (O (m ^ 2) \) )

Code

#include <bits/stdc++.h>

using namespace std;

namespace StandardIO {

    template<typename T>inline void read (T &x) {
        x=0;T f=1;char c=getchar();
        for (; c<'0'||c>'9'; c=getchar()) if (c=='-') f=-1;
        for (; c>='0'&&c<='9'; c=getchar()) x=x*10+c-'0';
        x*=f;
    }

    template<typename T>inline void write (T x) {
        if (x<0) putchar('-'),x*=-1;
        if (x>=10) write(x/10);
        putchar(x%10+'0');
    }

}

using namespace StandardIO;

namespace Project {
    #define int long long
    
    const int N=100100;
    
    int n,m,len,top;
    pair<int,int> ans,answer[N],tmp[N];
    
    inline void query () {
        int ll=0;
        ans.second=0x7fffffff;
        for (register int i=1; i<=top; ++i) {
            if (ans.second>answer[i].second) ans=answer[i],tmp[++ll]=ans;
        }
        for (register int i=1; i<=ll; ++i) {
            answer[i]=tmp[i];
        }
        top=ll;
    }

    inline void MAIN () {
        read(n),read(m),ans=make_pair(0,0),len=n-1,answer[++top]=ans;
        for (register int i=1,op,x,y; i<=m; ++i) {
            read(op);
            if (op==1) { 
                read(x),top=1;
                answer[top]=ans=make_pair(0,0);
                len+=x;
            } else if (op==2) {
                read(x);
                answer[++top]=make_pair(len+1,0);
                query();
                len+=x;
            } else {
                read(x),read(y);
                for (register int i=1; i<=top; ++i) answer[i].second+=x+y*answer[i].first;
                query();
            }
            write(ans.first+1),putchar(' '),write(ans.second),putchar('\n');
        }
    }
    
    #undef int
}

int main () {
//  freopen("1.in","r",stdin);
//  freopen("2.out","w",stdout);
    Project::MAIN();
}

Guess you like

Origin www.cnblogs.com/ilverene/p/11622392.html