Submission #86812

# Submission time Handle Problem Language Result Execution time Memory
86812 2018-11-27T15:34:58 Z JustasZ Horses (IOI15_horses) C++14
17 / 100
811 ms 49000 KB
#include "horses.h"
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) "["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn=5e5+100;
const int mod=1e9+7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll pwr(ll a, ll pw)
{
    ll ret=1;
    while(pw>0)
    {
        if(pw&1)ret=(ret*a)%mod;
        a=(a*a)%mod;
        pw>>=1;
    }
    return ret;
}
ll modinv(ll a)
{
    return pwr(a, mod-2);
}
int N;
ll X[maxn], Y[maxn], seg[maxn*4];
set<int>pos;
void build(int id=1, int l=0, int r=N-1)
{
    if(l == r)
    {
        seg[id]=Y[l];
        return;
    }
    int mid=(l+r)/2;
    build(id*2, l, mid);
    build(id*2+1, mid+1, r);
    seg[id]=max(seg[id*2], seg[id*2+1]);
}
void modify(int p, ll d, int id=1, int l=0, int r=N-1)
{
    if(l == r)
    {
        seg[id]+=d;
        return;
    }
    int mid=(l+r)/2;
    if(p <= mid)modify(p, d, id*2, l, mid);
    else modify(p, d, id*2+1, mid+1, r);
    seg[id]=max(seg[id*2], seg[id*2+1]);
}
ll query(int x, int y, int id=1, int l=0, int r=N-1)
{
    if(l > y || r < x)return 0;
    if(l >= x && r <= y)return seg[id];
    int mid=(l+r)/2;
    return max(query(x, y, id*2, l, mid), query(x, y, id*2+1, mid+1, r));
}

ll F[maxn];
void upd(int p, ll val)
{
    for(; p<=N; p+=p&-p)
        F[p]=(F[p]*val)%mod;
}
ll get(int p)
{
    ll ret=1;
    for(; p>0; p-=p&-p)
        ret=(ret*F[p])%mod;
    return ret;
}
int getans()
{
    ll ret=query(0, N-1);
    if(sz(pos))
    {
        auto it=prev(pos.end());
        for(int c=0; c<=30; c++)
        {
            ret=max(ret, (get(*it+1)*query(*it, N-1))%mod);
            if(it == pos.begin())break;
            --it;
        }
    }
    return (int)ret;
}
int init(int n, int x[], int y[])
{
    N=n;
    for(int i=0; i<N; i++)
        X[i]=x[i], Y[i]=y[i];
    for(int i=N-1; i>=0; i--)
        if(X[i] >= 2)
            pos.insert(i);
    build();
    for(int i=1; i<=N; i++)
        F[i]=1;
    for(int i=0; i<N; i++)
        upd(i+1, X[i]);
    return getans();
}
int updateX(int p, int val)
{
    upd(p+1, val*modinv(X[p])%mod);
    if(X[p] == 1 && val >= 2)pos.insert(p);
    if(X[p] >= 2 && val == 1)pos.erase(p);
    X[p]=val;
    return getans();
}
int updateY(int p, int val)
{
    ll d=val-Y[p];
    modify(p, d);
    Y[p]=val;
    return getans();
}
/*int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    int n, A[maxn], B[maxn];
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>A[i];
    for(int i=0; i<n; i++)
        cin>>B[i];
    cout<<init(n, A, B)<<"\n";
    return 0;
}*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 532 KB Output is correct
5 Correct 2 ms 552 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 700 KB Output is correct
11 Correct 2 ms 700 KB Output is correct
12 Correct 2 ms 700 KB Output is correct
13 Correct 2 ms 700 KB Output is correct
14 Correct 2 ms 700 KB Output is correct
15 Correct 2 ms 700 KB Output is correct
16 Correct 2 ms 700 KB Output is correct
17 Correct 2 ms 700 KB Output is correct
18 Correct 2 ms 700 KB Output is correct
19 Correct 2 ms 700 KB Output is correct
20 Correct 2 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 700 KB Output is correct
2 Correct 2 ms 700 KB Output is correct
3 Correct 2 ms 700 KB Output is correct
4 Correct 2 ms 700 KB Output is correct
5 Correct 2 ms 700 KB Output is correct
6 Correct 2 ms 700 KB Output is correct
7 Correct 2 ms 700 KB Output is correct
8 Correct 2 ms 700 KB Output is correct
9 Correct 2 ms 700 KB Output is correct
10 Correct 2 ms 700 KB Output is correct
11 Correct 2 ms 700 KB Output is correct
12 Correct 2 ms 700 KB Output is correct
13 Correct 2 ms 700 KB Output is correct
14 Correct 2 ms 700 KB Output is correct
15 Correct 2 ms 700 KB Output is correct
16 Correct 2 ms 700 KB Output is correct
17 Correct 2 ms 744 KB Output is correct
18 Correct 2 ms 744 KB Output is correct
19 Correct 2 ms 744 KB Output is correct
20 Correct 2 ms 744 KB Output is correct
21 Incorrect 2 ms 744 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 811 ms 49000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 49000 KB Output is correct
2 Correct 2 ms 49000 KB Output is correct
3 Correct 2 ms 49000 KB Output is correct
4 Correct 2 ms 49000 KB Output is correct
5 Correct 2 ms 49000 KB Output is correct
6 Correct 2 ms 49000 KB Output is correct
7 Correct 2 ms 49000 KB Output is correct
8 Correct 2 ms 49000 KB Output is correct
9 Correct 2 ms 49000 KB Output is correct
10 Correct 2 ms 49000 KB Output is correct
11 Correct 2 ms 49000 KB Output is correct
12 Correct 2 ms 49000 KB Output is correct
13 Correct 2 ms 49000 KB Output is correct
14 Correct 3 ms 49000 KB Output is correct
15 Correct 2 ms 49000 KB Output is correct
16 Correct 2 ms 49000 KB Output is correct
17 Correct 2 ms 49000 KB Output is correct
18 Correct 2 ms 49000 KB Output is correct
19 Correct 2 ms 49000 KB Output is correct
20 Correct 2 ms 49000 KB Output is correct
21 Incorrect 2 ms 49000 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 49000 KB Output is correct
2 Correct 2 ms 49000 KB Output is correct
3 Correct 2 ms 49000 KB Output is correct
4 Correct 2 ms 49000 KB Output is correct
5 Correct 2 ms 49000 KB Output is correct
6 Correct 2 ms 49000 KB Output is correct
7 Correct 2 ms 49000 KB Output is correct
8 Correct 2 ms 49000 KB Output is correct
9 Correct 2 ms 49000 KB Output is correct
10 Correct 2 ms 49000 KB Output is correct
11 Correct 2 ms 49000 KB Output is correct
12 Correct 2 ms 49000 KB Output is correct
13 Correct 2 ms 49000 KB Output is correct
14 Correct 2 ms 49000 KB Output is correct
15 Correct 2 ms 49000 KB Output is correct
16 Correct 2 ms 49000 KB Output is correct
17 Correct 2 ms 49000 KB Output is correct
18 Correct 2 ms 49000 KB Output is correct
19 Correct 2 ms 49000 KB Output is correct
20 Correct 2 ms 49000 KB Output is correct
21 Incorrect 2 ms 49000 KB Output isn't correct
22 Halted 0 ms 0 KB -