Submission #107551

# Submission time Handle Problem Language Result Execution time Memory
107551 2019-04-25T04:10:46 Z PeppaPig Horses (IOI15_horses) C++14
100 / 100
409 ms 50808 KB
#include "horses.h"
#include <bits/stdc++.h>
 
#define long long long
 
using namespace std;
 
const int N = 1<<19;
const int M = 1e9+7;
 
#define var int p = 1, int l = 0, int r = n-1
#define mid ((l + r) >> 1)
#define lb p<<1, l, mid
#define rb p<<1|1, mid+1, r
 
struct node {
    double log;
    long sum;
    node() : log(0), sum(1) { }
    node(double log, long sum) : log(log), sum(sum) { }
    friend node operator+(const node &a, const node &b) {
        node ret;
        ret.log = a.log + b.log;
        ret.sum = (a.sum * b.sum) % M;
        return ret;
    }
    friend bool operator<(const node &a, const node &b) {
        return make_pair(a.log, a.sum) < make_pair(b.log, b.sum);
    }
} t[N<<1], lz[N<<1];
 
int n, x[N], y[N];
node A[N];
 
void build(var) {
    if(l == r) return void(t[p] = A[l]);
    build(lb), build(rb);
    t[p] = t[p<<1] < t[p<<1|1] ? t[p<<1|1] : t[p<<1];
}
 
void push(var) {
    t[p] = t[p] + lz[p];
    if(l != r) {
        lz[p<<1] = lz[p<<1] + lz[p];
        lz[p<<1|1] = lz[p<<1|1] + lz[p];
    }
    lz[p] = node(0, 1);
}
 
void update(int x, int y, node k, var) {
    push(p, l, r);
    if(x > r || l > y) return;
    if(x <= l && r <= y) {
        lz[p] = lz[p] + k;
        push(p, l, r);
        return;
    }
    update(x, y, k, lb), update(x, y, k, rb);
    t[p] = t[p<<1] < t[p<<1|1] ? t[p<<1|1] : t[p<<1];
}
 
int init(int N, int X[], int Y[]) {
    n = N;
    node cul(0, 1);
    for(int i = 0; i < n; i++) {
        x[i] = X[i], y[i] = Y[i];
        cul = cul + node((double)log2(x[i]), x[i]);
        A[i] = cul + node((double)log2(y[i]), y[i]); 
    }
    build();
    return t[1].sum;
}
 
long modpow(long a, long b) {
    long ret = 1;
    for( ; b; b >>= 1) {
        if(b & 1) ret = (ret * a) % M;
        a = (a * a) % M;
    }
    return ret;
}
 
int updateX(int pos, int val) {
    double nlog = (double)log2(val) - (double)log2(x[pos]);
    long nsum = (1ll * val * modpow(x[pos], M-2)) % M;
    x[pos] = val;
    update(pos, n-1, node(nlog, nsum));
    return t[1].sum;
}
 
int updateY(int pos, int val) {
    double nlog = (double)log2(val) - (double)log2(y[pos]);
    long nsum = (1ll * val * modpow(y[pos], M-2)) % M;
    y[pos] = val;
    update(pos, pos, node(nlog, nsum));
    return t[1].sum;
}

Compilation message

horses.cpp: In constructor 'node::node(double, long long int)':
horses.cpp:20:32: warning: declaration of 'sum' shadows a member of 'node' [-Wshadow]
     node(double log, long sum) : log(log), sum(sum) { }
                                ^
horses.cpp:18:10: note: shadowed declaration is here
     long sum;
          ^~~
horses.cpp:20:32: warning: declaration of 'log' shadows a member of 'node' [-Wshadow]
     node(double log, long sum) : log(log), sum(sum) { }
                                ^
horses.cpp:17:12: note: shadowed declaration is here
     double log;
            ^~~
horses.cpp: In function 'void update(int, int, node, int, int, int)':
horses.cpp:50:38: warning: declaration of 'y' shadows a global declaration [-Wshadow]
 void update(int x, int y, node k, var) {
                                      ^
horses.cpp:32:14: note: shadowed declaration is here
 int n, x[N], y[N];
              ^
horses.cpp:50:38: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 void update(int x, int y, node k, var) {
                                      ^
horses.cpp:32:8: note: shadowed declaration is here
 int n, x[N], y[N];
        ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:62:33: warning: declaration of 'N' shadows a global declaration [-Wshadow]
 int init(int N, int X[], int Y[]) {
                                 ^
horses.cpp:8:11: note: shadowed declaration is here
 const int N = 1<<19;
           ^
horses.cpp:71:17: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return t[1].sum;
            ~~~~~^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:88:17: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return t[1].sum;
            ~~~~~^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:96:17: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return t[1].sum;
            ~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 38 ms 41336 KB Output is correct
2 Correct 45 ms 41340 KB Output is correct
3 Correct 41 ms 41472 KB Output is correct
4 Correct 37 ms 41464 KB Output is correct
5 Correct 36 ms 41312 KB Output is correct
6 Correct 37 ms 41316 KB Output is correct
7 Correct 36 ms 41436 KB Output is correct
8 Correct 37 ms 41336 KB Output is correct
9 Correct 34 ms 41336 KB Output is correct
10 Correct 43 ms 41336 KB Output is correct
11 Correct 36 ms 41336 KB Output is correct
12 Correct 36 ms 41344 KB Output is correct
13 Correct 38 ms 41336 KB Output is correct
14 Correct 41 ms 41336 KB Output is correct
15 Correct 36 ms 41336 KB Output is correct
16 Correct 37 ms 41336 KB Output is correct
17 Correct 38 ms 41336 KB Output is correct
18 Correct 35 ms 41332 KB Output is correct
19 Correct 36 ms 41336 KB Output is correct
20 Correct 38 ms 41336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 41336 KB Output is correct
2 Correct 38 ms 41336 KB Output is correct
3 Correct 36 ms 41336 KB Output is correct
4 Correct 33 ms 41336 KB Output is correct
5 Correct 42 ms 41336 KB Output is correct
6 Correct 34 ms 41336 KB Output is correct
7 Correct 39 ms 41464 KB Output is correct
8 Correct 41 ms 41336 KB Output is correct
9 Correct 33 ms 41336 KB Output is correct
10 Correct 32 ms 41344 KB Output is correct
11 Correct 33 ms 41344 KB Output is correct
12 Correct 37 ms 41344 KB Output is correct
13 Correct 35 ms 41400 KB Output is correct
14 Correct 33 ms 41336 KB Output is correct
15 Correct 38 ms 41420 KB Output is correct
16 Correct 38 ms 41336 KB Output is correct
17 Correct 37 ms 41336 KB Output is correct
18 Correct 35 ms 41336 KB Output is correct
19 Correct 35 ms 41336 KB Output is correct
20 Correct 37 ms 41336 KB Output is correct
21 Correct 41 ms 41312 KB Output is correct
22 Correct 36 ms 41388 KB Output is correct
23 Correct 38 ms 41464 KB Output is correct
24 Correct 37 ms 41592 KB Output is correct
25 Correct 38 ms 41464 KB Output is correct
26 Correct 38 ms 41464 KB Output is correct
27 Correct 42 ms 41436 KB Output is correct
28 Correct 36 ms 41344 KB Output is correct
29 Correct 36 ms 41444 KB Output is correct
30 Correct 37 ms 41436 KB Output is correct
31 Correct 39 ms 41464 KB Output is correct
32 Correct 40 ms 41464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 178 ms 50404 KB Output is correct
2 Correct 409 ms 50600 KB Output is correct
3 Correct 287 ms 50808 KB Output is correct
4 Correct 344 ms 50624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 41404 KB Output is correct
2 Correct 37 ms 41336 KB Output is correct
3 Correct 33 ms 41336 KB Output is correct
4 Correct 37 ms 41336 KB Output is correct
5 Correct 34 ms 41472 KB Output is correct
6 Correct 38 ms 41336 KB Output is correct
7 Correct 40 ms 41464 KB Output is correct
8 Correct 41 ms 41472 KB Output is correct
9 Correct 33 ms 41336 KB Output is correct
10 Correct 36 ms 41340 KB Output is correct
11 Correct 40 ms 41372 KB Output is correct
12 Correct 34 ms 41400 KB Output is correct
13 Correct 36 ms 41336 KB Output is correct
14 Correct 35 ms 41336 KB Output is correct
15 Correct 36 ms 41292 KB Output is correct
16 Correct 34 ms 41336 KB Output is correct
17 Correct 34 ms 41336 KB Output is correct
18 Correct 34 ms 41368 KB Output is correct
19 Correct 35 ms 41464 KB Output is correct
20 Correct 33 ms 41336 KB Output is correct
21 Correct 37 ms 41344 KB Output is correct
22 Correct 44 ms 41340 KB Output is correct
23 Correct 36 ms 41336 KB Output is correct
24 Correct 44 ms 41464 KB Output is correct
25 Correct 34 ms 41592 KB Output is correct
26 Correct 39 ms 41344 KB Output is correct
27 Correct 38 ms 41436 KB Output is correct
28 Correct 40 ms 41352 KB Output is correct
29 Correct 38 ms 41336 KB Output is correct
30 Correct 44 ms 41344 KB Output is correct
31 Correct 37 ms 41336 KB Output is correct
32 Correct 47 ms 41464 KB Output is correct
33 Correct 98 ms 49656 KB Output is correct
34 Correct 100 ms 49808 KB Output is correct
35 Correct 115 ms 49656 KB Output is correct
36 Correct 125 ms 49656 KB Output is correct
37 Correct 96 ms 49668 KB Output is correct
38 Correct 81 ms 49656 KB Output is correct
39 Correct 74 ms 49656 KB Output is correct
40 Correct 102 ms 49724 KB Output is correct
41 Correct 83 ms 49660 KB Output is correct
42 Correct 81 ms 49676 KB Output is correct
43 Correct 103 ms 49724 KB Output is correct
44 Correct 89 ms 49528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 41336 KB Output is correct
2 Correct 35 ms 41344 KB Output is correct
3 Correct 37 ms 41368 KB Output is correct
4 Correct 33 ms 41344 KB Output is correct
5 Correct 35 ms 41344 KB Output is correct
6 Correct 38 ms 41404 KB Output is correct
7 Correct 34 ms 41336 KB Output is correct
8 Correct 36 ms 41392 KB Output is correct
9 Correct 36 ms 41344 KB Output is correct
10 Correct 37 ms 41344 KB Output is correct
11 Correct 33 ms 41344 KB Output is correct
12 Correct 34 ms 41336 KB Output is correct
13 Correct 39 ms 41336 KB Output is correct
14 Correct 39 ms 41336 KB Output is correct
15 Correct 37 ms 41336 KB Output is correct
16 Correct 39 ms 41336 KB Output is correct
17 Correct 37 ms 41336 KB Output is correct
18 Correct 40 ms 41336 KB Output is correct
19 Correct 35 ms 41336 KB Output is correct
20 Correct 36 ms 41344 KB Output is correct
21 Correct 36 ms 41336 KB Output is correct
22 Correct 35 ms 41344 KB Output is correct
23 Correct 39 ms 41464 KB Output is correct
24 Correct 39 ms 41436 KB Output is correct
25 Correct 64 ms 41468 KB Output is correct
26 Correct 36 ms 41444 KB Output is correct
27 Correct 37 ms 41336 KB Output is correct
28 Correct 39 ms 41464 KB Output is correct
29 Correct 39 ms 41344 KB Output is correct
30 Correct 37 ms 41472 KB Output is correct
31 Correct 39 ms 41336 KB Output is correct
32 Correct 36 ms 41400 KB Output is correct
33 Correct 183 ms 50524 KB Output is correct
34 Correct 349 ms 50592 KB Output is correct
35 Correct 347 ms 50732 KB Output is correct
36 Correct 372 ms 50692 KB Output is correct
37 Correct 100 ms 49656 KB Output is correct
38 Correct 96 ms 49532 KB Output is correct
39 Correct 118 ms 49656 KB Output is correct
40 Correct 125 ms 49692 KB Output is correct
41 Correct 108 ms 49572 KB Output is correct
42 Correct 98 ms 49508 KB Output is correct
43 Correct 76 ms 49528 KB Output is correct
44 Correct 92 ms 49528 KB Output is correct
45 Correct 69 ms 49624 KB Output is correct
46 Correct 71 ms 49528 KB Output is correct
47 Correct 78 ms 49272 KB Output is correct
48 Correct 81 ms 49272 KB Output is correct
49 Correct 305 ms 50424 KB Output is correct
50 Correct 334 ms 50424 KB Output is correct
51 Correct 212 ms 50408 KB Output is correct
52 Correct 212 ms 50296 KB Output is correct
53 Correct 293 ms 50476 KB Output is correct
54 Correct 216 ms 50144 KB Output is correct
55 Correct 160 ms 49656 KB Output is correct
56 Correct 198 ms 50296 KB Output is correct
57 Correct 158 ms 50296 KB Output is correct
58 Correct 173 ms 50444 KB Output is correct
59 Correct 84 ms 49400 KB Output is correct