Submission #925177

# Submission time Handle Problem Language Result Execution time Memory
925177 2024-02-10T23:49:38 Z Karoot Horses (IOI15_horses) C++17
Compilation error
0 ms 0 KB
#include <iostream>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>

#define all(x)  (x).begin(), (x).end()
#define rall(x)  (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;

ll linf = 1e15+1;

inline void scoobydoobydoo(){
    ios::sync_with_stdio(false);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

const int M = 1e9+7;
const int MAXN = 5e5+1;

long double X[MAXN], Y[MAXN];

struct Node {   
    long double sum;
    long double maxi;
    ll index;
};

Node ST[4*MAXN];
int leftOf[4*MAXN], rightOf[4*MAXN];
int indexToNode[MAXN];

void buildTree(int l, int r, int node = 1){
    leftOf[node] = l; rightOf[node] = r;
    if (l == r){
        indexToNode[l] = node;
        ST[node].index = l;
        ST[node].maxi = log2(Y[l]);
        ST[node].sum = log2(X[l]);
        return;
    }
    int mid = (l+r)>>1;
    buildTree(l, mid, 2*node);
    buildTree(mid+1, r, 2*node+1);
    ST[node].sum = ST[2*node].sum + ST[2*node+1].sum;
    if (ST[2*node].maxi > ST[2*node+1].maxi+ST[2*node].sum){
        ST[node].index = ST[2*node].index;
        ST[node].maxi = ST[2*node].maxi;
    } else {
        ST[node].index = ST[2*node+1].index;
        ST[node].maxi = ST[2*node+1].maxi+ST[2*node].sum;
    }
    return;
}

long double query(){
    long double rest = ST[1].maxi - floor(ST[1].maxi);
    ll bigi = ST[1].maxi;
    ll soFar = 2;

    long double ans = 1;
    for (int i = 0; i <= log2(bigi)+1; i++){
        if (bigi&(1<<i)){
            ans = ((ll)ans*soFar)%M;
        }
        soFar *= soFar;
        soFar %= M;
    }

    ans *= pow(2.0, rest);
    return ((ll)round(ans))%M;
}

void update1(int node){
    if (!node)return;
    ST[node].sum = ST[2*node].sum + ST[2*node+1].sum;
    if (ST[2*node].maxi > ST[2*node+1].maxi+ST[2*node].sum){
        ST[node].index = ST[2*node].index;
        ST[node].maxi = ST[2*node].maxi;
    } else {
        ST[node].index = ST[2*node+1].index;
        ST[node].maxi = ST[2*node+1].maxi+ST[2*node].sum;
    }
    update1(node>>1);
}

int updateX(int pos, long double val){
    ST[indexToNode[pos]].sum = log2(val);
    update1(indexToNode[pos]>>1);
    return query();
}

int updateY(int pos, long double val){
    ST[indexToNode[pos]].maxi = log2(val);
    update1(indexToNode[pos]>>1);
    return query();
}

int init(int n, int x[], int y[]) {
	for(int i = 0; i < n; i++){
		X[i] = x[i];
        Y[i] = y[i];
	}
    buildTree(0, n-1);
	return query();
}

Compilation message

horses.cpp: In function 'long double query()':
horses.cpp:67:21: warning: conversion from 'long double' to 'll' {aka 'long long int'} may change value [-Wfloat-conversion]
   67 |     ll bigi = ST[1].maxi;
      |               ~~~~~~^~~~
horses.cpp: In function 'int updateX(int, long double)':
horses.cpp:99:17: warning: conversion from 'long double' to 'int' may change value [-Wfloat-conversion]
   99 |     return query();
      |            ~~~~~^~
horses.cpp: In function 'int updateY(int, long double)':
horses.cpp:105:17: warning: conversion from 'long double' to 'int' may change value [-Wfloat-conversion]
  105 |     return query();
      |            ~~~~~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:114:14: warning: conversion from 'long double' to 'int' may change value [-Wfloat-conversion]
  114 |  return query();
      |         ~~~~~^~
/usr/bin/ld: /tmp/ccox5tDk.o: in function `main':
grader.c:(.text.startup+0x113): undefined reference to `updateX(int, int)'
/usr/bin/ld: grader.c:(.text.startup+0x16d): undefined reference to `updateY(int, int)'
collect2: error: ld returned 1 exit status