Submission #560524

# Submission time Handle Problem Language Result Execution time Memory
560524 2022-05-11T15:45:11 Z Sergio_2357 Horses (IOI15_horses) C++17
17 / 100
181 ms 70524 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;

const long long mod = 1e9 + 7;

struct range {
public:
    long long m, mbh, x, y;
    range()
    {
        m = 1;
        mbh = 0;
    }
    range(int x_, int y_)
    {
        x = x_;
        y = y_;
        m = x;
        mbh = (x * y) % mod;
    }
    range operator+(range b)
    {
        range res;
        res.m = m * b.m;
        res.m %= mod;
        res.mbh = max(mbh, m * b.mbh);
        res.mbh %= mod;
        return res;
    }
};

template <class T>
struct SegTree {
    int n;
    vector<T> v;
    void rupdate(int i, int l, int r, int idx, T val)
    {
        if (r - l == 1) {
            if (l == idx)
                v[i] = val;
        } else {
            int m = (r - l) / 2 + l;
            if (idx < m)
                rupdate(2 * i, l, m, idx, val);
            else
                rupdate(2 * i + 1, m, r, idx, val);
            v[i] = v[2 * i] + v[2 * i + 1];
        }
    }
    void update(int idx, T val)
    {
        rupdate(1, 0, n, idx, val);
    }
    T query()
    {
        return v[1];
    }
    SegTree() { }
    SegTree(vector<T> in)
    {
        n = 1;
        while (n < in.size())
            n *= 2;
        v = vector<T>(2 * n + 5);
        for (int i = 0; i < in.size(); i++)
            update(i, in[i]);
    }
};

SegTree<range> st;
vector<range> vr;

int init(int N, int X[], int Y[])
{
    vr = vector<range>(N);
    for (int i = 0; i < N; i++) {
        vr[i] = range(X[i], Y[i]);
    }
    //cout << N << endl;
    st = SegTree<range>(vr);
    return st.query().mbh;
}

int updateX(int pos, int val)
{
    vr[pos] = range(val, vr[pos].y);
    st.update(pos, vr[pos]);
    return st.query().mbh;
}

int updateY(int pos, int val)
{
    vr[pos] = range(vr[pos].x, val);
    st.update(pos, vr[pos]);
    return st.query().mbh;
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:82:23: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   82 |     return st.query().mbh;
      |            ~~~~~~~~~~~^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:87:34: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   87 |     vr[pos] = range(val, vr[pos].y);
horses.cpp:89:23: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   89 |     return st.query().mbh;
      |            ~~~~~~~~~~~^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:94:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   94 |     vr[pos] = range(vr[pos].x, val);
horses.cpp:96:23: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   96 |     return st.query().mbh;
      |            ~~~~~~~~~~~^~~
horses.cpp: In instantiation of 'SegTree<T>::SegTree(std::vector<_Tp>) [with T = range]':
horses.cpp:81:27:   required from here
horses.cpp:63:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<range, std::allocator<range> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         while (n < in.size())
      |                ~~^~~~~~~~~~~
horses.cpp:66:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<range, std::allocator<range> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for (int i = 0; i < in.size(); i++)
      |                         ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 284 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 296 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Incorrect 1 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 181 ms 70524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 304 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Incorrect 1 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Incorrect 1 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -