Submission #291468

# Submission time Handle Problem Language Result Execution time Memory
291468 2020-09-05T10:58:25 Z MarcoMeijer Horses (IOI15_horses) C++14
100 / 100
364 ms 63992 KB
#include <bits/stdc++.h>

using namespace std;

#include "horses.h"

//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define INF 1e9
#define pb push_back
#define fi first
#define se second
#define sz size()

const int MX = 5e5+10;
const int MOD = 1e9+7;
ll n, x[MX], y[MX];
ll segX[MX*2];
ll segY[MX*2];
set<int> corX;

void buildSeg() {
    RE(i,n) segX[i+n] = x[i];
    RE(i,n) segY[i+n] = y[i];
    REV(i,1,n) segX[i] = (segX[i*2]*segX[i*2+1])%MOD;
    REV(i,1,n) segY[i] = max(segY[i*2], segY[i*2+1]);
}
void setSegX(int i, ll v) {
    for(segX[i+=n]=v; i>1; i/=2) segX[i/2] = (segX[i]*segX[i^1])%MOD;
}
void setSegY(int i, ll v) {
    for(segY[i+=n]=v; i>1; i/=2) segY[i/2] = max(segY[i], segY[i^1]);
}
ll getSegX(int l, int r) {
    ll res = 1;
    for(l+=n, r+=n; l<r; l/=2, r/=2) {
        if(l&1) res = (res*segX[l++])%MOD;
        if(r&1) res = (res*segX[--r])%MOD;
    }
    return res;
}
ll getSegY(int l, int r) {
    ll res = 0;
    for(l+=n, r+=n; l<r; l/=2, r/=2) {
        if(l&1) res = max(res, segY[l++]);
        if(r&1) res = max(res, segY[--r]);
    }
    return res;
}

int getAns() {
    ll bst = 1;
    int i=n;
    auto it = corX.end();
    while(it != corX.begin()) {
        --it;
        bst = x[*it]*max(bst, getSegY(*it,i));
        i = *it;
        if(bst >= INF) {
            break;
        }
    }
    bst = max(bst, getSegY(0,n));
    bst %= MOD;
    bst = (bst*getSegX(0,i))%MOD;
    return bst;
}

int init(int N, int X[], int Y[]) {
    n=N;
    RE(i,n) x[i]=X[i];
    RE(i,n) y[i]=Y[i];
    RE(i,n) if(x[i] != 1) corX.insert(i);
    buildSeg();
	return getAns();
}

int updateX(int pos, int val) {	
    corX.erase(pos);
    x[pos] = val;
    if(val != 1) corX.insert(pos);
    setSegX(pos, val);
	return getAns();
}

int updateY(int pos, int val) {
    y[pos] = val;
    setSegY(pos, val);
	return getAns();
}

Compilation message

horses.cpp: In function 'void setSegX(int, ll)':
horses.cpp:42:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   42 |     for(segX[i+=n]=v; i>1; i/=2) segX[i/2] = (segX[i]*segX[i^1])%MOD;
      |              ~^~~
horses.cpp: In function 'void setSegY(int, ll)':
horses.cpp:45:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   45 |     for(segY[i+=n]=v; i>1; i/=2) segY[i/2] = max(segY[i], segY[i^1]);
      |              ~^~~
horses.cpp: In function 'll getSegX(int, int)':
horses.cpp:49:10: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   49 |     for(l+=n, r+=n; l<r; l/=2, r/=2) {
      |         ~^~~
horses.cpp:49:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   49 |     for(l+=n, r+=n; l<r; l/=2, r/=2) {
      |               ~^~~
horses.cpp: In function 'll getSegY(int, int)':
horses.cpp:57:10: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   57 |     for(l+=n, r+=n; l<r; l/=2, r/=2) {
      |         ~^~~
horses.cpp:57:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   57 |     for(l+=n, r+=n; l<r; l/=2, r/=2) {
      |               ~^~~
horses.cpp: In function 'int getAns()':
horses.cpp:66:11: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   66 |     int i=n;
      |           ^
horses.cpp:72:12: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
   72 |         if(bst >= INF) {
      |            ^~~
horses.cpp:76:30: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   76 |     bst = max(bst, getSegY(0,n));
      |                              ^
horses.cpp:79:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   79 |     return bst;
      |            ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 512 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 201 ms 52256 KB Output is correct
2 Correct 314 ms 52216 KB Output is correct
3 Correct 275 ms 52216 KB Output is correct
4 Correct 357 ms 52344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 416 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 41 ms 27896 KB Output is correct
34 Correct 42 ms 27896 KB Output is correct
35 Correct 180 ms 51320 KB Output is correct
36 Correct 176 ms 51268 KB Output is correct
37 Correct 42 ms 27896 KB Output is correct
38 Correct 90 ms 39800 KB Output is correct
39 Correct 32 ms 27768 KB Output is correct
40 Correct 162 ms 57336 KB Output is correct
41 Correct 33 ms 29944 KB Output is correct
42 Correct 35 ms 29944 KB Output is correct
43 Correct 164 ms 57592 KB Output is correct
44 Correct 156 ms 57748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 512 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 205 ms 52220 KB Output is correct
34 Correct 312 ms 52216 KB Output is correct
35 Correct 282 ms 52216 KB Output is correct
36 Correct 364 ms 52160 KB Output is correct
37 Correct 41 ms 27896 KB Output is correct
38 Correct 41 ms 27904 KB Output is correct
39 Correct 182 ms 51320 KB Output is correct
40 Correct 175 ms 51272 KB Output is correct
41 Correct 42 ms 27896 KB Output is correct
42 Correct 91 ms 39800 KB Output is correct
43 Correct 31 ms 27768 KB Output is correct
44 Correct 163 ms 57208 KB Output is correct
45 Correct 32 ms 29816 KB Output is correct
46 Correct 34 ms 29944 KB Output is correct
47 Correct 158 ms 57592 KB Output is correct
48 Correct 158 ms 57720 KB Output is correct
49 Correct 120 ms 34936 KB Output is correct
50 Correct 115 ms 35064 KB Output is correct
51 Correct 240 ms 63992 KB Output is correct
52 Correct 222 ms 63480 KB Output is correct
53 Correct 168 ms 33144 KB Output is correct
54 Correct 163 ms 46840 KB Output is correct
55 Correct 84 ms 30840 KB Output is correct
56 Correct 232 ms 59000 KB Output is correct
57 Correct 78 ms 31480 KB Output is correct
58 Correct 111 ms 31992 KB Output is correct
59 Correct 158 ms 57592 KB Output is correct