Submission #468393

# Submission time Handle Problem Language Result Execution time Memory
468393 2021-08-28T00:51:00 Z julian33 Horses (IOI15_horses) C++14
100 / 100
483 ms 86568 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
    cerr<<vars<<" = ";
    string delim="";
    (...,(cerr<<delim<<values,delim=", "));
    cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif

#define pb push_back
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);} 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mxN=5e5+5; //make sure this is right
const int mod=1e9+7;

#define double long double

ll fpow(ll b,ll e){
    ll res=1;
    while(e){
        if(e&1)
            res=(res*b)%mod;
        b=(b*b)%mod;
        e>>=1;
    }
    return res;
}

ll divmod(ll a,ll b){
    return (a*fpow(b,mod-2))%mod;
}

ll st[4*mxN],lazy[4*mxN],x[mxN],y[mxN],n,psa2[mxN];
double st2[4*mxN],lazy2[4*mxN],psa[mxN];

void mul(ll &a,ll b){a=(a*b)%mod;}

void build(int v,int l,int r){
    if(l==r){
        st2[v]=psa[l]+log10(y[l]);
        st[v]=(psa2[l]*y[l])%mod;
    } else{
        int m=(l+r)>>1;
        build(v<<1,l,m);
        build(v<<1|1,m+1,r);
        st2[v]=max(st2[v<<1],st2[v<<1|1]);
    }
}

void push(int v){
    mul(st[v<<1],lazy[v]);
    mul(st[v<<1|1],lazy[v]);
    mul(lazy[v<<1],lazy[v]);
    mul(lazy[v<<1|1],lazy[v]);
    lazy[v]=1;
    st2[v<<1]+=lazy2[v];
    st2[v<<1|1]+=lazy2[v];
    lazy2[v<<1]+=lazy2[v];
    lazy2[v<<1|1]+=lazy2[v];
    lazy2[v]=0;
}

void range_upd(int v,int l,int r,int lq,int rq,ll v1,double v2){
    if(lq>rq)
        return;
    if(l>=lq && r<=rq){
        st[v]=(st[v]*v1)%mod;
        st2[v]+=v2;
        lazy2[v]+=v2;
        lazy[v]=(lazy[v]*v1)%mod;
    } else{
        int m=(l+r)>>1;
        push(v);
        range_upd(v<<1,l,m,lq,min(rq,m),v1,v2);
        range_upd(v<<1|1,m+1,r,max(lq,m+1),rq,v1,v2);
        st2[v]=max(st2[v<<1],st2[v<<1|1]);
    }
}

void point_upd(int v,int l,int r,int ind,ll v1,double v2){
    if(l>ind || r<ind)
        return;
    if(l==r){
        mul(st[v],v1);
        st2[v]+=v2;
    } else{
        int m=(l+r)>>1;
        push(v);
        point_upd(v<<1,l,m,ind,v1,v2);
        point_upd(v<<1|1,m+1,r,ind,v1,v2);
        st2[v]=max(st2[v<<1],st2[v<<1|1]);
    }
}

int get(int v,int l,int r){
    deb(l,r,st[v]);
    if(l==r)
        return st[v];
    push(v);
    int m=(l+r)>>1;
    if(st2[v<<1]>st2[v<<1|1])
        return get(v<<1,l,m);
    return get(v<<1|1,m+1,r);
}

int init(int N, int X[], int Y[]){
    n=N;
    psa2[0]=1;
    for(int i=1;i<=n;i++){
        x[i]=X[i-1];
        y[i]=Y[i-1];
        psa[i]=psa[i-1]+log10(x[i]);
        psa2[i]=(psa2[i-1]*x[i])%mod;
    }
    fill(lazy+1,lazy+1+4*n,1);
    build(1,1,n);
    return get(1,1,n);
}

int updateX(int pos, int val){
    pos++;
    ll v=divmod(val,x[pos]);
    double v2=log10(val)-log10(x[pos]);
    x[pos]=val;
    range_upd(1,1,n,pos,n,v,v2);
    return get(1,1,n);
}

int updateY(int pos,int val){
    pos++;
    ll v=divmod(val,y[pos]);
    double v2=log10(val)-log10(y[pos]);
    y[pos]=val;
    point_upd(1,1,n,pos,v,v2);
    return get(1,1,n);
}

Compilation message

horses.cpp: In function 'int get(int, int, int)':
horses.cpp:114:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  114 |         return st[v];
      |                ~~~~^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:132:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  132 |     build(1,1,n);
      |               ^
horses.cpp:133:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  133 |     return get(1,1,n);
      |                    ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:141:19: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  141 |     range_upd(1,1,n,pos,n,v,v2);
      |                   ^
horses.cpp:141:25: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  141 |     range_upd(1,1,n,pos,n,v,v2);
      |                         ^
horses.cpp:142:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  142 |     return get(1,1,n);
      |                    ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:150:19: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  150 |     point_upd(1,1,n,pos,v,v2);
      |                   ^
horses.cpp:151:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  151 |     return get(1,1,n);
      |                    ^
horses.cpp: In instantiation of 'void logger(std::string, Args&& ...) [with Args = {int&, int&, long long int&}; std::string = std::__cxx11::basic_string<char>]':
horses.cpp:112:5:   required from here
horses.cpp:17:20: warning: unused parameter 'vars' [-Wunused-parameter]
   17 | void logger(string vars, Args&&... values) {}
      |             ~~~~~~~^~~~
horses.cpp:17:32: warning: unused parameter 'values#0' [-Wunused-parameter]
   17 | void logger(string vars, Args&&... values) {}
      |                          ~~~~~~^~~~~~~~~~
horses.cpp:17:32: warning: unused parameter 'values#1' [-Wunused-parameter]
horses.cpp:17:32: warning: unused parameter 'values#2' [-Wunused-parameter]
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 2 ms 460 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 2 ms 460 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 282 ms 63204 KB Output is correct
2 Correct 476 ms 81396 KB Output is correct
3 Correct 436 ms 81472 KB Output is correct
4 Correct 442 ms 81384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 360 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
24 Correct 3 ms 460 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 2 ms 460 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 2 ms 460 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 128 ms 80256 KB Output is correct
34 Correct 128 ms 80232 KB Output is correct
35 Correct 132 ms 62168 KB Output is correct
36 Correct 132 ms 62188 KB Output is correct
37 Correct 111 ms 80156 KB Output is correct
38 Correct 103 ms 62568 KB Output is correct
39 Correct 84 ms 62428 KB Output is correct
40 Correct 108 ms 62508 KB Output is correct
41 Correct 84 ms 63776 KB Output is correct
42 Correct 84 ms 62148 KB Output is correct
43 Correct 90 ms 62148 KB Output is correct
44 Correct 89 ms 62108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 0 ms 364 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 2 ms 460 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 2 ms 460 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 277 ms 63080 KB Output is correct
34 Correct 483 ms 81560 KB Output is correct
35 Correct 422 ms 81528 KB Output is correct
36 Correct 457 ms 81496 KB Output is correct
37 Correct 135 ms 80280 KB Output is correct
38 Correct 131 ms 80256 KB Output is correct
39 Correct 133 ms 62224 KB Output is correct
40 Correct 132 ms 62148 KB Output is correct
41 Correct 109 ms 80176 KB Output is correct
42 Correct 102 ms 62532 KB Output is correct
43 Correct 83 ms 62408 KB Output is correct
44 Correct 110 ms 62648 KB Output is correct
45 Correct 84 ms 63700 KB Output is correct
46 Correct 84 ms 62128 KB Output is correct
47 Correct 89 ms 62108 KB Output is correct
48 Correct 91 ms 62176 KB Output is correct
49 Correct 443 ms 86468 KB Output is correct
50 Correct 453 ms 86568 KB Output is correct
51 Correct 323 ms 74932 KB Output is correct
52 Correct 322 ms 74476 KB Output is correct
53 Correct 426 ms 84780 KB Output is correct
54 Correct 318 ms 70844 KB Output is correct
55 Correct 264 ms 65476 KB Output is correct
56 Correct 315 ms 73760 KB Output is correct
57 Correct 265 ms 67396 KB Output is correct
58 Correct 275 ms 66340 KB Output is correct
59 Correct 92 ms 68612 KB Output is correct