Submission #220354

#TimeUsernameProblemLanguageResultExecution timeMemory
220354giorgikobHorses (IOI15_horses)C++14
Compilation error
0 ms0 KiB
#include "horses.h"


typedef long long ll;

const int mod = 1e9+7;

int jump[1000000];
int X[1000000], Y[1000000];

int get_idx(int l,int r){

        if(l == r){
                return l;
        }

        int mid = l+r;
        mid >>= 1;
        int x = get_idx(l,mid);
        int y = get_idx(mid+1,r);

        ll cnt = 1;
        for(int i = x+1; i <= y; i++){
                if(jump[i] != -1){
                        i = jump[i];
                        continue;
                }
                cnt *= X[i];
                if(cnt > Y[x]){
                        break;
                }
        }

        return (cnt > Y[x]) ? y : x;
}

ll calc(int pos){
        ll cnt = 1;
        for(int i = 0; i < pos; i++){
                cnt *= X[i];
                cnt %= mod;
        }
        cnt *= Y[pos];
        cnt %= mod;
        return cnt;
}

void go(){

        for(int i = 0; i < N; i++){
                if(X[i] == 1){
                        int l = i;
                        while(i+1 < N && X[i+1] == 0) i++;
                        while(l != i) jump[l] = i, l++;
                }
        }
}

int init(int N, int x[], int y[]) {

        for(int i = 0; i < N; i++){
                jump[i] = -1;
                beg[i] = -1;
                X[i] = x[i];
                Y[i] = y[i];
        }

        go();

        int idx = get_idx(0,N);

	return calc(idx);
}

int updateX(int pos, int val) {

        X[pos] = val;

        go();

        int idx = get_idx(0,N);

	return calc(idx);
}

int updateY(int pos, int val) {

        Y[pos] = val;

        int idx = get_idx(0,N);

	return calc(idx);
}


ll calc(int pos){
        ll cnt = 1;
        for(int i = 0; i < pos; i++){
                cnt *= X[i];
                cnt %= mod;
        }
        cnt *= Y[i];
        cnt %= mod;
        return cnt;
}

void go(){

        for(int i = 0; i < N; i++){
                if(X[i] == 1){
                        int l = i;
                        while(i+1 < N && X[i+1] == 0) i++;
                        while(l != i) jump[l] = i, l++;
                }
        }
}

int init(int N, int X[], int Y[]) {

        for(int i = 0; i < N; i++){
                jump[i] = -1;
                beg[i] = -1;
        }

        go();

        int idx = get_idx(l,r);

	return calc(idx);
}

int updateX(int pos, int val) {

        X[pos] = val;

        go();

        int idx = get_idx(0,N);

	return calc(idx);
}

int updateY(int pos, int val) {

        Y[pos] = val;

        int idx = get_idx(0,N);

	return calc(idx);
}

Compilation message (stderr)

horses.cpp: In function 'void go()':
horses.cpp:50:28: error: 'N' was not declared in this scope
         for(int i = 0; i < N; i++){
                            ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:63:17: error: 'beg' was not declared in this scope
                 beg[i] = -1;
                 ^~~
horses.cpp:72:13: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return calc(idx);
         ~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:81:29: error: 'N' was not declared in this scope
         int idx = get_idx(0,N);
                             ^
horses.cpp:83:13: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return calc(idx);
         ~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:90:29: error: 'N' was not declared in this scope
         int idx = get_idx(0,N);
                             ^
horses.cpp:92:13: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return calc(idx);
         ~~~~^~~~~
horses.cpp: In function 'll calc(int)':
horses.cpp:96:4: error: redefinition of 'll calc(int)'
 ll calc(int pos){
    ^~~~
horses.cpp:37:4: note: 'll calc(int)' previously defined here
 ll calc(int pos){
    ^~~~
horses.cpp:102:18: error: 'i' was not declared in this scope
         cnt *= Y[i];
                  ^
horses.cpp: In function 'void go()':
horses.cpp:107:6: error: redefinition of 'void go()'
 void go(){
      ^~
horses.cpp:48:6: note: 'void go()' previously defined here
 void go(){
      ^~
horses.cpp:109:28: error: 'N' was not declared in this scope
         for(int i = 0; i < N; i++){
                            ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:118:5: error: redefinition of 'int init(int, int*, int*)'
 int init(int N, int X[], int Y[]) {
     ^~~~
horses.cpp:59:5: note: 'int init(int, int*, int*)' previously defined here
 int init(int N, int x[], int y[]) {
     ^~~~
horses.cpp:118:33: warning: declaration of 'Y' shadows a global declaration [-Wshadow]
 int init(int N, int X[], int Y[]) {
                                 ^
horses.cpp:9:17: note: shadowed declaration is here
 int X[1000000], Y[1000000];
                 ^
horses.cpp:118:33: warning: declaration of 'X' shadows a global declaration [-Wshadow]
 int init(int N, int X[], int Y[]) {
                                 ^
horses.cpp:9:5: note: shadowed declaration is here
 int X[1000000], Y[1000000];
     ^
horses.cpp:122:17: error: 'beg' was not declared in this scope
                 beg[i] = -1;
                 ^~~
horses.cpp:127:27: error: 'l' was not declared in this scope
         int idx = get_idx(l,r);
                           ^
horses.cpp:127:29: error: 'r' was not declared in this scope
         int idx = get_idx(l,r);
                             ^
horses.cpp:129:13: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return calc(idx);
         ~~~~^~~~~
horses.cpp:118:23: warning: unused parameter 'X' [-Wunused-parameter]
 int init(int N, int X[], int Y[]) {
                       ^
horses.cpp:118:32: warning: unused parameter 'Y' [-Wunused-parameter]
 int init(int N, int X[], int Y[]) {
                                ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:132:5: error: redefinition of 'int updateX(int, int)'
 int updateX(int pos, int val) {
     ^~~~~~~
horses.cpp:75:5: note: 'int updateX(int, int)' previously defined here
 int updateX(int pos, int val) {
     ^~~~~~~
horses.cpp:138:29: error: 'N' was not declared in this scope
         int idx = get_idx(0,N);
                             ^
horses.cpp:140:13: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return calc(idx);
         ~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:143:5: error: redefinition of 'int updateY(int, int)'
 int updateY(int pos, int val) {
     ^~~~~~~
horses.cpp:86:5: note: 'int updateY(int, int)' previously defined here
 int updateY(int pos, int val) {
     ^~~~~~~
horses.cpp:147:29: error: 'N' was not declared in this scope
         int idx = get_idx(0,N);
                             ^
horses.cpp:149:13: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return calc(idx);
         ~~~~^~~~~