Submission #603820

# Submission time Handle Problem Language Result Execution time Memory
603820 2022-07-24T12:06:09 Z neki Horses (IOI15_horses) C++14
100 / 100
630 ms 68684 KB
#include <bits/stdc++.h>
#define ll long long
#define vc vector
 
using namespace std;
const ll mn=500100, mod=1000000007;
 
ll x[mn], y[mn], n;
ll tpro[2 * mn];
ll tmax[2 * mn];
set<ll> act;
ll my[mn];
void updpro(ll pos, ll val){
    for (tpro[pos += mn]=val; pos > 1; pos >>= 1) tpro[pos>>1]=(tpro[pos] * tpro[pos^1])%mod;
}
void updmax(ll pos, ll val){
    for (tmax[pos += mn]=val; pos > 1; pos >>= 1) tmax[pos>>1]=max(tmax[pos], tmax[pos^1]);
}
ll getpro(ll l, ll r){
    ll ret=1;
    for(l+=mn, r+=mn;l<r;l>>=1, r>>=1){
        if(l&1) ret*=tpro[l++], ret%=mod;
        if(r&1) ret*=tpro[--r], ret%=mod;
    }
    return ret;
}
ll getmax(ll l, ll r){
    ll ret=0;
    for(l+=mn, r+=mn;l<r;l>>=1, r>>=1){
        if(l&1) ret=max(ret, tmax[l++]);
        if(r&1) ret=max(ret, tmax[--r]);
    }
    return ret;
}
void getmy(ll pos){
    ll l=pos, r;
    auto pr=act.upper_bound(pos);
    if(pr==act.end()) r=n;
    else r=(*pr);
    my[pos]=getmax(l, r);
}
 
ll getyear(ll pos){ return (getpro(0, pos+1) * my[pos])%mod; }
 
ll getans(){
    vc<ll> preglej;
    auto poi = act.end();
    for(ll i=0;i<min((ll)100, (ll)act.size());++i){
        --poi;
        preglej.push_back(*poi);
    }
    reverse(preglej.begin(), preglej.end());
    
    ll best=0, cur=1;
    for(ll i=1;i<preglej.size();++i){
        cur*=x[preglej[i]];
        if(my[preglej[best]]<cur or my[preglej[best]]<cur * my[preglej[i]]) best=i, cur=1;
    }
    ll ret=getyear(preglej[best]);
    return ret;
}
 
int updateX(int pos, int val){
    if(x[pos]>1 or pos==0) act.erase(pos);
    x[pos]=val;updpro(pos, val);
    if(x[pos]>1 or pos==0) act.insert(pos);
    
    auto zau = act.upper_bound(pos); --zau;
    getmy(*zau);
    if(zau!=act.begin()){--zau; getmy(*zau);}
    
    return getans();
}
int updateY(int pos, int val){
    y[pos]=val;updmax(pos, val);
    auto poi=act.upper_bound(pos);--poi;
    getmy(*poi);
    
    return getans();
}
 
int init(int N, int X[], int Y[]){
    n=N;for(ll i=0;i<n;++i) x[i]=X[i], y[i]=Y[i];
    for(ll i=0;i<n;++i) updpro(i, X[i]), updmax(i, Y[i]);
    for(ll i=0;i<n;++i) if(x[i]>1 or i==0) act.insert(i);
    for(ll i=0;i<n;++i) if(x[i]>1 or i==0) getmy(i);
    return getans();
}

Compilation message

horses.cpp: In function 'long long int getans()':
horses.cpp:55:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(ll i=1;i<preglej.size();++i){
      |                ~^~~~~~~~~~~~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:72:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   72 |     return getans();
      |            ~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:79:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   79 |     return getans();
      |            ~~~~~~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:87:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   87 |     return getans();
      |            ~~~~~~^~
# 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 340 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 1 ms 340 KB Output is correct
8 Correct 1 ms 340 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 340 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 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
# 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 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 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 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 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 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 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 340 KB Output is correct
23 Correct 2 ms 516 KB Output is correct
24 Correct 2 ms 476 KB Output is correct
25 Correct 3 ms 596 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 456 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 377 ms 56096 KB Output is correct
2 Correct 566 ms 68568 KB Output is correct
3 Correct 506 ms 59928 KB Output is correct
4 Correct 577 ms 63684 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 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 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 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 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 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 340 KB Output is correct
19 Correct 0 ms 340 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 340 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 544 KB Output is correct
25 Correct 3 ms 484 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 1 ms 456 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 103 ms 35424 KB Output is correct
34 Correct 99 ms 35312 KB Output is correct
35 Correct 317 ms 66044 KB Output is correct
36 Correct 297 ms 66040 KB Output is correct
37 Correct 87 ms 31936 KB Output is correct
38 Correct 191 ms 46696 KB Output is correct
39 Correct 79 ms 29732 KB Output is correct
40 Correct 294 ms 61092 KB Output is correct
41 Correct 75 ms 29828 KB Output is correct
42 Correct 75 ms 29832 KB Output is correct
43 Correct 276 ms 61412 KB Output is correct
44 Correct 254 ms 61416 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 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 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 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 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 3 ms 596 KB Output is correct
26 Correct 3 ms 584 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 1 ms 452 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 425 ms 59880 KB Output is correct
34 Correct 561 ms 68684 KB Output is correct
35 Correct 526 ms 59900 KB Output is correct
36 Correct 630 ms 63676 KB Output is correct
37 Correct 107 ms 35404 KB Output is correct
38 Correct 98 ms 35412 KB Output is correct
39 Correct 304 ms 65992 KB Output is correct
40 Correct 310 ms 66008 KB Output is correct
41 Correct 81 ms 31948 KB Output is correct
42 Correct 171 ms 46696 KB Output is correct
43 Correct 85 ms 29720 KB Output is correct
44 Correct 265 ms 61116 KB Output is correct
45 Correct 72 ms 29876 KB Output is correct
46 Correct 77 ms 29828 KB Output is correct
47 Correct 270 ms 61356 KB Output is correct
48 Correct 278 ms 61452 KB Output is correct
49 Correct 311 ms 38672 KB Output is correct
50 Correct 267 ms 38716 KB Output is correct
51 Correct 508 ms 67928 KB Output is correct
52 Correct 444 ms 67336 KB Output is correct
53 Correct 255 ms 35164 KB Output is correct
54 Correct 352 ms 50564 KB Output is correct
55 Correct 118 ms 30932 KB Output is correct
56 Correct 420 ms 62844 KB Output is correct
57 Correct 121 ms 31468 KB Output is correct
58 Correct 139 ms 32004 KB Output is correct
59 Correct 268 ms 61388 KB Output is correct