Submission #365029

# Submission time Handle Problem Language Result Execution time Memory
365029 2021-02-10T19:04:24 Z BartolM Horses (IOI15_horses) C++17
57 / 100
1500 ms 71324 KB
#include "horses.h"
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;

const int INF=0x3f3f3f3f;
const int MOD=1e9+7;
const int OFF=(1<<19);
const int MAXN=5e5+5;

int n;
pll T[2*OFF];
ll Tmax[2*OFF];
ll x[MAXN], y[MAXN];
set <int> S;

ll mul(ll a, ll b) {
    return a*b%MOD;
}

pll f(pll a, pll b) {
    return mp(mul(a.X, b.X), min((ll)MOD, a.Y*b.Y));
}

pll umn(int a, int b, int pos=1, int lo=0, int hi=OFF) {
    if (lo>=a && hi<=b) return T[pos];
    if (lo>=b || hi<=a) return mp(1, 1);
    int mid=(lo+hi)/2;
    return f(umn(a, b, pos*2, lo, mid), umn(a, b, pos*2+1, mid, hi));
}

ll maxi(int a, int b, int pos=1, int lo=0, int hi=OFF) {
    if (lo>=a && hi<=b) return Tmax[pos];
    if (lo>=b || hi<=a) return 1;
    int mid=(lo+hi)/2;
    return max(maxi(a, b, pos*2, lo, mid), maxi(a, b, pos*2+1, mid, hi));
}

int mrg(int a, int b, ll ya, ll yb) {
    if (a==n) return b;
    if (b==n) return a;
    ll bb=f(umn(a+1, b+1), mp(yb, yb)).Y;
    return bb>=ya ? b : a;
}

ll answer() {
    if (S.size()==1) return maxi(0, n);

    int res=n, cnt=31; ll yres=0;
    set <int>::iterator it=S.end(); it--;
    while (it!=S.begin() && cnt) {
        auto nx=it;
        it--;
        cnt--;
        ll curr_y=maxi(*it, *nx);

        res=mrg(*it, res, curr_y, yres);
        if (res==*it) yres=curr_y;
    }
    return mul(umn(0, res+1).X, yres);
}

int init(int N, int XX[], int YY[]) {
    n=N;
    for (int i=0; i<n; ++i) x[i]=XX[i], y[i]=YY[i];
    for (int i=0; i<n; ++i) if (x[i]!=1) S.insert(i);
    S.insert(n); S.insert(0);

    memset(Tmax, 0, sizeof Tmax);
    fill(T, T+2*OFF, mp(1, 1));
    for (int i=0; i<n; ++i) Tmax[OFF+i]=y[i], T[OFF+i].X=T[OFF+i].Y=x[i];
    for (int i=OFF-1; i>0; --i) T[i]=f(T[i*2], T[i*2+1]), Tmax[i]=max(Tmax[i*2], Tmax[i*2+1]);

    return answer();
}

int updateY(int pos, int val) {
    y[pos]=val;
    pos+=OFF;
    Tmax[pos]=val;
    pos/=2;
    while (pos) {
        Tmax[pos]=max(Tmax[pos*2], Tmax[pos*2+1]);
        pos/=2;
    }
    return answer();
}

int updateX(int pos, int val) {

    if (val!=1) S.insert(pos);
    x[pos]=val;
    if (val==1 && S.count(pos)) S.erase(pos);
    S.insert(0);

    pos+=OFF;
    T[pos].X=T[pos].Y=val;
    pos/=2;

    while (pos) {
        T[pos]=f(T[pos*2], T[pos*2+1]);
        pos/=2;
    }
    return answer();
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:84:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   84 |     return answer();
      |            ~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:96:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   96 |     return answer();
      |            ~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:114:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  114 |     return answer();
      |            ~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 24940 KB Output is correct
2 Correct 17 ms 24940 KB Output is correct
3 Correct 17 ms 24940 KB Output is correct
4 Correct 17 ms 24940 KB Output is correct
5 Correct 17 ms 24940 KB Output is correct
6 Correct 17 ms 24940 KB Output is correct
7 Correct 17 ms 24940 KB Output is correct
8 Correct 21 ms 24940 KB Output is correct
9 Correct 17 ms 24940 KB Output is correct
10 Correct 17 ms 24940 KB Output is correct
11 Correct 17 ms 24940 KB Output is correct
12 Correct 17 ms 24960 KB Output is correct
13 Correct 17 ms 24940 KB Output is correct
14 Correct 17 ms 24940 KB Output is correct
15 Correct 17 ms 24940 KB Output is correct
16 Correct 20 ms 24940 KB Output is correct
17 Correct 17 ms 24940 KB Output is correct
18 Correct 18 ms 24940 KB Output is correct
19 Correct 17 ms 24940 KB Output is correct
20 Correct 20 ms 24940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 24940 KB Output is correct
2 Correct 17 ms 24940 KB Output is correct
3 Correct 17 ms 24940 KB Output is correct
4 Correct 17 ms 24940 KB Output is correct
5 Correct 17 ms 24940 KB Output is correct
6 Correct 17 ms 24940 KB Output is correct
7 Correct 17 ms 24940 KB Output is correct
8 Correct 17 ms 24940 KB Output is correct
9 Correct 17 ms 25068 KB Output is correct
10 Correct 17 ms 24940 KB Output is correct
11 Correct 17 ms 24940 KB Output is correct
12 Correct 18 ms 24940 KB Output is correct
13 Correct 17 ms 24940 KB Output is correct
14 Correct 17 ms 24940 KB Output is correct
15 Correct 17 ms 24940 KB Output is correct
16 Correct 17 ms 24940 KB Output is correct
17 Correct 17 ms 24960 KB Output is correct
18 Correct 17 ms 24940 KB Output is correct
19 Correct 17 ms 24940 KB Output is correct
20 Correct 18 ms 25068 KB Output is correct
21 Correct 17 ms 24940 KB Output is correct
22 Correct 17 ms 24940 KB Output is correct
23 Correct 35 ms 25068 KB Output is correct
24 Correct 34 ms 25068 KB Output is correct
25 Correct 34 ms 25068 KB Output is correct
26 Correct 36 ms 25068 KB Output is correct
27 Correct 34 ms 25196 KB Output is correct
28 Correct 37 ms 25068 KB Output is correct
29 Correct 19 ms 24940 KB Output is correct
30 Correct 34 ms 25068 KB Output is correct
31 Correct 28 ms 24940 KB Output is correct
32 Correct 34 ms 24940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1593 ms 62956 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 24940 KB Output is correct
2 Correct 17 ms 24940 KB Output is correct
3 Correct 17 ms 24940 KB Output is correct
4 Correct 21 ms 24940 KB Output is correct
5 Correct 17 ms 24940 KB Output is correct
6 Correct 18 ms 25068 KB Output is correct
7 Correct 17 ms 24940 KB Output is correct
8 Correct 17 ms 24940 KB Output is correct
9 Correct 17 ms 24940 KB Output is correct
10 Correct 18 ms 24940 KB Output is correct
11 Correct 17 ms 24940 KB Output is correct
12 Correct 17 ms 24940 KB Output is correct
13 Correct 20 ms 24940 KB Output is correct
14 Correct 17 ms 24940 KB Output is correct
15 Correct 17 ms 24940 KB Output is correct
16 Correct 17 ms 24940 KB Output is correct
17 Correct 17 ms 24940 KB Output is correct
18 Correct 17 ms 24940 KB Output is correct
19 Correct 17 ms 24940 KB Output is correct
20 Correct 17 ms 24940 KB Output is correct
21 Correct 17 ms 24940 KB Output is correct
22 Correct 17 ms 24940 KB Output is correct
23 Correct 35 ms 25068 KB Output is correct
24 Correct 34 ms 25068 KB Output is correct
25 Correct 34 ms 25088 KB Output is correct
26 Correct 34 ms 25068 KB Output is correct
27 Correct 34 ms 25068 KB Output is correct
28 Correct 34 ms 25068 KB Output is correct
29 Correct 19 ms 24940 KB Output is correct
30 Correct 34 ms 25068 KB Output is correct
31 Correct 28 ms 24940 KB Output is correct
32 Correct 34 ms 24940 KB Output is correct
33 Correct 283 ms 39148 KB Output is correct
34 Correct 219 ms 40812 KB Output is correct
35 Correct 368 ms 71148 KB Output is correct
36 Correct 356 ms 71324 KB Output is correct
37 Correct 271 ms 39148 KB Output is correct
38 Correct 289 ms 51820 KB Output is correct
39 Correct 58 ms 38764 KB Output is correct
40 Correct 342 ms 66292 KB Output is correct
41 Correct 152 ms 38892 KB Output is correct
42 Correct 226 ms 39020 KB Output is correct
43 Correct 182 ms 66668 KB Output is correct
44 Correct 182 ms 66668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 24940 KB Output is correct
2 Correct 21 ms 24940 KB Output is correct
3 Correct 17 ms 24940 KB Output is correct
4 Correct 16 ms 24940 KB Output is correct
5 Correct 17 ms 24940 KB Output is correct
6 Correct 16 ms 24940 KB Output is correct
7 Correct 16 ms 24940 KB Output is correct
8 Correct 16 ms 24940 KB Output is correct
9 Correct 16 ms 24940 KB Output is correct
10 Correct 17 ms 24940 KB Output is correct
11 Correct 18 ms 25068 KB Output is correct
12 Correct 16 ms 24940 KB Output is correct
13 Correct 16 ms 24940 KB Output is correct
14 Correct 19 ms 24940 KB Output is correct
15 Correct 17 ms 24940 KB Output is correct
16 Correct 17 ms 24940 KB Output is correct
17 Correct 17 ms 24940 KB Output is correct
18 Correct 17 ms 24940 KB Output is correct
19 Correct 16 ms 24940 KB Output is correct
20 Correct 16 ms 24940 KB Output is correct
21 Correct 18 ms 24940 KB Output is correct
22 Correct 17 ms 24940 KB Output is correct
23 Correct 34 ms 25068 KB Output is correct
24 Correct 34 ms 25068 KB Output is correct
25 Correct 33 ms 25068 KB Output is correct
26 Correct 33 ms 25068 KB Output is correct
27 Correct 39 ms 25068 KB Output is correct
28 Correct 34 ms 25068 KB Output is correct
29 Correct 19 ms 24940 KB Output is correct
30 Correct 34 ms 25108 KB Output is correct
31 Correct 27 ms 24940 KB Output is correct
32 Correct 33 ms 24940 KB Output is correct
33 Execution timed out 1573 ms 64720 KB Time limit exceeded
34 Halted 0 ms 0 KB -