Submission #715616

# Submission time Handle Problem Language Result Execution time Memory
715616 2023-03-27T10:15:48 Z boris_mihov Horses (IOI15_horses) C++17
17 / 100
81 ms 71644 KB
#include "horses.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

typedef long long llong;
const int MAXN = 500000 + 10;
const int MOD = 1e9 + 7;

struct Node
{
    __int128 ans;
    llong prodX;
    bool isANSbig;
    bool isXbig;

    Node()
    {
        ans = -1;
    }

    inline friend Node operator + (Node left, Node right)
    {
        Node res;
        res.prodX = left.prodX * right.prodX;
        if (res.prodX >= MOD)
        {
            res.isXbig = true;
            res.prodX %= MOD;
        } else
        {
            res.isXbig = left.isXbig || right.isXbig;
        }
        
        if (left.isXbig || right.isANSbig || (left.ans < left.prodX * right.ans))
        {
            res.ans = left.prodX * right.ans;
            if (res.ans >= 1LL * MOD * MOD)
            {
                res.isANSbig = true;
                res.ans %= 1LL * MOD * MOD; 
            }
        } else
        {
            res.ans = left.ans;
            res.isANSbig = false;
        }

        return res;
    }
};

int n;
int x[MAXN];
int y[MAXN];
struct SegmentTree
{
    Node tree[4 * MAXN];
    void build(int l, int r, int node)
    {
        if (l == r)
        {
            tree[node].prodX = x[l];
            tree[node].isXbig = false;
            tree[node].isANSbig = false;
            tree[node].ans = 1LL * x[l] * y[l];
            return;
        }

        int mid = (l + r) / 2;
        build(l, mid, 2*node);
        build(mid + 1, r, 2*node + 1);
        tree[node] = tree[2*node] + tree[2*node + 1];
    }

    void update(int l, int r, int node, int queryIdx, int queryVal, bool which)
    {
        if (l == r)
        {
            if (which) tree[node].ans = queryVal;
            else tree[node].prodX = queryVal;
            return;
        }

        int mid = (l + r) / 2;
        if (queryIdx <= mid) update(l, mid, 2*node, queryIdx, queryVal, which);
        else update(mid + 1, r, 2*node + 1, queryVal, queryVal, which);
        tree[node] = tree[2*node] + tree[2*node + 1];
    }

    inline int getANS()
    {
        return tree[1].ans % MOD;
    }

    void build()
    {
        build(1, n, 1);
    }

    void update(int idx, int val, bool which)
    {
        update(1, n, 1, idx, val, which);
    }
};

SegmentTree tree;
int init(int N, int X[], int Y[]) 
{
    n = N;
    for (int i = 1 ; i <= n ; ++i)
    {
        x[i] = X[i - 1];
        y[i] = Y[i - 1];
    }

    tree.build();
	return tree.getANS();
}

int updateX(int pos, int val) 
{	
    pos++;
    tree.update(pos, val, false);
	return tree.getANS();
}

int updateY(int pos, int val) 
{
    pos++;
    tree.update(pos, val, true);
	return tree.getANS();
}

Compilation message

horses.cpp: In member function 'int SegmentTree::getANS()':
horses.cpp:94:28: warning: conversion from '__int128' to 'int' may change value [-Wconversion]
   94 |         return tree[1].ans % MOD;
      |                ~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 26 ms 62892 KB Output is correct
2 Correct 24 ms 62932 KB Output is correct
3 Correct 25 ms 62884 KB Output is correct
4 Correct 24 ms 62840 KB Output is correct
5 Correct 25 ms 62796 KB Output is correct
6 Correct 23 ms 62932 KB Output is correct
7 Correct 24 ms 62892 KB Output is correct
8 Correct 24 ms 62880 KB Output is correct
9 Correct 24 ms 62932 KB Output is correct
10 Correct 25 ms 62976 KB Output is correct
11 Correct 25 ms 62932 KB Output is correct
12 Correct 24 ms 62892 KB Output is correct
13 Correct 24 ms 62936 KB Output is correct
14 Correct 26 ms 62920 KB Output is correct
15 Correct 27 ms 62904 KB Output is correct
16 Correct 24 ms 62924 KB Output is correct
17 Correct 27 ms 62952 KB Output is correct
18 Correct 25 ms 62924 KB Output is correct
19 Correct 24 ms 62836 KB Output is correct
20 Correct 25 ms 62888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 62932 KB Output is correct
2 Correct 23 ms 62864 KB Output is correct
3 Correct 24 ms 62856 KB Output is correct
4 Correct 26 ms 62872 KB Output is correct
5 Correct 25 ms 62796 KB Output is correct
6 Correct 24 ms 62796 KB Output is correct
7 Correct 25 ms 62844 KB Output is correct
8 Correct 25 ms 62800 KB Output is correct
9 Correct 25 ms 62856 KB Output is correct
10 Correct 24 ms 62856 KB Output is correct
11 Correct 27 ms 62932 KB Output is correct
12 Correct 24 ms 62888 KB Output is correct
13 Correct 25 ms 62920 KB Output is correct
14 Correct 28 ms 62796 KB Output is correct
15 Correct 29 ms 62856 KB Output is correct
16 Correct 25 ms 62932 KB Output is correct
17 Correct 25 ms 62916 KB Output is correct
18 Correct 25 ms 62888 KB Output is correct
19 Correct 27 ms 62816 KB Output is correct
20 Correct 27 ms 62840 KB Output is correct
21 Incorrect 25 ms 62868 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 81 ms 71644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 62848 KB Output is correct
2 Correct 24 ms 62932 KB Output is correct
3 Correct 25 ms 62824 KB Output is correct
4 Correct 25 ms 62944 KB Output is correct
5 Correct 25 ms 62944 KB Output is correct
6 Correct 25 ms 62836 KB Output is correct
7 Correct 27 ms 62884 KB Output is correct
8 Correct 25 ms 62912 KB Output is correct
9 Correct 26 ms 62812 KB Output is correct
10 Correct 24 ms 62844 KB Output is correct
11 Correct 27 ms 62864 KB Output is correct
12 Correct 25 ms 62880 KB Output is correct
13 Correct 25 ms 62804 KB Output is correct
14 Correct 26 ms 62836 KB Output is correct
15 Correct 25 ms 62932 KB Output is correct
16 Correct 24 ms 62908 KB Output is correct
17 Correct 26 ms 62932 KB Output is correct
18 Correct 23 ms 62932 KB Output is correct
19 Correct 24 ms 62920 KB Output is correct
20 Correct 25 ms 62896 KB Output is correct
21 Incorrect 26 ms 62808 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 62868 KB Output is correct
2 Correct 26 ms 62896 KB Output is correct
3 Correct 24 ms 62888 KB Output is correct
4 Correct 24 ms 62892 KB Output is correct
5 Correct 25 ms 62912 KB Output is correct
6 Correct 30 ms 62864 KB Output is correct
7 Correct 24 ms 62932 KB Output is correct
8 Correct 26 ms 62932 KB Output is correct
9 Correct 27 ms 62948 KB Output is correct
10 Correct 26 ms 62888 KB Output is correct
11 Correct 25 ms 62816 KB Output is correct
12 Correct 26 ms 62856 KB Output is correct
13 Correct 25 ms 62920 KB Output is correct
14 Correct 29 ms 62924 KB Output is correct
15 Correct 26 ms 62840 KB Output is correct
16 Correct 26 ms 62824 KB Output is correct
17 Correct 30 ms 62796 KB Output is correct
18 Correct 26 ms 62836 KB Output is correct
19 Correct 30 ms 62900 KB Output is correct
20 Correct 28 ms 62796 KB Output is correct
21 Incorrect 26 ms 62932 KB Output isn't correct
22 Halted 0 ms 0 KB -