QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#741080#9569. Subwayucup-team2796AC ✓339ms98212kbC++2317.6kb2024-11-13 13:16:352024-11-13 13:16:36

Judging History

你现在查看的是最新测评结果

  • [2024-11-13 13:16:36]
  • 评测
  • 测评结果:AC
  • 用时:339ms
  • 内存:98212kb
  • [2024-11-13 13:16:35]
  • 提交

answer

#line 1 "library/Template/template.hpp"
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}
#line 2 "library/Utility/fastio.hpp"
#include <unistd.h>
namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf

uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio

using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */
#line 3 "sol.cpp"

template <unsigned mod = 1000000007> struct fp {
    unsigned v;
    static constexpr int get_mod() {
        return mod;
    }
    constexpr unsigned inv() const {
        assert(v != 0);
        int x = v, y = mod, p = 1, q = 0, t = 0, tmp = 0;
        while (y > 0) {
            t = x / y;
            x -= t * y, p -= t * q;
            tmp = x, x = y, y = tmp;
            tmp = p, p = q, q = tmp;
        }
        if (p < 0)
            p += mod;
        return p;
    }
    constexpr fp(ll x = 0) : v(x >= 0 ? x % mod : (mod - (-x) % mod) % mod) {}
    fp operator-() const {
        return fp() - *this;
    }
    fp pow(ull t) {
        fp res = 1, b = *this;
        while (t) {
            if (t & 1)
                res *= b;
            b *= b;
            t >>= 1;
        }
        return res;
    }
    fp &operator+=(const fp &x) {
        if ((v += x.v) >= mod)
            v -= mod;
        return *this;
    }
    fp &operator-=(const fp &x) {
        if ((v += mod - x.v) >= mod)
            v -= mod;
        return *this;
    }
    fp &operator*=(const fp &x) {
        v = ull(v) * x.v % mod;
        return *this;
    }
    fp &operator/=(const fp &x) {
        v = ull(v) * x.inv() % mod;
        return *this;
    }
    fp operator+(const fp &x) const {
        return fp(*this) += x;
    }
    fp operator-(const fp &x) const {
        return fp(*this) -= x;
    }
    fp operator*(const fp &x) const {
        return fp(*this) *= x;
    }
    fp operator/(const fp &x) const {
        return fp(*this) /= x;
    }
    bool operator==(const fp &x) const {
        return v == x.v;
    }
    bool operator!=(const fp &x) const {
        return v != x.v;
    }
    friend istream &operator>>(istream &is, fp &x) {
        return is >> x.v;
    }
    friend ostream &operator<<(ostream &os, const fp &x) {
        return os << x.v;
    }
};

template <unsigned mod> void rd(fp<mod> &x) {
    fastio::rd(x.v);
}
template <unsigned mod> void wt(fp<mod> x) {
    fastio::wt(x.v);
}
template <typename T> T Inv(ll n) {
    static int md;
    static vector<T> buf({0, 1});
    if (md != T::get_mod()) {
        md = T::get_mod();
        buf = vector<T>({0, 1});
    }
    assert(n > 0);
    n %= md;
    while (SZ(buf) <= n) {
        int k = SZ(buf), q = (md + k - 1) / k;
        buf.push_back(buf[k * q - md] * q);
    }
    return buf[n];
}

template <typename T> T Fact(ll n, bool inv = 0) {
    static int md;
    static vector<T> buf({1, 1}), ibuf({1, 1});
    if (md != T::get_mod()) {
        md = T::get_mod();
        buf = ibuf = vector<T>({1, 1});
    }
    assert(n >= 0 and n < md);
    while (SZ(buf) <= n) {
        buf.push_back(buf.back() * SZ(buf));
        ibuf.push_back(ibuf.back() * Inv<T>(SZ(ibuf)));
    }
    return inv ? ibuf[n] : buf[n];
}

template <typename T> T nPr(int n, int r, bool inv = 0) {
    if (n < 0 || n < r || r < 0)
        return 0;
    return Fact<T>(n, inv) * Fact<T>(n - r, inv ^ 1);
}
template <typename T> T nCr(int n, int r, bool inv = 0) {
    if (n < 0 || n < r || r < 0)
        return 0;
    return Fact<T>(n, inv) * Fact<T>(r, inv ^ 1) * Fact<T>(n - r, inv ^ 1);
}
// sum = n, r tuples
template <typename T> T nHr(int n, int r, bool inv = 0) {
    return nCr<T>(n + r - 1, r - 1, inv);
}
// sum = n, a nonzero tuples and b tuples
template <typename T> T choose(int n, int a, int b) {
    if (n == 0)
        return !a;
    return nCr<T>(n + b - 1, a + b - 1);
}

template<typename T,T MX>struct CHT{
    using Line=pair<T,T>;
    int n;
    vector<T> xs;
    vector<Line> ls;
    CHT(){}
    CHT(vector<T>& ps){
        xs=ps;
        UNIQUE(xs);
        n=1;
        while(n<(int)xs.size())n<<=1;
        xs.resize(n,xs.back());
        ls.resize(2*n-1,Line(0,MX));
    }
    T eval(Line& f,T x){return f.first*x+f.second;}
    void add(T a,T b,int k=0,int L=0,int R=-1){
        if(R==-1)R=n;
        Line f={a,b};
        while(L!=R){
            int mid=(L+R)>>1;
            T lx=xs[L],mx=xs[mid],rx=xs[R-1];
            Line& g=ls[k];
            if(eval(f,lx)<eval(g,lx) and eval(f,rx)<eval(g,rx)){
                g=f;
                return;
            }
            if(eval(f,lx)>=eval(g,lx) and eval(f,rx)>=eval(g,rx))return;
            if(eval(f,mx)<eval(g,mx))swap(f,g);
            if(eval(f,lx)<eval(g,lx)){
                k=k*2+1;
                R=mid;
            }
            else{
                k=k*2+2;
                L=mid;
            }
        }
    }
    void add_segment(T a,T b,T L,T R){
        int l=lower_bound(ALL(xs),L)-xs.begin(),r=lower_bound(ALL(xs),R)-xs.begin();
        int a0=l,b0=r;
        l+=n,r+=n;
        int sz=1;
        while(l<r){
            if(r&1){
                r--;
                b0-=sz;
                add(a,b,r-1,b0,b0+sz);
            }
            if(l&1){
                add(a,b,l-1,a0,a0+sz);
                l++;
                a0+=sz;
            }
            l>>=1;
            r>>=1;
            sz<<=1;
        }
    }
    T getmin(T x){
        int k=lower_bound(ALL(xs),x)-xs.begin()+n-1;
        T res=eval(ls[k],x);
        while(k){
            k=(k-1)>>1;
            chmin(res,eval(ls[k],x));
        }
        return res;
    }
};


int main() {
    int n,k;
    read(n,k);
    vector<ll> a(k),b(k);
    read(a,b);
    using P=pair<ll,ll>;
    vector<vector<P>> train(k);
    vector<vector<P>> belong(n); // {train num,pos}
    vector<vector<int>> belord(k); // index of train[i][j] in belong[v] 
    rep(i,0,k){
        int m;
        read(m);
        train[i].resize(m);
        rep(j,0,m){
            int x,w;
            if(j!=0)read(w);
            read(x);
            x--;
            train[i][j]={x,w};
        }
    }

    // sort a
    {
        vector<int> ord(k);
        iota(ALL(ord),0);
        sort(ALL(ord),[&](int i,int j){
            return a[i]<a[j];
        });
        vector<ll> _a(k),_b(k);
        vector<vector<P>> _t(k);
        rep(i,0,k){
            _a[i]=a[ord[i]];
            _b[i]=b[ord[i]];
            _t[i]=train[ord[i]];
        }
        swap(a,_a);
        swap(b,_b);
        swap(train,_t);
        rep(i,0,k){
            belord[i].resize(SZ(train[i]));
            rep(j,0,SZ(train[i])){
                int x=train[i][j].first;
                belord[i][j]=SZ(belong[x]);
                belong[x].push_back({i,j});
            }
        }
    }

    vector dist(n,vector<ll>());
    rep(i,0,n)dist[i].resize(SZ(belong[i]),INF);
    using T=pair<ll,P>;
    priority_queue<T,vector<T>,greater<T>> pq;
    rep(j,0,SZ(belong[0])){
        dist[0][j]=0;
        pq.push({0,{0,j}});
    }

    vector reach(n,vector<int>());
    vector<int> mex(n);
    vector<CHT<ll,INF>> cht(n);
    rep(i,0,n){
        reach[i].resize(SZ(belong[i]));
        vector<ll> xs;
        for(auto& [x,_]:belong[i])xs.push_back(a[x]);
        cht[i]=CHT<ll,INF>(xs);
    }

    while(!pq.empty()){
        auto [D,xy]=pq.top();
        auto [x,y]=xy;
        auto [tnum,tpos]=belong[x][y];
        pq.pop();
        if(dist[x][y]!=D)continue;
        reach[x][y]=1;
        cht[x].add(b[tnum],D);
        // next train pos
        {
            if(tpos!=SZ(train[tnum])-1){
                int npos=tpos+1;
                auto [nv,cost]=train[tnum][npos];
                int id=belord[tnum][npos];
                if(chmin(dist[nv][id],D+cost)){
                    pq.push({dist[nv][id],{nv,id}});
                }
            }
        }

        // transfer another train
        {
            if(x!=0){
                while(mex[x]<SZ(belong[x]) and reach[x][mex[x]]==1){
                    mex[x]++;
                }
                if(mex[x]==SZ(belong[x])){
                    continue;
                }
                auto [id,_]=belong[x][mex[x]];
                ll nd=cht[x].getmin(a[id]);
                if(chmin(dist[x][mex[x]],nd)){
                    pq.push({dist[x][mex[x]],{x,mex[x]}});
                }
            }
        }
    }

    rep(v,1,n){
        show(dist[v]);
        ll ret=MIN(dist[v]);
        print(ret);
    }
    return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3736kb

input:

6 3
1 5 1
5 5 1
3 1 2 2 3 3
3 5 1 2 1 4
3 3 4 5 4 6

output:

2
5
21
14
18

result:

ok 5 number(s): "2 5 21 14 18"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3748kb

input:

6 3
1 5 1
5 5 1
5 1 2 2 100 3 100 6 1 4
5 1 100 2 4 3 100 5 1 4
2 3 1 5

output:

2
31
43
37
136

result:

ok 5 number(s): "2 31 43 37 136"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3716kb

input:

5 9
278281 70119 511791 834898 25300 63487 609134 236836 394497
835557 287345 579404 879128 636344 306393 569430 152565 47119
2 3 823004250 4
2 1 25427550 3
2 1 15849621 3
2 1 701911826 5
3 5 679672631 3 907176714 2
2 1 817370554 2
2 3 697987914 2
2 4 873900795 2
2 1 814305954 5

output:

817370554
15849621
80811085745
701911826

result:

ok 4 number(s): "817370554 15849621 80811085745 701911826"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3664kb

input:

5 10
436148 103565 528276 212202 680282 92724 609031 560815 80390 406327
546832 581372 731920 348686 791433 98906 112247 118131 361076 724950
4 1 213029090 4 415633732 5 581145231 3
2 4 306227294 2
2 1 713116112 4
2 3 99672714 5
2 3 975143846 1
5 4 249118026 5 689334413 1 597093740 2 553624319 3
3 4...

output:

597093740
765908995
213029090
628662822

result:

ok 4 number(s): "597093740 765908995 213029090 628662822"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3656kb

input:

3 5
696710 837216 390019 431068 960618
589388 829806 692481 154511 282620
2 1 711629163 3
2 1 781784306 3
2 1 686636041 3
2 3 794790206 2
2 1 844212542 2

output:

844212542
686636041

result:

ok 2 number(s): "844212542 686636041"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3952kb

input:

3 8
344877 101098 328614 735002 476606 635558 573861 261083
964379 333960 25186 276560 258996 683650 765559 582374
2 3 838262394 1
2 2 863940316 3
2 2 476918371 3
3 3 320092619 1 400754003 2
3 3 150885055 2 90507792 1
2 3 190275693 2
2 2 600234969 3
2 2 679446528 3

output:

400754003
29224357199

result:

ok 2 number(s): "400754003 29224357199"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

50 52
895514 29433 851800 887860 340384 95967 506578 666268 850660 602220 717255 242039 34055 752012 248567 170469 505996 823344 143369 390858 112988 892365 15368 617804 351619 557340 788960 990487 283825 272924 24678 130649 341049 980236 558990 254726 682005 963825 953074 603477 706464 340694 23541...

output:

632126151
479346918
492618840
3695787776
22624579200
174047740
416387993526
21429733469
15831777447
203893499
522142321620
977566721
279122223
30345963113
804573598
73397618725
6389037892
224856032596
416404080694
75356833904
69909552850
4504114918
13173874327
1104455938
275720760247
136977429637
22...

result:

ok 49 numbers

Test #8:

score: 0
Accepted
time: 1ms
memory: 3736kb

input:

50 186
909405 536090 349598 989013 812836 176449 79855 101754 179492 328610 751840 298905 429840 327083 222463 770826 222448 679356 524717 759894 186015 464746 390432 205629 893518 619709 777762 985329 612480 308146 507216 337177 463052 10105 150939 411855 75743 831031 391242 914978 198839 259846 36...

output:

279207921
30546650
3955157971
366881738
678883775
822326137
828131153
510756214
2799968412
2039093375
2727811374
2032421076
1966318841
894245748
2686792493
218322703
721713806
962052764
2586140415
201519887
722596289
49603757
329009601
562632121
73396118
399363911
1252345566
631600417
106456928
5055...

result:

ok 49 numbers

Test #9:

score: 0
Accepted
time: 0ms
memory: 5044kb

input:

50 746
109522 187240 733057 796323 66411 270785 937748 93610 470338 557856 166396 453860 431444 832088 13928 85925 15012 650718 328138 113957 812853 420621 146202 494017 985809 97315 96915 329400 118469 310530 501365 375790 461794 395440 784193 383084 825278 651991 584960 198686 644465 936326 856317...

output:

108689636
452441994
85834082
194842954
1581446
78212329
192476904
317795566
17889600
204753389
160234611
32867254
60240077
5211225
59666696
182239665
3783349
260084869
211347631
275823469
278103417
62390636
110457213
390191494
14670321
1101923
516180268
190362002
66561551
565544855
21826762
21720545...

result:

ok 49 numbers

Test #10:

score: 0
Accepted
time: 0ms
memory: 3916kb

input:

100 241
564812 561763 140723 436240 394309 44156 384984 144017 947539 422591 408747 362914 763371 162274 318323 676445 200578 532099 333815 768706 880020 140834 689221 544561 536480 764898 626990 221618 173930 13451 775752 248365 66936 533899 658027 131826 28438 795120 203253 433075 523346 599087 67...

output:

267913444
25339157310
8314344093
5464367180
1286326436
90461126
8907606133
16347606802
14711829080
8971431750
170752878
397694350
1037375748
18879356054
1501065529
2069064987
9584178341
17014391217
903970115
490753396
1632578522
10191345537
26994814823
2195645069
11593917652
17481016054
759764904
72...

result:

ok 99 numbers

Test #11:

score: 0
Accepted
time: 3ms
memory: 5096kb

input:

100 909
354490 607942 638780 621647 693678 345069 712251 189946 997948 842605 432303 208309 279462 858887 48769 974330 209759 652626 989265 72153 199248 326709 19953 978295 817366 854640 719591 770122 370818 808084 794671 257438 367000 694918 70071 168530 368273 624129 870946 439004 183705 785489 77...

output:

333297663
399355935
1059814556
1107743829
1427474071
696020875
353795528
459479343
659808640
1241037904
609650958
1306280384
377707905
26924777
786395257
123000005
1573062540
17829641
1567227849
189812239
370915753
928681025
89799511
815276047
135696305
515669937
942621003
445110058
86765197
1037062...

result:

ok 99 numbers

Test #12:

score: 0
Accepted
time: 3ms
memory: 5068kb

input:

1000 1789
943374 138795 977938 443021 385160 611446 873697 123265 14099 169470 105296 236046 377530 677105 433109 673693 542845 669265 772059 343016 454867 119346 90752 210176 359971 736639 253271 241927 403402 177845 24872 969078 397336 60325 932971 633624 626450 101687 358225 707661 256242 599586 ...

output:

695358284
57840977
47729563480
435035512
53612876532
26933106204
4709406363
97679790525
119919863949
78014553223
324259812
40737969101
825514049
152856002235
25891521677
92733560736
98950794057
182569608
369133896
55806982817
16885319597
88498741741
90610242716
52312675258
77437996874
11273252242
56...

result:

ok 999 numbers

Test #13:

score: 0
Accepted
time: 2ms
memory: 4772kb

input:

1000 1328
942464 700134 838046 230830 933766 241402 754798 823043 908485 771434 356964 779662 242435 658845 57070 349037 920119 952268 194414 510421 654479 753093 51195 678925 521131 537897 685665 725809 233695 739566 778076 336559 62389 81629 777441 708621 65449 395413 249430 591777 980459 77062 91...

output:

234864701
70427560643
33979112868
42154802
71102236248
360025339
8808877949
77704918952
202854481721
482146430
362270842220
187668535546
142540492218
202398929923
87515104508
103824540069
292703838878
70226700124
112913296906
204185466003
294581984792
344742221973
131973239350
55299336706
2803617572...

result:

ok 999 numbers

Test #14:

score: 0
Accepted
time: 40ms
memory: 15708kb

input:

1000 7893
234290 650221 485034 842643 583731 316391 855877 823188 996737 358070 913797 57603 43458 220809 843466 16281 586350 16643 661960 482050 214036 744249 692933 179360 771862 316856 434846 586374 290472 17854 418050 919421 61269 515068 557493 392514 238650 237722 168143 347078 924169 447795 19...

output:

811896320
1293855635
3137682407
683460714
124384666
3296401445
1891230314
617384608
818485965
926302922
908780409
371762097
530183257
5228061326
2528845153
2848035487
6292785548
3903673375
4384276771
824141642
2803177585
1373654628
2979388693
3991276711
1077652949
1076377042
2477897384
1012232752
30...

result:

ok 999 numbers

Test #15:

score: 0
Accepted
time: 39ms
memory: 14888kb

input:

10000 17223
411638 198168 78675 791920 399414 264260 756544 346010 72555 798265 399527 770715 218981 209633 792241 825286 312326 307287 803037 449058 805254 687533 938875 188202 566450 824807 986611 451083 581033 152703 385916 972649 621726 888799 212068 256602 249113 701737 251023 528041 668534 932...

output:

264478456
19629721444
58747142191
104890162435
81066903934
91271124384
22059849400
70219594888
158782955
67401328996
69908156642
88420661476
38894396830
71239910353
187511078
47005947919
48165339358
116258852571
27391548301
44644425059
32244633281
77343528772
110200074127
714011432
47544674155
42533...

result:

ok 9999 numbers

Test #16:

score: 0
Accepted
time: 70ms
memory: 23128kb

input:

10000 25193
994140 551560 777647 912578 474695 874446 518615 417794 420734 440280 350540 541909 459397 623405 484132 530213 893346 876986 371447 608193 954849 983503 977635 78490 913680 862880 157577 427719 908035 466245 876429 74305 69905 39098 798745 946215 57237 807776 931482 669564 337518 699578...

output:

845652800
329776210
619974790
29929115140
30865901800
23200678780
19487956608
20645175064
28571777786
32256070176
25974785637
39313190
16417867617
27530962994
39937693673
28768213109
31601702992
2731250211
18352720960
1655075805
35020768680
30915562998
36375405013
18515092663
17652203888
23185095801...

result:

ok 9999 numbers

Test #17:

score: 0
Accepted
time: 120ms
memory: 36420kb

input:

10000 35595
493555 197324 654547 122496 889265 384537 919812 673444 123975 149073 118275 853523 987923 20299 51365 84516 23229 626560 339071 867988 355757 37199 555437 401153 593680 983098 125135 319858 898774 910056 544710 960716 900023 211809 578683 494558 432041 145877 299929 162775 168492 515157...

output:

591468959
4263529491
25741990105
27747745929
943922301
553146669
20626771411
14990070866
15262817600
211312938
11187306628
1068742817
11523231170
7101110107
446301007
19777942603
2195348317
11676420850
27575950618
32793610274
23087439456
22784650364
15234639781
22317398412
22614349884
595571011
2497...

result:

ok 9999 numbers

Test #18:

score: 0
Accepted
time: 339ms
memory: 82152kb

input:

80000 200000
730 924 743 431 870 392 335 696 107 318 861 77 801 8 979 400 449 120 116 431 99 735 857 724 281 760 31 692 98 946 879 689 544 225 573 736 898 621 546 636 435 721 690 713 145 397 223 497 175 813 260 75 419 33 882 799 913 3 718 435 446 979 649 337 37 294 375 734 302 427 73 77 226 437 803 ...

output:

791188403
2399823861
2386202556
2909894787
287633485
2368174473
2906702082
786507242
1477545394
1703521029
509906919
1829434250
909741049
1079335592
1786633246
661888662
1414969089
808847450
1669656387
552797298
2136464329
805638677
2102591251
2275594058
2967158824
1829256802
1985829244
2351845524
9...

result:

ok 79999 numbers

Test #19:

score: 0
Accepted
time: 316ms
memory: 81588kb

input:

80000 200000
168 446 375 344 206 936 930 717 149 51 174 373 757 379 674 924 159 742 683 420 417 383 329 409 814 678 745 205 948 870 961 301 4 910 326 857 805 153 313 816 625 502 14 258 782 744 804 556 222 878 672 120 647 196 257 826 596 513 605 244 731 847 443 906 533 839 679 47 610 930 874 175 202 ...

output:

4694327740
3673506542
7348627430
8776334468
1123408211
3673215254
5409204785
10205855980
713749847
6939228992
409298683
3979247684
6122113086
4491261716
1735087796
4081961971
3572466704
9593662214
3470631758
6430431831
8368016925
5307782578
7858207599
4999883319
408435432
1225804485
10205468550
9081...

result:

ok 79999 numbers

Test #20:

score: 0
Accepted
time: 288ms
memory: 81484kb

input:

80000 200000
827 502 812 663 509 269 549 625 846 160 418 299 305 32 272 967 452 312 449 579 85 177 976 250 224 14 248 857 874 137 126 362 714 429 290 876 498 121 667 944 410 563 552 86 742 379 543 262 467 44 145 584 166 526 492 13 485 927 8 675 819 85 243 588 848 645 469 143 319 152 172 70 615 89 28...

output:

60850535012
47038953531
40533521143
73660958655
59049469642
46438218142
10909182359
34628504787
7906895415
29124518263
80967115602
54545535185
8106889025
20117032803
48340675407
46638217567
16914226370
52743836929
56146941814
29624826597
20817458246
62051337894
83469515648
93176932728
69057417865
51...

result:

ok 79999 numbers

Test #21:

score: 0
Accepted
time: 274ms
memory: 81768kb

input:

80000 200000
964 542 741 252 994 895 391 682 523 240 27 730 759 665 10 815 588 746 275 457 843 18 586 115 463 417 899 206 345 599 43 45 62 658 320 359 823 933 396 769 655 635 110 201 881 680 600 612 616 448 770 880 965 574 830 715 701 751 890 770 928 372 129 819 203 684 738 948 207 887 759 121 112 9...

output:

987807386074
71459872606
656235612667
536637034958
755215966130
941870869549
183451797333
110992635531
576569326315
537537774378
163034482809
704372909442
665743960142
720085731568
283230693088
472885695222
726591716415
290836841268
508815052531
834982735226
749010896290
180249439336
156228831377
96...

result:

ok 79999 numbers

Test #22:

score: 0
Accepted
time: 285ms
memory: 98212kb

input:

200000 200000
905 114 726 732 939 439 384 275 557 754 529 672 644 473 616 578 109 698 405 155 934 565 839 994 749 839 31 698 791 32 307 217 147 750 52 42 29 815 600 627 171 12 352 480 963 168 107 46 555 485 538 57 768 895 66 566 912 823 837 770 312 385 641 377 486 70 375 711 407 443 197 987 235 112 ...

output:

12323826721502
15004061760538
7196363704579
13334969319441
9697072553906
12504581559799
12115595155075
7749166079400
1514251668529
13462188588550
6294437940602
8167379127912
15833116015544
1346547850260
12648151642609
11580264389168
10633719276683
6854925852465
11301580083105
16760061895665
19196895...

result:

ok 199999 numbers

Test #23:

score: 0
Accepted
time: 294ms
memory: 73916kb

input:

50000 200000
3 103 110 831 753 657 468 126 591 334 998 113 405 555 606 850 441 90 843 603 235 786 602 622 97 492 112 638 148 768 425 788 937 694 412 683 130 166 309 923 98 488 546 82 845 917 847 126 637 12 834 428 598 813 135 557 147 634 909 171 462 233 86 129 708 412 995 760 935 920 814 363 866 145...

output:

1805907340
1812164168
1804427033
1485001224
1805614002
1805029037
1808101220
1805233803
1816739773
1806819862
501604450
1804686476
953035408
1807347493
1810659193
1806421481
1651920929
999177749
738156637
1601250140
1806300125
1066454462
791182972
1520664272
1806190433
1101742448
1809375614
18097207...

result:

ok 49999 numbers

Test #24:

score: 0
Accepted
time: 302ms
memory: 74036kb

input:

50000 200000
580 253 840 264 944 597 512 515 995 478 232 607 15 290 405 16 4 597 376 290 990 837 341 80 490 73 887 544 293 22 131 637 925 819 472 348 421 607 701 807 718 157 747 333 737 303 671 864 573 136 626 789 567 105 889 800 557 333 28 853 754 84 955 64 254 708 516 734 667 779 871 26 89 535 923...

output:

1813294228
1807782677
1805562333
1812032331
1808333484
1808542602
1807346448
952993159
1809380024
1805041815
1810540006
1805592985
1812061895
1809986875
1811400180
1813897967
1817272081
666128119
1805052998
1810782829
1209224300
1809262539
1806391843
1477712148
1808854241
1807875974
1804760365
18137...

result:

ok 49999 numbers

Test #25:

score: 0
Accepted
time: 308ms
memory: 76708kb

input:

50000 200000
803 998 894 965 902 528 26 688 640 693 50 270 255 106 251 87 970 937 833 870 903 984 91 19 909 929 458 98 27 192 910 650 608 312 225 239 592 6 769 9 805 236 954 843 524 896 242 188 324 378 940 49 715 873 6 185 384 471 370 120 90 449 416 677 39 864 243 707 966 202 144 676 110 697 242 161...

output:

302302078
1803536721
1906892926
1813569955
1805076543
1907935580
1809536152
1813284031
1808624867
1808323229
1837642380
1807267109
1815489378
1808761209
1805343982
1805943523
1811579097
1812470590
1806259258
1808754987
1855108870
902805876
1820755759
1811449747
1908615114
1810190806
1811244344
18158...

result:

ok 49999 numbers

Test #26:

score: 0
Accepted
time: 306ms
memory: 73528kb

input:

50000 200000
122 720 303 865 121 95 500 616 228 681 895 110 377 754 860 409 840 797 896 182 726 967 648 533 571 353 839 592 36 441 964 840 481 33 561 632 992 279 429 624 448 636 539 803 599 437 785 145 781 917 386 798 815 953 821 929 533 618 19 894 891 383 284 869 692 936 699 400 954 252 238 65 136 ...

output:

1873809050
1846249118
1855961516
1918602549
1873688154
1904210733
1865530510
1848689781
1858395623
1883502591
1947096201
1889746574
1858988744
1854363675
1882487977
1980580405
1876451478
1853884578
1911082716
1967502605
1853197800
1850663629
1898860167
1869648365
1850765377
1873225346
1911916019
185...

result:

ok 49999 numbers

Test #27:

score: 0
Accepted
time: 286ms
memory: 95980kb

input:

150002 200000
655709 225157 108907 727068 608962 580866 581370 668996 114913 688147 712347 444838 525048 529151 616248 323272 928096 299982 957892 92901 823481 871047 790404 887676 967315 750251 684253 956440 711957 696237 283825 582336 760037 292099 547034 533895 844949 839791 278671 509891 270292 ...

output:

1
1
1
1
459033299465
654777758202
1
1
739030725968
635286862202
641842274271
604169942075
478371848868
1
702372356769
650955972455
746315850667
494032782311
1
698596460050
1
1
736593933613
1
1
1
1
447949147110
625280092772
613528339692
586660179287
645941160880
492414541306
575368360255
1
6564698659...

result:

ok 150001 numbers

Test #28:

score: 0
Accepted
time: 286ms
memory: 96228kb

input:

150002 200000
806439 478781 393219 500219 775919 898532 871789 369638 548234 675736 647751 44321 905903 727068 855183 680552 467895 679352 602701 561367 789811 415371 542062 573330 352351 456317 426852 370155 423029 872663 435950 741370 376210 347297 344516 795643 507317 697863 705499 505161 462842 ...

output:

422749849215
403964091813
547229851490
566629066671
446699923314
1
580423179170
574366395533
1
380865787222
1
477194154611
468107519488
525568507960
341815002052
522453729540
530226656843
489043429921
1
378312478372
1
1
438092340423
564644551794
525844887365
387830782775
1
513603413795
1
54821467986...

result:

ok 150001 numbers

Test #29:

score: 0
Accepted
time: 285ms
memory: 96236kb

input:

150002 200000
976805 668011 953792 311931 611672 571212 589943 348719 877189 841910 667565 887005 929805 424841 711141 839560 273432 683330 642409 937090 834319 347285 950970 191607 407231 580660 925505 870786 776763 661028 119489 587183 283879 730187 827094 399872 751248 705475 959502 841024 864765...

output:

6
713943713176
738547371547
688483154921
584199523593
10
740932195324
4
512546216040
483589354194
715101736645
439495076716
515417014713
7
10
489946053220
629126573900
722461630616
5
639474345122
6
9
2
580028786705
679501816536
634259037810
6
482012689959
644692009353
1
675717963060
10
505070927484
...

result:

ok 150001 numbers

Test #30:

score: 0
Accepted
time: 277ms
memory: 96280kb

input:

150002 200000
154864 57461 642253 712148 976532 506197 88805 787571 644663 390141 978415 816474 928905 414574 622201 573841 946904 550279 716840 745763 869082 297974 922453 620439 367705 306554 369433 365444 459852 742350 407743 905015 790471 418940 383657 34763 510996 338619 881027 747086 397195 93...

output:

382304804927
8
9
2
5
512317646154
480108992949
486671968255
6
457377138326
447062491519
415086327063
468685016831
323786018769
406572587103
467463635317
2
447346597837
8
310001896814
6
1
493023257021
481910878898
2
7
323672904272
352895603188
520145251904
456391243197
553841321877
547440498043
39345...

result:

ok 150001 numbers

Test #31:

score: 0
Accepted
time: 283ms
memory: 96332kb

input:

150002 200000
721911 261509 922302 960086 802810 655938 98744 510720 624425 997158 521423 963559 821018 987335 617052 930637 943151 185120 627685 545644 426963 544058 703812 101987 861301 896317 990230 858857 814789 933746 572573 302846 393882 673967 721556 258232 513728 721978 959780 790858 506397 ...

output:

99
533682655216
709794114091
479731237823
623970481408
725318091176
738741683852
633038834061
539461307018
456233574013
749278466943
714730807674
628505685033
552717905363
497453525085
583474397399
522067396438
669441803570
722408141818
687791332287
26
454874514393
10
30
52
663627267134
665287416220...

result:

ok 150001 numbers

Test #32:

score: 0
Accepted
time: 279ms
memory: 96476kb

input:

150002 200000
668427 138810 802833 414033 566783 477047 965823 551386 924569 398356 519143 808705 356562 524462 560387 862765 710063 678408 798802 512054 178396 175753 49719 656697 570798 762603 501374 698544 961908 309808 19256 482518 420294 364117 975330 881288 480876 629402 209788 528108 422379 8...

output:

51
488224005299
442054622073
487678122492
282867395757
3
439507904787
532385233960
20
306243066958
525962389846
501001576577
317392442221
26
344978177519
82
562570328857
53
563504978115
428864674581
528010072512
424703098520
547010718083
441574622322
17
486825391644
470455853378
532449944023
10
5502...

result:

ok 150001 numbers

Extra Test:

score: 0
Extra Test Passed