Submission #202434

# Submission time Handle Problem Language Result Execution time Memory
202434 2020-02-16T05:25:43 Z anonymous Horses (IOI15_horses) C++14
100 / 100
198 ms 66680 KB
#include "horses.h"
#include<iostream>
#define MOD (1000000007LL)
#define LL long long
#define INF (1LL<<30)
#define MAXN 500005
using namespace std;
LL n, x[MAXN], y[MAXN];
class Segtree {
    LL ST[MAXN*4][5]; //mod product, actual (or inf), opt product, opt, prod of stuff to right of opt
public:
    void pushup(int cur) {
        ST[cur][0]=(ST[2*cur][0]*ST[2*cur+1][0])%MOD;
        ST[cur][1]=min(ST[2*cur][1]*ST[2*cur+1][1], INF);
        if (ST[2*cur][4] == INF || y[ST[2*cur][3]] <= ST[2*cur+1][2]*ST[2*cur][4]) {
            ST[cur][2] = min(ST[2*cur+1][2]*ST[2*cur][1], INF);
            ST[cur][3] = ST[2*cur+1][3];
            ST[cur][4] = ST[2*cur+1][4];
        } else {
            ST[cur][2] = ST[2*cur][2];
            ST[cur][3] = ST[2*cur][3];
            ST[cur][4] = min(ST[2*cur][4]*ST[2*cur+1][1], INF);
        }
    }
    void build(int l, int r, int cur) {
        if (l == r) {
            ST[cur][0] = x[l];
            ST[cur][1] = x[l];
            ST[cur][2] = min(x[l]*y[l], INF);
            ST[cur][3] = l;
            ST[cur][4] = 1;
        } else {
            int mid=(l+r)>>1;
            build(l, mid, 2*cur);
            build(mid+1, r, 2*cur+1);
            pushup(cur);
        }
    }
    void upd(int ind, int l, int r, int cur) {
        if (l > ind || r < ind) {return;}
        if (l == r) {
            ST[cur][0] = x[l];
            ST[cur][1] = x[l];
            ST[cur][2] = min(x[l]*y[l], INF);
            ST[cur][3] = l;
        } else {
            int mid=(l+r)>>1;
            upd(ind, l, mid, 2*cur);
            upd(ind, mid+1, r, 2*cur+1);
            pushup(cur);
        }
    }
    LL ask(int ind, int l, int r, int cur) { //ask for prefix mod product
        if (ind < l) {return(1);}
        if (r <= ind) {return(ST[cur][0]);}
        else {
            int mid=(l+r)>>1;
            return((ask(ind, l, mid, 2*cur)*ask(ind, mid+1, r, 2*cur+1))%MOD);
        }
    }
    LL opt() {return(ST[1][3]);}
} ST;

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];
	}
	ST.build(0, N-1, 1);
	LL p = ST.opt(), prod = ST.ask(p, 0, N-1, 1);
	LL ans = (prod * y[p])%MOD;
	return( (int) ans);
}

int updateX(int pos, int val) {
	x[pos]=val;
	ST.upd(pos, 0, n-1, 1);
	LL p = ST.opt(), prod = ST.ask(p, 0, n-1, 1);
	LL ans = (prod * y[p])%MOD;
	return( (int) ans);
}

int updateY(int pos, int val) {
	y[pos]=val;
	ST.upd(pos, 0, n-1, 1);
	LL p = ST.opt(), prod = ST.ask(p, 0, n-1, 1);
	LL ans = (prod * y[p])%MOD;
	return( (int) ans);
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:71:45: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  LL p = ST.opt(), prod = ST.ask(p, 0, N-1, 1);
                                             ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:78:18: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  ST.upd(pos, 0, n-1, 1);
                 ~^~
horses.cpp:79:45: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  LL p = ST.opt(), prod = ST.ask(p, 0, n-1, 1);
                                             ^
horses.cpp:79:40: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  LL p = ST.opt(), prod = ST.ask(p, 0, n-1, 1);
                                       ~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:86:18: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  ST.upd(pos, 0, n-1, 1);
                 ~^~
horses.cpp:87:45: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  LL p = ST.opt(), prod = ST.ask(p, 0, n-1, 1);
                                             ^
horses.cpp:87:40: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  LL p = ST.opt(), prod = ST.ask(p, 0, n-1, 1);
                                       ~^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 248 KB Output is correct
10 Correct 5 ms 380 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 6 ms 504 KB Output is correct
24 Correct 6 ms 504 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 6 ms 504 KB Output is correct
27 Correct 5 ms 504 KB Output is correct
28 Correct 5 ms 504 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 504 KB Output is correct
31 Correct 5 ms 504 KB Output is correct
32 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 55672 KB Output is correct
2 Correct 198 ms 66680 KB Output is correct
3 Correct 163 ms 57952 KB Output is correct
4 Correct 179 ms 61816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 400 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 6 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 0 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 6 ms 632 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 504 KB Output is correct
28 Correct 5 ms 504 KB Output is correct
29 Correct 5 ms 504 KB Output is correct
30 Correct 5 ms 504 KB Output is correct
31 Correct 5 ms 512 KB Output is correct
32 Correct 5 ms 504 KB Output is correct
33 Correct 72 ms 57244 KB Output is correct
34 Correct 71 ms 57220 KB Output is correct
35 Correct 96 ms 64248 KB Output is correct
36 Correct 93 ms 63992 KB Output is correct
37 Correct 56 ms 55288 KB Output is correct
38 Correct 58 ms 56184 KB Output is correct
39 Correct 49 ms 55160 KB Output is correct
40 Correct 68 ms 59128 KB Output is correct
41 Correct 50 ms 55288 KB Output is correct
42 Correct 51 ms 55288 KB Output is correct
43 Correct 66 ms 59512 KB Output is correct
44 Correct 67 ms 59512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 5 ms 508 KB Output is correct
25 Correct 6 ms 504 KB Output is correct
26 Correct 6 ms 636 KB Output is correct
27 Correct 5 ms 504 KB Output is correct
28 Correct 5 ms 504 KB Output is correct
29 Correct 5 ms 504 KB Output is correct
30 Correct 5 ms 504 KB Output is correct
31 Correct 5 ms 504 KB Output is correct
32 Correct 5 ms 504 KB Output is correct
33 Correct 101 ms 57976 KB Output is correct
34 Correct 196 ms 66680 KB Output is correct
35 Correct 145 ms 57848 KB Output is correct
36 Correct 165 ms 61688 KB Output is correct
37 Correct 69 ms 57080 KB Output is correct
38 Correct 67 ms 57208 KB Output is correct
39 Correct 94 ms 64120 KB Output is correct
40 Correct 92 ms 64120 KB Output is correct
41 Correct 54 ms 55288 KB Output is correct
42 Correct 58 ms 56184 KB Output is correct
43 Correct 47 ms 55160 KB Output is correct
44 Correct 69 ms 59128 KB Output is correct
45 Correct 48 ms 55288 KB Output is correct
46 Correct 50 ms 55336 KB Output is correct
47 Correct 65 ms 59488 KB Output is correct
48 Correct 65 ms 59512 KB Output is correct
49 Correct 171 ms 59128 KB Output is correct
50 Correct 155 ms 59128 KB Output is correct
51 Correct 145 ms 65912 KB Output is correct
52 Correct 124 ms 65400 KB Output is correct
53 Correct 167 ms 57592 KB Output is correct
54 Correct 110 ms 57976 KB Output is correct
55 Correct 89 ms 56312 KB Output is correct
56 Correct 104 ms 61020 KB Output is correct
57 Correct 96 ms 56824 KB Output is correct
58 Correct 103 ms 57336 KB Output is correct
59 Correct 67 ms 59512 KB Output is correct