Submission #620071

# Submission time Handle Problem Language Result Execution time Memory
620071 2022-08-02T21:18:38 Z Bench0310 Horses (IOI15_horses) C++17
100 / 100
673 ms 65524 KB
#include <bits/stdc++.h>
#include "horses.h"

using namespace std;
typedef long long ll;

const ll mod=1000000007;
const ll lim=1000000000;
ll mul(ll a,ll b){return (a*b)%mod;};

const int N=500005;
int n;
ll x[N];
ll y[N];
ll treex[4*N];
ll treey[4*N];
set<int> s;

void pull(int idx)
{
    treex[idx]=mul(treex[2*idx],treex[2*idx+1]);
    treey[idx]=max(treey[2*idx],treey[2*idx+1]);
}

void build(int idx,int l,int r)
{
    if(l==r)
    {
        treex[idx]=x[l];
        treey[idx]=y[l];
    }
    else
    {
        int m=(l+r)/2;
        build(2*idx,l,m);
        build(2*idx+1,m+1,r);
        pull(idx);
    }
}

void update(int idx,int l,int r,int pos,ll val,int t)
{
    if(l==r)
    {
        if(t==0) treex[idx]=val;
        else treey[idx]=val;
    }
    else
    {
        int m=(l+r)/2;
        if(pos<=m) update(2*idx,l,m,pos,val,t);
        else update(2*idx+1,m+1,r,pos,val,t);
        pull(idx);
    }
}

ll query(int idx,int l,int r,int ql,int qr,int t)
{
    if(ql>qr) return (1-t);
    if(l==ql&&r==qr) return (t==0?treex[idx]:treey[idx]);
    int m=(l+r)/2;
    ll one=query(2*idx,l,m,ql,min(qr,m),t);
    ll two=query(2*idx+1,m+1,r,max(ql,m+1),qr,t);
    if(t==0) return mul(one,two);
    else return max(one,two);
}

int solve()
{
    bool rm=0;
    if(s.find(0)==s.end())
    {
        rm=1;
        s.insert(0);
    }
    ll best=0;
    int nxt=n;
    for(auto it=s.rbegin();it!=s.rend();it++)
    {
        int p=(*it);
        best=x[p]*max(best,query(1,0,n-1,p,nxt-1,1));
        nxt=p;
        if(best>=lim) break;
    }
    if(rm) s.erase(0);
    return int(mul(best%mod,query(1,0,n-1,0,nxt-1,0)));
}

int init(int tn,int X[],int Y[])
{
    n=tn;
    for(int i=0;i<n;i++)
    {
        x[i]=X[i];
        y[i]=Y[i];
        if(x[i]>1) s.insert(i);
    }
    build(1,0,n-1);
    return solve();
}

int updateX(int pos,int val)
{
    if(x[pos]>1) s.erase(pos);
    x[pos]=val;
    if(x[pos]>1) s.insert(pos);
    update(1,0,n-1,pos,x[pos],0);
    return solve();
}

int updateY(int pos,int val)
{
    y[pos]=val;
    update(1,0,n-1,pos,y[pos],1);
    return solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 312 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 472 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 316 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 6 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 579 ms 56704 KB Output is correct
2 Correct 355 ms 65492 KB Output is correct
3 Correct 346 ms 56620 KB Output is correct
4 Correct 397 ms 60596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 308 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 312 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 312 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 2 ms 456 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 4 ms 340 KB Output is correct
33 Correct 46 ms 32576 KB Output is correct
34 Correct 49 ms 32572 KB Output is correct
35 Correct 179 ms 62924 KB Output is correct
36 Correct 173 ms 62896 KB Output is correct
37 Correct 97 ms 30720 KB Output is correct
38 Correct 119 ms 43468 KB Output is correct
39 Correct 35 ms 30544 KB Output is correct
40 Correct 166 ms 57928 KB Output is correct
41 Correct 62 ms 30520 KB Output is correct
42 Correct 84 ms 30632 KB Output is correct
43 Correct 161 ms 58284 KB Output is correct
44 Correct 149 ms 58252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 360 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 308 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 4 ms 324 KB Output is correct
28 Correct 3 ms 452 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 642 ms 56660 KB Output is correct
34 Correct 350 ms 65524 KB Output is correct
35 Correct 366 ms 56692 KB Output is correct
36 Correct 364 ms 60540 KB Output is correct
37 Correct 46 ms 32560 KB Output is correct
38 Correct 46 ms 32544 KB Output is correct
39 Correct 188 ms 62952 KB Output is correct
40 Correct 171 ms 62912 KB Output is correct
41 Correct 95 ms 30724 KB Output is correct
42 Correct 106 ms 43512 KB Output is correct
43 Correct 38 ms 30540 KB Output is correct
44 Correct 156 ms 57912 KB Output is correct
45 Correct 58 ms 30540 KB Output is correct
46 Correct 76 ms 30604 KB Output is correct
47 Correct 149 ms 58296 KB Output is correct
48 Correct 154 ms 58232 KB Output is correct
49 Correct 154 ms 35572 KB Output is correct
50 Correct 141 ms 35552 KB Output is correct
51 Correct 345 ms 64724 KB Output is correct
52 Correct 243 ms 64240 KB Output is correct
53 Correct 673 ms 33816 KB Output is correct
54 Correct 257 ms 47464 KB Output is correct
55 Correct 143 ms 31548 KB Output is correct
56 Correct 266 ms 59716 KB Output is correct
57 Correct 376 ms 32316 KB Output is correct
58 Correct 561 ms 32832 KB Output is correct
59 Correct 146 ms 58336 KB Output is correct