Submission #312647

# Submission time Handle Problem Language Result Execution time Memory
312647 2020-10-13T23:59:08 Z joseacaz Horses (IOI15_horses) C++17
17 / 100
172 ms 45560 KB
#include "horses.h"
#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pii>;
using vpl = vector<pll>;

struct Node
{
    double pre, tot;
    int x;
};

const ll MOD = 1e9 + 7;
const int MAXN = 5e5 + 5;
int N;
ll X[MAXN], Y[MAXN], ST2[MAXN];
double a[MAXN];
Node ST[4*MAXN];

Node operator +(const Node& _x, const Node& _y)
{
    Node tmp;
    tmp.pre = _x.pre;
    tmp.x = _x.x;
    tmp.tot = _x.tot + _y.tot;
    
    if(_x.tot + _y.pre > _x.pre)
    {
        tmp.pre = _x.tot + _y.pre;
        tmp.x = _y.x;
    }
    
    return tmp;
}

void build(int node = 0, int l = 0, int r = N - 1)
{
    if(l == r)
    {
        ST[node] = Node{a[l], a[l], l};
        return;
    }
    
    int mid = (l+r)/2, lchild = 2*node + 1, rchild = 2*node + 2;
    build(lchild, l, mid);
    build(rchild, mid + 1, r);
    ST[node] = ST[lchild] + ST[rchild];
}

void upd(int pos, double x, int node = 0, int l = 0, int r = N - 1)
{
    if(r < pos || pos < l)
        return;
    if(l == r)
    {
        a[l] = x;
        ST[node] = Node{x, x, l};
        return;
    }

    int mid = (l+r)/2, lchild = 2*node + 1, rchild = 2*node + 2;
    upd(pos, x, lchild, l, mid);
    upd(pos, x, rchild, mid + 1, r);
    ST[node] = ST[lchild] + ST[rchild];
}

void build2(int node = 0, int l = 0, int r = N - 1)
{
    if(l == r)
    {
        ST2[node] = X[l];
        return;
    }
    
    int mid = (l+r)/2, lchild = 2*node + 1, rchild = 2*node + 2;
    build2(lchild, l, mid);
    build2(rchild, mid + 1, r);
    ST2[node] = (ST2[lchild] * ST2[rchild]) % MOD;
}

void upd2(int pos, int val, int node = 0, int l = 0, int r = N - 1)
{
    if(r < pos || pos < l)
        return;
    if(l == r)
    {
        ST2[node] = val;
        return;
    }
    
    int mid = (l+r)/2, lchild = 2*node + 1, rchild = 2*node + 2;
    upd2(pos, val, lchild, l, mid);
    upd2(pos, val, rchild, mid + 1, r);
    ST2[node] = (ST2[lchild] * ST2[rchild]) % MOD;
}

ll qry(int pos, int node = 0, int l = 0, int r = N - 1)
{
    int mid = (l+r)/2, lchild = 2*node + 1, rchild = 2*node + 2;
    if(l == r)
        return ST2[node];
    if(mid < pos)
        return (ST2[lchild] * qry(pos, rchild, mid + 1, r)) % MOD;
    else
        return qry(pos, lchild, l, mid);
}

int init(int _N, int _X[], int _Y[])
{
    N = _N;
    for(int i = 0; i < N; i++)
    {
        X[i] = _X[i];
        Y[i] = _Y[i];
    }
    build2();

    a[0] = log2(X[0]) + log2(Y[0]);
    for(int i = 1; i < N; i++)
        a[i] = log2(X[i]) + log2(Y[i]) - log2(Y[i - 1]);
    build();
    
    int idx = ST[0].x;
    return (qry(idx) * Y[idx]) % MOD;
}

int updateX(int pos, int val)
{
    upd(pos, log2(val) - log2(X[pos]));
    X[pos] = val;
    upd2(pos, val);

	int idx = ST[0].x;
    return (qry(idx) * Y[idx]) % MOD;
}

int updateY(int pos, int val)
{
	upd(pos, log2(val) - log2(Y[pos]));
	upd(pos + 1, log2(Y[pos]) - log2(val));
    Y[pos] = val;
    upd2(pos, val);

	int idx = ST[0].x;
    return (qry(idx) * Y[idx]) % MOD;
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:132:32: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  132 |     return (qry(idx) * Y[idx]) % MOD;
      |            ~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:142:32: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  142 |     return (qry(idx) * Y[idx]) % MOD;
      |            ~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:153:32: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  153 |     return (qry(idx) * Y[idx]) % MOD;
      |            ~~~~~~~~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Incorrect 0 ms 384 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 172 ms 45560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 416 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Incorrect 0 ms 384 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Incorrect 1 ms 384 KB Output isn't correct
22 Halted 0 ms 0 KB -