题解 | generator 3-2019牛客暑期多校训练营第五场D题

题目来源于牛客竞赛:https://ac.nowcoder.com/acm/contest/discuss
题目描述:
题解 | generator 3-2019牛客暑期多校训练营第五场D题_第1张图片
输入描述:
题解 | generator 3-2019牛客暑期多校训练营第五场D题_第2张图片
输出描述:
题解 | generator 3-2019牛客暑期多校训练营第五场D题_第3张图片
示例1:
题解 | generator 3-2019牛客暑期多校训练营第五场D题_第4张图片
示例2:
题解 | generator 3-2019牛客暑期多校训练营第五场D题_第5张图片
题解:
题解 | generator 3-2019牛客暑期多校训练营第五场D题_第6张图片
题解 | generator 3-2019牛客暑期多校训练营第五场D题_第7张图片
题解 | generator 3-2019牛客暑期多校训练营第五场D题_第8张图片
题解 | generator 3-2019牛客暑期多校训练营第五场D题_第9张图片
代码:

/*{{{*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair PII;
typedef vector VI;
typedef vector VL;
typedef vector VPII;
typedef pair PLL;
typedef vector VPLL;
template void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template void R(T &head, U &... tail) { _R(head); R(tail...); }
template void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template void _W(const pair &x) {_W(x.F); putchar(' '); _W(x.S);}
template void _W(const vector &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 2e5+10;
struct CycleSequence {
    VI d0,d;
    void extend_st(int m) {
        if(m<=SZ(d0)) return;
        int it=0;
        while(SZ(d0)v2;
}
LL convex_hull_area(Point _p[],int N){
    REPP(i,1,N){
        if(_p[i].get_pair()<_p[0].get_pair()){
            swap(_p[0],_p[i]);
        }
    } 
    Point O=_p[0];
    REP(i,N){_p[i].x-=O.x;_p[i].y-=O.y;}
    sort(_p+1,_p+N,point_cmp);
    vectorret;
    ret.PB(_p[0]);
    REPP(i,1,N){
        while(SZ(ret)>1&&(ret.back()-ret[SZ(ret)-2])*(_p[i]-ret[SZ(ret)-2])<=0)ret.pop_back();
        ret.PB(_p[i]);
    }
    if(SZ(ret) <= 2) return 0;
    LL ans = ret[0] * ret[SZ(ret)-1];
    REPP(i,1,SZ(ret)) ans += ret[i] * ret[i-1];
    return abs(ans);
}
template
T rmqfunc(T a, T b) {
    return MP(max(a.F,b.F),min(a.S,b.S));
}

template 
class RMQ{
    public:
        vectorlog2;
        vector> values;

        template void build(IterType begin, IterType end){
            assert(begin!=end);
            int n=end-begin;
            log2=vector(n+1);
            for(int i=2;i<=n;i++)log2[i]=log2[i>>1]+1;
            values=vector >(log2.back()+1,vector(n));
            for(int i=0;i rmq;
    rmq.build(ALL(AA));
    REP(i,SZ(d2)){
        if(i>=n)break;
        LL tt = (n-1-i) / SZ(d2) + 1;
        int me=pos[i%SZ(d1)];
        int ll=me/seg*seg;
        int rr=ll+seg-1;
        PII ret;
        if(tt>=seg) {
            ret = rmq.query(ll,rr);
        }
        else if(me+tt-1<=rr) {
            ret = rmq.query(me,me+tt-1);
        }
        else {
            ret = rmqfunc(rmq.query(me,rr), rmq.query(ll,ll+tt-(rr-me+1)-1));
        }
        concerened_points[pn++] = Point(ret.F, d2[i]);
        concerened_points[pn++] = Point(ret.S, d2[i]);
    }
}
int main(){
    int x0, y0, a_x, a_y, b_x, b_y, mod_x, mod_y;
    LL n;
    R(x0, y0, a_x, a_y, b_x, b_y, mod_x, mod_y, n);
    gen(x0, a_x, b_x, mod_x, xs);
    gen(y0, a_y, b_y, mod_y, ys);
    int tail_len=max(xs.get_tail(), ys.get_tail());
    xs.extend_st(tail_len);
    ys.extend_st(tail_len);
    add_points(n - tail_len, xs.d, ys.d);
    REP(i,min(n, (LL)tail_len)) {
        concerened_points[pn++] = Point(xs.d0[i],ys.d0[i]);
    }
    W(convex_hull_area(concerened_points, pn));
    return 0;
}

更多问题,更详细题解可关注牛客竞赛区,一个刷题、比赛、分享的社区。
传送门:https://ac.nowcoder.com/acm/contest/discuss

你可能感兴趣的:(题解,19牛客暑期多校训练营第五场,题解,19牛客暑期多校训练营)