Submission #727721

# Submission time Handle Problem Language Result Execution time Memory
727721 2023-04-21T07:47:15 Z Vu_CG_Coder Horses (IOI15_horses) C++14
17 / 100
309 ms 70876 KB
/* [Author : Hoang Duy Vu] - THPT Chuyen Nguyen Du    */
//#pragma GCC optimize(" unroll-loops")
//#pragma gcc optimize("Ofast")
//#pragma GCC optimization("Ofast")
//#pragma optimize(Ofast)
#include "horses.h"
#include <bits/stdc++.h>
#define All(x) (x).begin(),(x).end()
#define ll long long
#define C make_pair
#define fi first
#define se second
#define two second.first
#define thr second.second
#define TASK "txt"
#define ld long double
using namespace std;
template<typename T> bool maximize(T &res, const T &val) {
    if (res < val) { res = val; return true; } return false; }
template<typename T> bool minimize(T &res, const T &val) {
    if (res > val) { res = val; return true; } return false; }

typedef pair<int,int> ii;
typedef pair<int,ii> iii;
const int LOG = 20;
const ll INF = 1e9;
const ll LNF = 1e18 + 7;
const ll mod = 1e9 + 7;
const int N = 5e5 + 100;

struct SegmentTree
{
    vector <ll> f;
    int n;

    SegmentTree(int _n = 0)
    {
        n = _n;
        f.assign(n*4,1);
    }

    void update(int i , int l , int r , int x , ll val)
    {
        if (l > x || r < x) return ;
        if (l == r) 
        {
            f[i] = val;
            return ;
        }

        int m = (l + r) >> 1;
        update(i*2,l,m,x,val);
        update(i*2+1,m+1,r,x,val);

        f[i] = (f[i*2]*f[i*2+1]) % mod;
    }

    ll get(int i , int l , int r , int c)
    {
        if (c < l) return 1;
        if (r <= c) return f[i];

        int m = (l + r) >> 1;

        return (get(i*2,l,m,c)*get(i*2+1,m+1,r,c)) % mod;
    }
};

struct SegmentTree2
{
    vector <ll> f;
    int n;

    SegmentTree2(int _n = 0)
    {
        n = _n;
        f.assign(n*4,0);
    }

    void update(int i , int l , int r , int x , ll val)
    {
        if (l > x || r < x) return ;
        if (l == r) 
        {
            f[i] = val;
            return ;
        }

        int m = (l + r) >> 1;
        update(i*2,l,m,x,val);
        update(i*2+1,m+1,r,x,val);

        f[i] = max(f[i*2],f[i*2+1]);
    }

    ll get(int i , int l , int r , int d , int c)
    {
        if (c < l || d > r || d > c) return 0;
        if (d <= l && r <= c) return f[i];

        int m = (l + r) >> 1;

        return max(get(i*2,l,m,d,c),get(i*2+1,m+1,r,d,c));
    }
};

SegmentTree2 Mx = 0;
SegmentTree IT = 0;
ll w[N] , val[N];
int n;
set <int> p;

ll calc() {

    auto l = p.end();
    l--;
    l--;
    auto r = l;
    r++;
    ll res = 0;

   // cout << (*l) << " " << (*r) << "\n";

    while (true)
    {
        int d = (*l) + 1;
        int c = (*r) - 1;

        if (d <= c)
        {
            ll gt = Mx.get(1,1,n,d,c);
            maximize(res,gt);
        }

        if (d == 1) break;

        maximize(res,val[(*l)]);
        res = res * w[(*l)];
        
        if (res >= 1e9) 
        {
            res = (res * IT.get(1,1,n,(*l) - 1)) % mod;
            return res;
        }
        l--;
        r--;
    }

    return res;
     
}

int init(int Nx, int X[], int Y[]) {
    n = Nx;

    p.insert(0);
    p.insert(n + 1);
    IT = n;
    Mx = n;
    for (int i = 1 ; i <= n ; i++)
    {
        w[i] = X[i - 1], val[i] = Y[i - 1];
        if (w[i] > 1) p.insert(i);
        IT.update(1,1,n,i,w[i]);
        Mx.update(1,1,n,i,val[i]);
    }

    return  calc();
}

int updateX(int pos, int val) {	
	return 0;
}

int updateY(int pos, int val) {
	return 0;
}

// int main()
// {
//     ios_base::sync_with_stdio(0);
//     cin.tie(NULL); cout.tie(NULL);
//     if(fopen(TASK".inp", "r")){
//     freopen(TASK".inp","r",stdin);
//     freopen(TASK".out","w",stdout);
//     }

//     int x[N] , y[N];
//     int t;

//     cin >> t;
//     for (int i = 0 ; i < t ; i++) cin >> x[i] >> y[i];

//     cout << init(t,x,y) << "\n";

//     int q;
//     cin >> q;
//     while (q--)
//     {
//         int id , g ,  h;
//         cin >> id >> g >> h;
//         if (id == 1) cout << updateX(g,h) << "\n";
//         else cout << updateY(g,h) << "\n";
//     }
    

//     return 0;
// }

Compilation message

horses.cpp: In function 'long long int calc()':
horses.cpp:140:13: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
  140 |         if (res >= 1e9)
      |             ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:168:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  168 |     return  calc();
      |             ~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:171:26: warning: declaration of 'val' shadows a global declaration [-Wshadow]
  171 | int updateX(int pos, int val) {
      |                      ~~~~^~~
horses.cpp:109:11: note: shadowed declaration is here
  109 | ll w[N] , val[N];
      |           ^~~
horses.cpp:171:17: warning: unused parameter 'pos' [-Wunused-parameter]
  171 | int updateX(int pos, int val) {
      |             ~~~~^~~
horses.cpp:171:26: warning: unused parameter 'val' [-Wunused-parameter]
  171 | int updateX(int pos, int val) {
      |                      ~~~~^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:175:26: warning: declaration of 'val' shadows a global declaration [-Wshadow]
  175 | int updateY(int pos, int val) {
      |                      ~~~~^~~
horses.cpp:109:11: note: shadowed declaration is here
  109 | ll w[N] , val[N];
      |           ^~~
horses.cpp:175:17: warning: unused parameter 'pos' [-Wunused-parameter]
  175 | int updateY(int pos, int val) {
      |             ~~~~^~~
horses.cpp:175:26: warning: unused parameter 'val' [-Wunused-parameter]
  175 | int updateY(int pos, int val) {
      |                      ~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 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 312 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 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 0 ms 308 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 312 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 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 312 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 0 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 0 ms 212 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 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 Incorrect 309 ms 70876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 312 KB Output is correct
2 Correct 1 ms 212 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 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 312 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 0 ms 212 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Incorrect 0 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 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 0 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 316 KB Output is correct
15 Correct 0 ms 308 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Incorrect 0 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -