Submission #56749

# Submission time Handle Problem Language Result Execution time Memory
56749 2018-07-12T11:36:59 Z Bodo171 Horses (IOI15_horses) C++14
100 / 100
1052 ms 255080 KB
#include "horses.h"
#include <iostream>
#include <set>
#include <climits>
using namespace std;
const int nmax=500005;
set<int> s;
set<int>::iterator it;
const long long mod=1000*1000*1000+7;
long long pr[4*nmax];
int arb[4*nmax];
int bun[nmax],v[nmax];
int mx,x,y,value,poz,st,dr,n,lg,ok,lst,M;
long long ans;
void U(int nod,int l,int r)
{
    if(l==r)
    {
        pr[nod]=value;
        return;
    }
    int m=(l+r)/2;
    if(poz<=m) U(2*nod,l,m);
    else U(2*nod+1,m+1,r);
    pr[nod]=(1LL*pr[2*nod]*pr[2*nod+1])%mod;
}
void Q(int nod,int l,int r)
{
    if(st<=l&&r<=dr)
    {
        ans=(1LL*ans*pr[nod])%mod;
        return;
    }
    int m=(l+r)/2;
    if(st<=m) Q(2*nod,l,m);
    if(m<dr) Q(2*nod+1,m+1,r);
}
void update(int nod,int l,int r)
{
    if(l==r)
    {
        arb[nod]=value;
        return;
    }
    int m=(l+r)/2;
    if(poz<=m) update(2*nod,l,m);
    else update(2*nod+1,m+1,r);
    arb[nod]=max(arb[2*nod],arb[2*nod+1]);
}
void query(int nod,int l,int r)
{
    if(st<=l&&r<=dr)
    {
        M=max(M,arb[nod]);
        return;
    }
    int m=(l+r)/2;
    if(st<=m) query(2*nod,l,m);
    if(m<dr) query(2*nod+1,m+1,r);
}
int qry(int S,int D)
{
    st=S;dr=D;M=0;
    query(1,1,n);
    return M;
}
int get_mx()
{
    long long opt=0;
    it=s.lower_bound(n+1);
    lg=32;mx=0;ok=1;poz=n;lst=n+1;
    for(int i=1;i<=lg&&it!=s.begin()&&ok;i++)
    {
        it--;
        x=v[(*it)-1];y=qry((*it),lst-1);
        if(y>mx) mx=y,poz=(*it),opt=y;
        if(mx!=0&&x>INT_MAX/mx) ok=0;
        else mx*=x;
        lst=(*it);
    }
    st=1;dr=poz;ans=1;
    Q(1,1,n);
    ans=(1LL*ans*opt)%mod;
    return ans;
}
int init(int N, int X[], int Y[]) {
    n=N;
    for(int i=0;i<N;i++)
    {
        poz=i+1;value=X[i];v[i]=X[i];
        U(1,1,n);
    }
    for(int i=0;i<N;i++)
    {
        poz=i+1;value=Y[i];
        update(1,1,n);
    }
    s.insert(n+1);lst=N;
    for(int i=N-1;i>=0;i--)
       if(X[i]!=1)
    {
        s.insert(i+1);
        bun[i+1]=qry(i+1,lst);
        lst=i;
    }
    if(s.find(1)==s.end())
    {
        bun[1]=qry(1,n);
        s.insert(1);
    }
	return get_mx();
}

int updateX(int pos, int val) {
    poz=pos+1;value=val;
    if(v[poz-1]!=1)
    {
        s.erase(poz);
    }
    U(1,1,n);
    v[poz-1]=val;
    if(val!=1)
    {
        s.insert(poz);
    }
    bun[poz]=qry(poz,(*s.upper_bound(poz))-1);
    if(s.find(1)==s.end())
    {
        bun[1]=qry(1,n);
        s.insert(1);
    }
	return get_mx();
}

int updateY(int pos, int val) {

    poz=pos+1;value=val;
    update(1,1,n);
    it=s.upper_bound(poz);
    if(it!=s.begin())
    {
        it--;
        bun[(*it)]=qry((*it),(*s.upper_bound((*it)))-1);
    }
    bun[1]=qry(1,n);
	return get_mx();
}

Compilation message

horses.cpp: In function 'int get_mx()':
horses.cpp:84:12: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return ans;
            ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 396 KB Output is correct
3 Correct 3 ms 416 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 672 KB Output is correct
6 Correct 2 ms 672 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
8 Correct 2 ms 716 KB Output is correct
9 Correct 4 ms 716 KB Output is correct
10 Correct 3 ms 716 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 3 ms 716 KB Output is correct
13 Correct 3 ms 716 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
15 Correct 2 ms 716 KB Output is correct
16 Correct 3 ms 716 KB Output is correct
17 Correct 3 ms 716 KB Output is correct
18 Correct 2 ms 716 KB Output is correct
19 Correct 2 ms 716 KB Output is correct
20 Correct 2 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 3 ms 748 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 3 ms 748 KB Output is correct
6 Correct 2 ms 748 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 3 ms 748 KB Output is correct
9 Correct 2 ms 748 KB Output is correct
10 Correct 4 ms 748 KB Output is correct
11 Correct 3 ms 748 KB Output is correct
12 Correct 2 ms 748 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 3 ms 748 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
16 Correct 3 ms 748 KB Output is correct
17 Correct 3 ms 748 KB Output is correct
18 Correct 3 ms 748 KB Output is correct
19 Correct 2 ms 748 KB Output is correct
20 Correct 3 ms 748 KB Output is correct
21 Correct 2 ms 748 KB Output is correct
22 Correct 3 ms 748 KB Output is correct
23 Correct 4 ms 764 KB Output is correct
24 Correct 4 ms 764 KB Output is correct
25 Correct 5 ms 852 KB Output is correct
26 Correct 4 ms 1060 KB Output is correct
27 Correct 8 ms 1060 KB Output is correct
28 Correct 4 ms 1060 KB Output is correct
29 Correct 4 ms 1060 KB Output is correct
30 Correct 5 ms 1060 KB Output is correct
31 Correct 6 ms 1060 KB Output is correct
32 Correct 5 ms 1060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 798 ms 45612 KB Output is correct
2 Correct 962 ms 45612 KB Output is correct
3 Correct 963 ms 45652 KB Output is correct
4 Correct 998 ms 45652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 45652 KB Output is correct
2 Correct 2 ms 45652 KB Output is correct
3 Correct 3 ms 45652 KB Output is correct
4 Correct 3 ms 45652 KB Output is correct
5 Correct 2 ms 45652 KB Output is correct
6 Correct 2 ms 45652 KB Output is correct
7 Correct 3 ms 45652 KB Output is correct
8 Correct 2 ms 45652 KB Output is correct
9 Correct 2 ms 45652 KB Output is correct
10 Correct 2 ms 45652 KB Output is correct
11 Correct 2 ms 45652 KB Output is correct
12 Correct 3 ms 45652 KB Output is correct
13 Correct 3 ms 45652 KB Output is correct
14 Correct 2 ms 45652 KB Output is correct
15 Correct 2 ms 45652 KB Output is correct
16 Correct 3 ms 45652 KB Output is correct
17 Correct 2 ms 45652 KB Output is correct
18 Correct 2 ms 45652 KB Output is correct
19 Correct 3 ms 45652 KB Output is correct
20 Correct 3 ms 45652 KB Output is correct
21 Correct 2 ms 45652 KB Output is correct
22 Correct 2 ms 45652 KB Output is correct
23 Correct 3 ms 45652 KB Output is correct
24 Correct 4 ms 45652 KB Output is correct
25 Correct 5 ms 45652 KB Output is correct
26 Correct 5 ms 45652 KB Output is correct
27 Correct 7 ms 45652 KB Output is correct
28 Correct 5 ms 45652 KB Output is correct
29 Correct 4 ms 45652 KB Output is correct
30 Correct 5 ms 45652 KB Output is correct
31 Correct 5 ms 45652 KB Output is correct
32 Correct 5 ms 45652 KB Output is correct
33 Correct 282 ms 45652 KB Output is correct
34 Correct 296 ms 45652 KB Output is correct
35 Correct 575 ms 63748 KB Output is correct
36 Correct 597 ms 74496 KB Output is correct
37 Correct 349 ms 74496 KB Output is correct
38 Correct 419 ms 74496 KB Output is correct
39 Correct 251 ms 74496 KB Output is correct
40 Correct 588 ms 87556 KB Output is correct
41 Correct 261 ms 87556 KB Output is correct
42 Correct 270 ms 87556 KB Output is correct
43 Correct 589 ms 97996 KB Output is correct
44 Correct 603 ms 104404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 104404 KB Output is correct
2 Correct 3 ms 104404 KB Output is correct
3 Correct 3 ms 104404 KB Output is correct
4 Correct 3 ms 104404 KB Output is correct
5 Correct 3 ms 104404 KB Output is correct
6 Correct 2 ms 104404 KB Output is correct
7 Correct 3 ms 104404 KB Output is correct
8 Correct 2 ms 104404 KB Output is correct
9 Correct 3 ms 104404 KB Output is correct
10 Correct 3 ms 104404 KB Output is correct
11 Correct 4 ms 104404 KB Output is correct
12 Correct 3 ms 104404 KB Output is correct
13 Correct 1 ms 104404 KB Output is correct
14 Correct 4 ms 104404 KB Output is correct
15 Correct 2 ms 104404 KB Output is correct
16 Correct 3 ms 104404 KB Output is correct
17 Correct 0 ms 104404 KB Output is correct
18 Correct 3 ms 104404 KB Output is correct
19 Correct 1 ms 104404 KB Output is correct
20 Correct 2 ms 104404 KB Output is correct
21 Correct 3 ms 104404 KB Output is correct
22 Correct 3 ms 104404 KB Output is correct
23 Correct 4 ms 104404 KB Output is correct
24 Correct 5 ms 104404 KB Output is correct
25 Correct 4 ms 104404 KB Output is correct
26 Correct 5 ms 104404 KB Output is correct
27 Correct 6 ms 104404 KB Output is correct
28 Correct 6 ms 104404 KB Output is correct
29 Correct 6 ms 104404 KB Output is correct
30 Correct 5 ms 104404 KB Output is correct
31 Correct 4 ms 104404 KB Output is correct
32 Correct 7 ms 104404 KB Output is correct
33 Correct 921 ms 109348 KB Output is correct
34 Correct 1052 ms 122036 KB Output is correct
35 Correct 1004 ms 125896 KB Output is correct
36 Correct 955 ms 133636 KB Output is correct
37 Correct 281 ms 133636 KB Output is correct
38 Correct 291 ms 133636 KB Output is correct
39 Correct 619 ms 151320 KB Output is correct
40 Correct 603 ms 162160 KB Output is correct
41 Correct 296 ms 162160 KB Output is correct
42 Correct 428 ms 162160 KB Output is correct
43 Correct 254 ms 162160 KB Output is correct
44 Correct 611 ms 175204 KB Output is correct
45 Correct 295 ms 175204 KB Output is correct
46 Correct 266 ms 175204 KB Output is correct
47 Correct 610 ms 185804 KB Output is correct
48 Correct 592 ms 192040 KB Output is correct
49 Correct 554 ms 192040 KB Output is correct
50 Correct 498 ms 192040 KB Output is correct
51 Correct 861 ms 215060 KB Output is correct
52 Correct 719 ms 226404 KB Output is correct
53 Correct 825 ms 226404 KB Output is correct
54 Correct 604 ms 226404 KB Output is correct
55 Correct 371 ms 226404 KB Output is correct
56 Correct 782 ms 243540 KB Output is correct
57 Correct 514 ms 243540 KB Output is correct
58 Correct 580 ms 243540 KB Output is correct
59 Correct 597 ms 255080 KB Output is correct