Submission #107549

#TimeUsernameProblemLanguageResultExecution timeMemory
107549PeppaPigHorses (IOI15_horses)C++14
Compilation error
0 ms0 KiB
#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;
}


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 (stderr)

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;
            ~~~~~^~~
horses.cpp: At global scope:
horses.cpp:100:9: error: redefinition of 'node A [524288]'
 node A[N];
         ^
horses.cpp:33:6: note: 'node A [524288]' previously declared here
 node A[N];
      ^
horses.cpp: In function 'void build(int, int, int)':
horses.cpp:102:6: error: redefinition of 'void build(int, int, int)'
 void build(var) {
      ^~~~~
horses.cpp:35:6: note: 'void build(int, int, int)' previously defined here
 void build(var) {
      ^~~~~
horses.cpp: In function 'void push(int, int, int)':
horses.cpp:108:6: error: redefinition of 'void push(int, int, int)'
 void push(var) {
      ^~~~
horses.cpp:41:6: note: 'void push(int, int, int)' previously defined here
 void push(var) {
      ^~~~
horses.cpp: In function 'void update(int, int, node, int, int, int)':
horses.cpp:117:6: error: redefinition of 'void update(int, int, node, int, int, int)'
 void update(int x, int y, node k, var) {
      ^~~~~~
horses.cpp:50:6: note: 'void update(int, int, node, int, int, int)' previously defined here
 void update(int x, int y, node k, var) {
      ^~~~~~
horses.cpp:117: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:117: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:129:5: error: redefinition of 'int init(int, int*, int*)'
 int init(int N, int X[], int Y[]) {
     ^~~~
horses.cpp:62:5: note: 'int init(int, int*, int*)' previously defined here
 int init(int N, int X[], int Y[]) {
     ^~~~
horses.cpp:129: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:138:17: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return t[1].sum;
            ~~~~~^~~
horses.cpp: In function 'long long int modpow(long long int, long long int)':
horses.cpp:141:6: error: redefinition of 'long long int modpow(long long int, long long int)'
 long modpow(long a, long b) {
      ^~~~~~
horses.cpp:74:6: note: 'long long int modpow(long long int, long long int)' previously defined here
 long modpow(long a, long b) {
      ^~~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:150:5: error: redefinition of 'int updateX(int, int)'
 int updateX(int pos, int val) {
     ^~~~~~~
horses.cpp:83:5: note: 'int updateX(int, int)' previously defined here
 int updateX(int pos, int val) {
     ^~~~~~~
horses.cpp:155: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:158:5: error: redefinition of 'int updateY(int, int)'
 int updateY(int pos, int val) {
     ^~~~~~~
horses.cpp:91:5: note: 'int updateY(int, int)' previously defined here
 int updateY(int pos, int val) {
     ^~~~~~~
horses.cpp:163:17: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return t[1].sum;
            ~~~~~^~~