Submission #82293

# Submission time Handle Problem Language Result Execution time Memory
82293 2018-10-29T19:16:03 Z farukkastamonuda Horses (IOI15_horses) C++14
100 / 100
646 ms 115472 KB
#include "horses.h"
#include <set>
 
using namespace std;
typedef long long llong;
 
int n;
int x[500001];
int y[500001];
 
set<int> mp;
int seg[1 << 20];
 
void initSeg(int i, int s, int e) {
    if (s == e) {
        seg[i] = y[s];
        return;
    }
    int m = (s + e) / 2;
    initSeg(i << 1, s, m);
    initSeg(i << 1 | 1, m + 1, e);
    seg[i] = max(seg[i << 1], seg[i << 1 | 1]);
}
 
void update(int i, int s, int e, int x) {
    if (s == e) {
        seg[i] = y[x];
        return;
    }
    int m = (s + e) / 2;
    if (x <= m) update(i << 1, s, m, x);
    else update(i << 1 | 1, m + 1, e, x);
    seg[i] = max(seg[i << 1], seg[i << 1 | 1]);
}
 
int query(int i, int s, int e, int x, int y) {
    if (e < x || y < s) return 0;
    if (x <= s && e <= y) return seg[i];
    int m = (s + e) / 2;
    return max(query(i << 1, s, m, x, y), query(i << 1 | 1, m + 1, e, x, y));
}
 
const int mod = 1e9 + 7;
 
int pw(int x, int p) {
    int ret = 1;
    while (p) {
        if (p & 1) ret = (llong)ret * x % mod;
        x = (llong)x * x % mod;
        p >>= 1;
    }
    return ret;
}
int fen[500001];
void init() {
    for (int i = 1; i <= n; ++i) fen[i] = x[i];
    for (int i = 1; i <= n; ++i) {
        int j = i + (i & -i);
        if (j <= n) fen[j] = (llong)fen[j] * fen[i] % mod;
    }
}
 
void update(int i, int x) {
    while (i <= n) {
        fen[i] = (llong)fen[i] * x % mod;
        i += i & -i;
    }
}
 
int query(int i) {
    int ret = 1;
    while (i) {
        ret = (llong)ret * fen[i] % mod;
        i -= i & -i;
    }
    return ret;
}
 
int get() {
    int mxi;
    llong mxv = 0;
    mp.insert(1);
    set<int>::iterator it = mp.end();
    for (int loop = 0; loop < 35 && it != mp.begin(); ++loop) {
        --it;
        int mxY = query(1, 1, n, *it, n);
        if (mxv < mxY) {
            mxi = *it;
            mxv = mxY;
        }
        mxv *= x[*it];
        if (mod < mxv) break;
    }
    return (llong)query(mxi) * query(1, 1, n, mxi, n) % mod;
}
 
int init(int N, int X[], int Y[]) {
	n = N;
	for (int i = 1; i <= n; ++i) {
        x[i] = X[i - 1]; y[i] = Y[i - 1];
        if (x[i] > 1) mp.insert(i);
	}
	init();
	initSeg(1, 1, n);
	return get();
}
 
int updateX(int pos, int val) {
    ++pos;
    update(pos, (llong)val * pw(x[pos], mod - 2) % mod);
    if (x[pos] > 1) mp.erase(pos);
    x[pos] = val;
    if (x[pos] > 1) mp.insert(pos);
	return get();
}
 
int updateY(int pos, int val) {
    ++pos;
    y[pos] = val;
    update(1, 1, n, pos);
	return get();
}

Compilation message

horses.cpp: In function 'void update(int, int, int, int)':
horses.cpp:25:39: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 void update(int i, int s, int e, int x) {
                                       ^
horses.cpp:8:5: note: shadowed declaration is here
 int x[500001];
     ^
horses.cpp: In function 'int query(int, int, int, int, int)':
horses.cpp:36:44: warning: declaration of 'y' shadows a global declaration [-Wshadow]
 int query(int i, int s, int e, int x, int y) {
                                            ^
horses.cpp:9:5: note: shadowed declaration is here
 int y[500001];
     ^
horses.cpp:36:44: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 int query(int i, int s, int e, int x, int y) {
                                            ^
horses.cpp:8:5: note: shadowed declaration is here
 int x[500001];
     ^
horses.cpp: In function 'int pw(int, int)':
horses.cpp:45:20: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 int pw(int x, int p) {
                    ^
horses.cpp:8:5: note: shadowed declaration is here
 int x[500001];
     ^
horses.cpp:48:41: warning: conversion to 'int' from 'llong {aka long long int}' may alter its value [-Wconversion]
         if (p & 1) ret = (llong)ret * x % mod;
                          ~~~~~~~~~~~~~~~^~~~~
horses.cpp:49:26: warning: conversion to 'int' from 'llong {aka long long int}' may alter its value [-Wconversion]
         x = (llong)x * x % mod;
             ~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void init()':
horses.cpp:59:53: warning: conversion to 'int' from 'llong {aka long long int}' may alter its value [-Wconversion]
         if (j <= n) fen[j] = (llong)fen[j] * fen[i] % mod;
                              ~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void update(int, int)':
horses.cpp:63:25: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 void update(int i, int x) {
                         ^
horses.cpp:8:5: note: shadowed declaration is here
 int x[500001];
     ^
horses.cpp:65:36: warning: conversion to 'int' from 'llong {aka long long int}' may alter its value [-Wconversion]
         fen[i] = (llong)fen[i] * x % mod;
                  ~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int query(int)':
horses.cpp:73:35: warning: conversion to 'int' from 'llong {aka long long int}' may alter its value [-Wconversion]
         ret = (llong)ret * fen[i] % mod;
               ~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int get()':
horses.cpp:94:55: warning: conversion to 'int' from 'llong {aka long long int}' may alter its value [-Wconversion]
     return (llong)query(mxi) * query(1, 1, n, mxi, n) % mod;
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:110:50: warning: conversion to 'int' from 'llong {aka long long int}' may alter its value [-Wconversion]
     update(pos, (llong)val * pw(x[pos], mod - 2) % mod);
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int get()':
horses.cpp:94:37: warning: 'mxi' may be used uninitialized in this function [-Wmaybe-uninitialized]
     return (llong)query(mxi) * query(1, 1, n, mxi, n) % mod;
                                ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 584 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 608 KB Output is correct
8 Correct 2 ms 608 KB Output is correct
9 Correct 2 ms 608 KB Output is correct
10 Correct 2 ms 608 KB Output is correct
11 Correct 2 ms 608 KB Output is correct
12 Correct 2 ms 660 KB Output is correct
13 Correct 2 ms 660 KB Output is correct
14 Correct 2 ms 660 KB Output is correct
15 Correct 2 ms 720 KB Output is correct
16 Correct 2 ms 720 KB Output is correct
17 Correct 2 ms 720 KB Output is correct
18 Correct 2 ms 720 KB Output is correct
19 Correct 2 ms 720 KB Output is correct
20 Correct 2 ms 736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 736 KB Output is correct
2 Correct 2 ms 736 KB Output is correct
3 Correct 2 ms 736 KB Output is correct
4 Correct 2 ms 752 KB Output is correct
5 Correct 2 ms 752 KB Output is correct
6 Correct 2 ms 752 KB Output is correct
7 Correct 2 ms 752 KB Output is correct
8 Correct 2 ms 752 KB Output is correct
9 Correct 2 ms 752 KB Output is correct
10 Correct 2 ms 752 KB Output is correct
11 Correct 2 ms 752 KB Output is correct
12 Correct 2 ms 752 KB Output is correct
13 Correct 2 ms 752 KB Output is correct
14 Correct 2 ms 752 KB Output is correct
15 Correct 2 ms 752 KB Output is correct
16 Correct 2 ms 752 KB Output is correct
17 Correct 2 ms 752 KB Output is correct
18 Correct 2 ms 752 KB Output is correct
19 Correct 2 ms 752 KB Output is correct
20 Correct 2 ms 752 KB Output is correct
21 Correct 2 ms 752 KB Output is correct
22 Correct 2 ms 752 KB Output is correct
23 Correct 3 ms 752 KB Output is correct
24 Correct 3 ms 752 KB Output is correct
25 Correct 3 ms 824 KB Output is correct
26 Correct 3 ms 984 KB Output is correct
27 Correct 4 ms 984 KB Output is correct
28 Correct 3 ms 984 KB Output is correct
29 Correct 2 ms 984 KB Output is correct
30 Correct 3 ms 984 KB Output is correct
31 Correct 4 ms 984 KB Output is correct
32 Correct 4 ms 984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 640 ms 39232 KB Output is correct
2 Correct 426 ms 51716 KB Output is correct
3 Correct 441 ms 55576 KB Output is correct
4 Correct 501 ms 63236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 63236 KB Output is correct
2 Correct 2 ms 63236 KB Output is correct
3 Correct 2 ms 63236 KB Output is correct
4 Correct 2 ms 63236 KB Output is correct
5 Correct 2 ms 63236 KB Output is correct
6 Correct 2 ms 63236 KB Output is correct
7 Correct 2 ms 63236 KB Output is correct
8 Correct 2 ms 63236 KB Output is correct
9 Correct 2 ms 63236 KB Output is correct
10 Correct 2 ms 63236 KB Output is correct
11 Correct 2 ms 63236 KB Output is correct
12 Correct 2 ms 63236 KB Output is correct
13 Correct 2 ms 63236 KB Output is correct
14 Correct 2 ms 63236 KB Output is correct
15 Correct 2 ms 63236 KB Output is correct
16 Correct 2 ms 63236 KB Output is correct
17 Correct 2 ms 63236 KB Output is correct
18 Correct 2 ms 63236 KB Output is correct
19 Correct 2 ms 63236 KB Output is correct
20 Correct 2 ms 63236 KB Output is correct
21 Correct 2 ms 63236 KB Output is correct
22 Correct 2 ms 63236 KB Output is correct
23 Correct 2 ms 63236 KB Output is correct
24 Correct 3 ms 63236 KB Output is correct
25 Correct 3 ms 63236 KB Output is correct
26 Correct 2 ms 63236 KB Output is correct
27 Correct 4 ms 63236 KB Output is correct
28 Correct 3 ms 63236 KB Output is correct
29 Correct 2 ms 63236 KB Output is correct
30 Correct 3 ms 63236 KB Output is correct
31 Correct 3 ms 63236 KB Output is correct
32 Correct 4 ms 63236 KB Output is correct
33 Correct 48 ms 63236 KB Output is correct
34 Correct 45 ms 63236 KB Output is correct
35 Correct 249 ms 81256 KB Output is correct
36 Correct 243 ms 82948 KB Output is correct
37 Correct 75 ms 82948 KB Output is correct
38 Correct 129 ms 82948 KB Output is correct
39 Correct 36 ms 82948 KB Output is correct
40 Correct 224 ms 82948 KB Output is correct
41 Correct 59 ms 82948 KB Output is correct
42 Correct 75 ms 82948 KB Output is correct
43 Correct 215 ms 82948 KB Output is correct
44 Correct 215 ms 88324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 88324 KB Output is correct
2 Correct 2 ms 88324 KB Output is correct
3 Correct 2 ms 88324 KB Output is correct
4 Correct 2 ms 88324 KB Output is correct
5 Correct 2 ms 88324 KB Output is correct
6 Correct 2 ms 88324 KB Output is correct
7 Correct 2 ms 88324 KB Output is correct
8 Correct 2 ms 88324 KB Output is correct
9 Correct 2 ms 88324 KB Output is correct
10 Correct 2 ms 88324 KB Output is correct
11 Correct 2 ms 88324 KB Output is correct
12 Correct 2 ms 88324 KB Output is correct
13 Correct 2 ms 88324 KB Output is correct
14 Correct 2 ms 88324 KB Output is correct
15 Correct 2 ms 88324 KB Output is correct
16 Correct 2 ms 88324 KB Output is correct
17 Correct 2 ms 88324 KB Output is correct
18 Correct 2 ms 88324 KB Output is correct
19 Correct 2 ms 88324 KB Output is correct
20 Correct 2 ms 88324 KB Output is correct
21 Correct 2 ms 88324 KB Output is correct
22 Correct 2 ms 88324 KB Output is correct
23 Correct 3 ms 88324 KB Output is correct
24 Correct 3 ms 88324 KB Output is correct
25 Correct 3 ms 88324 KB Output is correct
26 Correct 3 ms 88324 KB Output is correct
27 Correct 4 ms 88324 KB Output is correct
28 Correct 3 ms 88324 KB Output is correct
29 Correct 2 ms 88324 KB Output is correct
30 Correct 3 ms 88324 KB Output is correct
31 Correct 3 ms 88324 KB Output is correct
32 Correct 4 ms 88324 KB Output is correct
33 Correct 646 ms 93452 KB Output is correct
34 Correct 434 ms 106196 KB Output is correct
35 Correct 472 ms 109676 KB Output is correct
36 Correct 479 ms 115360 KB Output is correct
37 Correct 65 ms 115360 KB Output is correct
38 Correct 43 ms 115360 KB Output is correct
39 Correct 256 ms 115360 KB Output is correct
40 Correct 239 ms 115360 KB Output is correct
41 Correct 80 ms 115360 KB Output is correct
42 Correct 129 ms 115360 KB Output is correct
43 Correct 36 ms 115360 KB Output is correct
44 Correct 228 ms 115360 KB Output is correct
45 Correct 59 ms 115360 KB Output is correct
46 Correct 76 ms 115360 KB Output is correct
47 Correct 213 ms 115360 KB Output is correct
48 Correct 220 ms 115360 KB Output is correct
49 Correct 170 ms 115360 KB Output is correct
50 Correct 148 ms 115360 KB Output is correct
51 Correct 421 ms 115360 KB Output is correct
52 Correct 325 ms 115472 KB Output is correct
53 Correct 556 ms 115472 KB Output is correct
54 Correct 291 ms 115472 KB Output is correct
55 Correct 123 ms 115472 KB Output is correct
56 Correct 333 ms 115472 KB Output is correct
57 Correct 344 ms 115472 KB Output is correct
58 Correct 509 ms 115472 KB Output is correct
59 Correct 222 ms 115472 KB Output is correct