답안 #485053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
485053 2021-11-06T00:47:28 Z jeroenodb 말 (IOI15_horses) C++14
100 / 100
220 ms 70160 KB
#include "horses.h"
#include "bits/stdc++.h"
#ifdef LOCAL
#include "grader.cpp"
#endif
using namespace std;
#define all(x) begin(x),end(x)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1;
const ll oo = 1e9+1;
const long long MD = 1e9+7;
template<long long MOD=MD> struct mdint {
    int d=0;
    mdint () {d=0;}
    mdint (long long _d) : d(_d%MOD){};
    friend mdint& operator+=(mdint& a, const mdint& o) {
        a.d+=o.d; if(a.d>=MOD) a.d-=MOD;
        return a;
    }
    friend mdint& operator-=(mdint& a, const mdint& o) {
        a.d-=o.d; if(a.d<0) a.d+=MOD;
        return a;
    }
    friend mdint& operator*=(mdint& a, const mdint& o) {
        return a = mdint((ll)a.d*o.d);
    }
    mdint operator*(const mdint& o) const {
        mdint res = *this;
        res*=o;
        return res;
    }
    mdint operator+(const mdint& o) const {
        mdint res = *this;
        res+=o;
        return res;
    }
    mdint operator-(const mdint& o) const {
        mdint res = *this;
        res-=o;
        return res;
    }
    mdint operator^(long long b) const {
        mdint tmp = 1;
        mdint power = *this;
        while(b) {
            if(b&1) {
                tmp = tmp*power;
            }
            power = power*power;
            b/=2;
        }
        return tmp;
    }
    friend mdint operator/=(mdint& a, const mdint& o) {
        a *= (o^(MOD-2));
        return a;
    }
    mdint operator/(const mdint& o) {
        mdint res = *this;
        res/=o;
        return res;
    }
    bool operator==(const mdint& o) { return d==o.d;}
    bool operator!=(const mdint& o) { return d!=o.d;}
    friend istream& operator>>(istream& c, mdint& a) {return c >> a.d;}
    friend ostream& operator<<(ostream& c, const mdint& a) {return c << a.d;}
};
using  mint = mdint<MD>;
const ll Cut = 1e18;
struct node {
    mint prod=1;
    __int128 mx=0;
    ll prodl=1;
    node() {
    }
    node(int x, int y) {
        mx = (ll)x*y;
        prod=x;
        prodl=x;
    }
    void merge(const node& o) {
        prod*=o.prod;
        mx = max(mx,o.mx*prodl);
        if(Cut/prodl<o.prodl) prodl=Cut;
        else prodl*=o.prodl;
    }
    friend node merge(node a, const node& b) {
        a.merge(b);
        return a;
    }
};
struct segtree {
    int ptwo,n;
    vector<node> seg;
    segtree(){}
    node& operator[](int i) {
        return seg[i+ptwo];
    }
    segtree(int nn) {
        ptwo=1, n=nn;
        while(ptwo<n) ptwo*=2;
        seg.resize(ptwo*2);
    }
    auto query(int l, int r) {
        assert(l>=0 and l<ptwo and r >=0 and r<ptwo);
        l+=ptwo; r+=ptwo;
        node resl, resr;
        while(l and l<=r) {
            if(l%2==1) resl = merge(resl,seg[l++]);
            if(r%2==0) resr = merge(seg[r--],resr);
            l/=2; r/=2;
        }
        return merge(resl,resr);
    }
    auto cutoff() {
        if(seg[1].prodl<oo) return 0;
        int i=1;
        node nd;
        while(i<ptwo) {
            if(merge(nd,seg[i*2+1]).prodl>=oo) {
                i=i*2+1;
            } else {
                nd.merge(seg[i*2+1]);
                i=i*2;
            }
        }
        return i-ptwo;
    }
    void update(int i, int x, int y) {
        assert(i>=0 and i<ptwo);
        i+=ptwo;
        seg[i] = node(x,y);
        for(i/=2;i>=1;i/=2) {
            seg[i] = merge(seg[2*i],seg[2*i+1]);
        }
    }
    mint best() {
        int i = cutoff();
        if(i==0) {
            return ll(query(0,n-1).mx % MD);
        }
        return query(0,i-1).prod * ll( query(i,n-1).mx % MD);
    }
    void build() {
        for(int i=ptwo-1;i>=1;--i) {
            seg[i] = merge(seg[2*i],seg[2*i+1]);
        }
    }
};
segtree seg;
vi x,y;
int init(int N, int X[], int Y[]) {
    x=vi(X,X+N),y=vi(Y,Y+N);
    seg = segtree(N);
    for(auto i=0;i<N;++i) {
        seg[i] = node(x[i],y[i]);
    }
    seg.build();
    return seg.best().d;
}

int updateX(int pos, int val) {	
    x[pos]=val;
    seg.update(pos,x[pos],y[pos]);
    return seg.best().d;
}

int updateY(int pos, int val) {
	y[pos] = val;
    seg.update(pos,x[pos],y[pos]);
    return seg.best().d;
}

Compilation message

horses.cpp: In instantiation of 'mdint<MOD>::mdint(long long int) [with long long int MOD = 1000000007]':
horses.cpp:74:15:   required from here
horses.cpp:18:32: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   18 |     mdint (long long _d) : d(_d%MOD){};
      |                              ~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 432 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 58288 KB Output is correct
2 Correct 214 ms 58500 KB Output is correct
3 Correct 188 ms 58308 KB Output is correct
4 Correct 201 ms 65988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 236 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 66 ms 61320 KB Output is correct
34 Correct 65 ms 61360 KB Output is correct
35 Correct 87 ms 65612 KB Output is correct
36 Correct 88 ms 65680 KB Output is correct
37 Correct 60 ms 59528 KB Output is correct
38 Correct 59 ms 60580 KB Output is correct
39 Correct 50 ms 59340 KB Output is correct
40 Correct 70 ms 63344 KB Output is correct
41 Correct 51 ms 59408 KB Output is correct
42 Correct 54 ms 59588 KB Output is correct
43 Correct 62 ms 63652 KB Output is correct
44 Correct 61 ms 63692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 272 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 157 ms 62148 KB Output is correct
34 Correct 220 ms 66208 KB Output is correct
35 Correct 187 ms 62244 KB Output is correct
36 Correct 202 ms 65944 KB Output is correct
37 Correct 70 ms 61348 KB Output is correct
38 Correct 67 ms 61316 KB Output is correct
39 Correct 88 ms 65068 KB Output is correct
40 Correct 86 ms 64708 KB Output is correct
41 Correct 59 ms 59472 KB Output is correct
42 Correct 59 ms 60360 KB Output is correct
43 Correct 50 ms 59328 KB Output is correct
44 Correct 70 ms 63428 KB Output is correct
45 Correct 52 ms 59416 KB Output is correct
46 Correct 53 ms 59480 KB Output is correct
47 Correct 60 ms 63740 KB Output is correct
48 Correct 60 ms 63688 KB Output is correct
49 Correct 205 ms 63392 KB Output is correct
50 Correct 193 ms 63376 KB Output is correct
51 Correct 184 ms 70160 KB Output is correct
52 Correct 178 ms 69620 KB Output is correct
53 Correct 211 ms 61764 KB Output is correct
54 Correct 162 ms 62264 KB Output is correct
55 Correct 123 ms 60500 KB Output is correct
56 Correct 182 ms 65348 KB Output is correct
57 Correct 128 ms 61040 KB Output is correct
58 Correct 146 ms 61572 KB Output is correct
59 Correct 60 ms 63724 KB Output is correct