답안 #727724

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
727724 2023-04-21T07:52:32 Z Vu_CG_Coder 말 (IOI15_horses) C++14
17 / 100
419 ms 80440 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 gt) {	
    pos++;
	if (w[pos] == gt) return calc();
    IT.update(1,1,n,pos,gt);
    if (w[pos] == 1) p.insert(pos);
    else if (gt == 1) p.erase(pos);
    w[pos] = gt;
    return calc();
}

int updateY(int pos, int gt) {
    pos++;
    Mx.update(1,1,n,pos,gt);
    val[pos] = gt;
	return calc();
}

// 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:173:31: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  173 |  if (w[pos] == gt) return calc();
      |                           ~~~~^~
horses.cpp:178:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  178 |     return calc();
      |            ~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:185:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  185 |  return calc();
      |         ~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 260 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 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 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 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 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 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 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 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 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 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Incorrect 1 ms 212 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 370 ms 67904 KB Output is correct
2 Incorrect 419 ms 80440 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Incorrect 1 ms 212 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 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 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Incorrect 1 ms 212 KB Output isn't correct
23 Halted 0 ms 0 KB -