Submission #154143

# Submission time Handle Problem Language Result Execution time Memory
154143 2019-09-18T14:32:41 Z popovicirobert Horses (IOI15_horses) C++14
100 / 100
1153 ms 114896 KB
#include "horses.h"
#include <bits/stdc++.h>

using namespace std;

const int MOD = (int) 1e9 + 7;
const int MAXN = (int) 5e5;

inline int lgput(int a, int b) {
    int ans = 1;
    while(b > 0) {
        if(b & 1) ans = (1LL * ans * a) % MOD;
        b >>= 1;
        a = (1LL * a * a) % MOD;
    }
    return ans;
}

static int X[MAXN + 1], Y[MAXN + 1];
static int n;

struct Node {
    int rem, lazy_rem;
    long double mx, lazy;
}aint[4 * MAXN];

inline void refresh(int nod) {
    if(aint[2 * nod + 1].mx + aint[2 * nod + 1].lazy > aint[2 * nod + 2].mx + aint[2 * nod + 2].lazy) {
        aint[nod].mx = aint[2 * nod + 1].mx + aint[2 * nod + 1].lazy;
        aint[nod].rem = (1LL * aint[2 * nod + 1].rem * aint[2 * nod + 1].lazy_rem) % MOD;
    }
    else {
        aint[nod].mx = aint[2 * nod + 2].mx + aint[2 * nod + 2].lazy;
        aint[nod].rem = (1LL * aint[2 * nod + 2].rem * aint[2 * nod + 2].lazy_rem) % MOD;
    }
}

inline void push(int nod) {
    aint[2 * nod + 1].lazy += aint[nod].lazy;
    aint[2 * nod + 2].lazy += aint[nod].lazy;
    aint[nod].lazy = 0;

    aint[2 * nod + 1].lazy_rem = (1LL * aint[2 * nod + 1].lazy_rem * aint[nod].lazy_rem) % MOD;
    aint[2 * nod + 2].lazy_rem = (1LL * aint[2 * nod + 2].lazy_rem * aint[nod].lazy_rem) % MOD;
    aint[nod].lazy_rem = 1;
}

void update(int nod, int left, int right, int l, int r, long double val, int rem) {
    if(l <= left && right <= r) {
        aint[nod].lazy += val;
        aint[nod].lazy_rem = (1LL * aint[nod].lazy_rem * rem) % MOD;
        return ;
    }
    push(nod);
    int mid = (left + right) / 2;

    if(l <= mid) update(2 * nod + 1, left, mid, l, r, val, rem);
    if(mid < r) update(2 * nod + 2, mid + 1, right, l, r, val, rem);

    refresh(nod);
}

int init(int N, int x[], int y[]) {
    n = N;
    for(int i = 0; i < 4 * n; i++) {
        aint[i] = {1, 1, 0, 0};
    }
    for(int i = 0; i < n; i++) {
        X[i] = x[i], Y[i] = y[i];
        update(0, 0, n - 1, i, i, log(Y[i]), Y[i]);
        update(0, 0, n - 1, i, n - 1, log(X[i]), X[i]);
    }
	return (1LL * aint[0].rem * aint[0].lazy_rem) % MOD;
}

int updateX(int pos, int val) {
    update(0, 0, n - 1, pos, n - 1, -log(X[pos]), lgput(X[pos], MOD - 2));
    X[pos] = val;
    update(0, 0, n - 1, pos, n - 1, log(X[pos]), X[pos]);
	return (1LL * aint[0].rem * aint[0].lazy_rem) % MOD;
}

int updateY(int pos, int val) {
    update(0, 0, n - 1, pos, pos, -log(Y[pos]), lgput(Y[pos], MOD - 2));
    Y[pos] = val;
    update(0, 0, n - 1, pos, pos, log(Y[pos]), Y[pos]);
	return (1LL * aint[0].rem * aint[0].lazy_rem) % MOD;
}

Compilation message

horses.cpp: In function 'int lgput(int, int)':
horses.cpp:12:41: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         if(b & 1) ans = (1LL * ans * a) % MOD;
                         ~~~~~~~~~~~~~~~~^~~~~
horses.cpp:14:27: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         a = (1LL * a * a) % MOD;
             ~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void refresh(int)':
horses.cpp:30:84: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         aint[nod].rem = (1LL * aint[2 * nod + 1].rem * aint[2 * nod + 1].lazy_rem) % MOD;
                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:34:84: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         aint[nod].rem = (1LL * aint[2 * nod + 2].rem * aint[2 * nod + 2].lazy_rem) % MOD;
                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void push(int)':
horses.cpp:43:90: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     aint[2 * nod + 1].lazy_rem = (1LL * aint[2 * nod + 1].lazy_rem * aint[nod].lazy_rem) % MOD;
                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:44:90: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     aint[2 * nod + 2].lazy_rem = (1LL * aint[2 * nod + 2].lazy_rem * aint[nod].lazy_rem) % MOD;
                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void update(int, int, int, int, int, long double, int)':
horses.cpp:51:63: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         aint[nod].lazy_rem = (1LL * aint[nod].lazy_rem * rem) % MOD;
                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:73:48: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return (1LL * aint[0].rem * aint[0].lazy_rem) % MOD;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:80:48: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return (1LL * aint[0].rem * aint[0].lazy_rem) % MOD;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:87:48: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return (1LL * aint[0].rem * aint[0].lazy_rem) % MOD;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 380 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 420 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 4 ms 632 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 4 ms 632 KB Output is correct
26 Correct 4 ms 632 KB Output is correct
27 Correct 5 ms 632 KB Output is correct
28 Correct 4 ms 504 KB Output is correct
29 Correct 4 ms 504 KB Output is correct
30 Correct 4 ms 504 KB Output is correct
31 Correct 5 ms 632 KB Output is correct
32 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 957 ms 105564 KB Output is correct
2 Correct 1094 ms 106700 KB Output is correct
3 Correct 1034 ms 104896 KB Output is correct
4 Correct 1085 ms 104816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 368 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 5 ms 632 KB Output is correct
25 Correct 4 ms 632 KB Output is correct
26 Correct 4 ms 632 KB Output is correct
27 Correct 4 ms 632 KB Output is correct
28 Correct 4 ms 504 KB Output is correct
29 Correct 4 ms 632 KB Output is correct
30 Correct 4 ms 504 KB Output is correct
31 Correct 4 ms 504 KB Output is correct
32 Correct 4 ms 504 KB Output is correct
33 Correct 890 ms 104096 KB Output is correct
34 Correct 875 ms 104028 KB Output is correct
35 Correct 871 ms 104008 KB Output is correct
36 Correct 863 ms 104084 KB Output is correct
37 Correct 806 ms 104056 KB Output is correct
38 Correct 847 ms 104312 KB Output is correct
39 Correct 800 ms 104088 KB Output is correct
40 Correct 903 ms 104144 KB Output is correct
41 Correct 798 ms 104156 KB Output is correct
42 Correct 808 ms 104312 KB Output is correct
43 Correct 812 ms 104120 KB Output is correct
44 Correct 807 ms 104184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 1 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 400 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 5 ms 508 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 4 ms 632 KB Output is correct
26 Correct 4 ms 504 KB Output is correct
27 Correct 5 ms 604 KB Output is correct
28 Correct 4 ms 504 KB Output is correct
29 Correct 4 ms 504 KB Output is correct
30 Correct 4 ms 632 KB Output is correct
31 Correct 4 ms 632 KB Output is correct
32 Correct 4 ms 504 KB Output is correct
33 Correct 996 ms 105124 KB Output is correct
34 Correct 1113 ms 105312 KB Output is correct
35 Correct 1038 ms 105420 KB Output is correct
36 Correct 1082 ms 105208 KB Output is correct
37 Correct 880 ms 104340 KB Output is correct
38 Correct 879 ms 104440 KB Output is correct
39 Correct 860 ms 104640 KB Output is correct
40 Correct 860 ms 104440 KB Output is correct
41 Correct 807 ms 104416 KB Output is correct
42 Correct 848 ms 104440 KB Output is correct
43 Correct 807 ms 104232 KB Output is correct
44 Correct 824 ms 104440 KB Output is correct
45 Correct 818 ms 104440 KB Output is correct
46 Correct 832 ms 104368 KB Output is correct
47 Correct 836 ms 104336 KB Output is correct
48 Correct 812 ms 104308 KB Output is correct
49 Correct 1153 ms 108356 KB Output is correct
50 Correct 1107 ms 108284 KB Output is correct
51 Correct 1008 ms 114896 KB Output is correct
52 Correct 1016 ms 114376 KB Output is correct
53 Correct 1039 ms 106536 KB Output is correct
54 Correct 1022 ms 107104 KB Output is correct
55 Correct 941 ms 105388 KB Output is correct
56 Correct 1004 ms 110056 KB Output is correct
57 Correct 967 ms 106068 KB Output is correct
58 Correct 970 ms 106440 KB Output is correct
59 Correct 813 ms 108476 KB Output is correct