Submission #839296

# Submission time Handle Problem Language Result Execution time Memory
839296 2023-08-29T15:27:59 Z Cookie Horses (IOI15_horses) C++14
100 / 100
591 ms 65456 KB
#include<bits/stdc++.h>
#include<fstream>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//ifstream fin("FEEDING.INP");
//ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#include "horses.h"
const ll mod = 1e9 + 7;
const int mxn = 5e5 + 5, mxr = 25e3, sq = 500, mxv = 200, mxvv = 130, pr = 31;
const ll inf = 1e9;
int n, m;
pii st[4 * mxn + 1];
ll prod[4 * mxn + 1], x[mxn + 1], y[mxn + 1];
set<int>special;
void updprod(int nd, int l, int r, int id, ll v){
    if(id < l || id > r)return;
    if(l == r){
        prod[nd] = v;
        return;
    }
    int mid = (l + r) >> 1;
    updprod(nd << 1, l, mid, id, v); updprod(nd << 1 | 1, mid + 1, r, id, v);
    prod[nd] = (prod[nd << 1] * prod[nd << 1 | 1]) % mod;
}
void upd(int nd, int l, int r, int id, int v){
    if(id < l || id > r)return;
    if(l == r){
        st[nd] = make_pair(v, id);
        return;
    }
    int mid = (l + r) >> 1;
    upd(nd << 1, l, mid, id, v); upd(nd << 1 | 1, mid + 1, r, id, v);
    st[nd] = max(st[nd << 1], st[nd << 1 | 1]);
}
ll getprod(int nd, int l, int r, int ql, int qr){
    if(ql > r || qr < l)return(1);
    if(ql <= l && qr >= r)return(prod[nd]);
    int mid = (l + r) >> 1;
    return((getprod(nd << 1, l, mid, ql, qr) * getprod(nd << 1 | 1, mid + 1, r, ql, qr)) % mod);
}
pii get(int nd, int l, int r, int ql, int qr){
    if(ql > r || qr < l)return(make_pair(-1, -1));
    if(ql <= l && qr >= r)return(st[nd]);
    int mid = (l + r) >> 1;
    return(max(get(nd << 1, l, mid, ql, qr), get(nd << 1 | 1, mid + 1, r, ql, qr)));
}
void updx(int pos, int val){
    if(x[pos] != 1)special.erase(pos);
    x[pos] = val;
    if(x[pos] != 1)special.insert(pos);
    updprod(1, 0, n - 1, pos, val);
}
void updy(int pos, int val){
    y[pos] = val;
    upd(1, 0, n - 1, pos, val);
}
int solve(){
    ll mul = 0, idbest = n - 1;
        for(int j = n - 1; j >= 0;){
            if(mul > inf)break;
            if(x[j] >= 2){
                if(y[j] > mul){
                    mul = y[j]; idbest = j;
                }
                mul = mul * x[j];
                j--;
            }else{
                auto it = special.lower_bound(j);
                int id = -1;
                if(it != special.begin()){
                    --it;
                    id = *it;
                }
                auto [mxy, idy] = get(1, 0, n - 1, id + 1, j);
                if(mxy > mul){
                    mul = mxy; idbest = idy;
                }
                
                j = id;
            }
            
            
        }
        
    return((getprod(1, 0, n - 1, 0, idbest) * y[idbest]) % mod);
}
int init(int N, int X[], int Y[]) {
    n = N;
    for(int i = 0; i < n; i++){
        x[i] = X[i];
        if(x[i] > 1){
            special.insert(i);
        }
        
        updprod(1, 0, n - 1, i, x[i]);
    }
    for(int i = 0; i < n; i++){
        y[i] = Y[i];
        upd(1, 0, n - 1, i, y[i]);
    }
    
    return(solve());
}
 
int updateX(int pos, int val) {	
    updx(pos, val);
	return(solve());
}
 
int updateY(int pos, int val) {
    updy(pos, val);
	return(solve());
}
 

Compilation message

horses.cpp: In function 'int solve()':
horses.cpp:87:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   87 |                 auto [mxy, idy] = get(1, 0, n - 1, id + 1, j);
      |                      ^
horses.cpp:98:37: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   98 |     return((getprod(1, 0, n - 1, 0, idbest) * y[idbest]) % mod);
      |                                     ^~~~~~
horses.cpp:98:58: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   98 |     return((getprod(1, 0, n - 1, 0, idbest) * y[idbest]) % mod);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:112:32: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  112 |         upd(1, 0, n - 1, i, y[i]);
      |                             ~~~^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 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 1 ms 340 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 1 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 1 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 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 328 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 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 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 340 KB Output is correct
12 Correct 0 ms 300 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 340 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 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 2 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 294 ms 52948 KB Output is correct
2 Correct 392 ms 65456 KB Output is correct
3 Correct 362 ms 56768 KB Output is correct
4 Correct 396 ms 60572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 296 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 1 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 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 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 4 ms 340 KB Output is correct
33 Correct 177 ms 32624 KB Output is correct
34 Correct 175 ms 32584 KB Output is correct
35 Correct 282 ms 62904 KB Output is correct
36 Correct 297 ms 62860 KB Output is correct
37 Correct 215 ms 30716 KB Output is correct
38 Correct 232 ms 43484 KB Output is correct
39 Correct 178 ms 30536 KB Output is correct
40 Correct 294 ms 57872 KB Output is correct
41 Correct 169 ms 30552 KB Output is correct
42 Correct 204 ms 30548 KB Output is correct
43 Correct 285 ms 58324 KB Output is correct
44 Correct 280 ms 58280 KB Output is correct
# 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 0 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 308 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 452 KB Output is correct
31 Correct 1 ms 324 KB Output is correct
32 Correct 3 ms 328 KB Output is correct
33 Correct 282 ms 56704 KB Output is correct
34 Correct 378 ms 65404 KB Output is correct
35 Correct 343 ms 56644 KB Output is correct
36 Correct 406 ms 60460 KB Output is correct
37 Correct 178 ms 32564 KB Output is correct
38 Correct 172 ms 32540 KB Output is correct
39 Correct 272 ms 62832 KB Output is correct
40 Correct 268 ms 62800 KB Output is correct
41 Correct 203 ms 30780 KB Output is correct
42 Correct 225 ms 43508 KB Output is correct
43 Correct 165 ms 30528 KB Output is correct
44 Correct 266 ms 57972 KB Output is correct
45 Correct 156 ms 30552 KB Output is correct
46 Correct 184 ms 30604 KB Output is correct
47 Correct 264 ms 58328 KB Output is correct
48 Correct 251 ms 58328 KB Output is correct
49 Correct 265 ms 35524 KB Output is correct
50 Correct 235 ms 35632 KB Output is correct
51 Correct 374 ms 64732 KB Output is correct
52 Correct 292 ms 64180 KB Output is correct
53 Correct 591 ms 33864 KB Output is correct
54 Correct 351 ms 47376 KB Output is correct
55 Correct 224 ms 31584 KB Output is correct
56 Correct 307 ms 59648 KB Output is correct
57 Correct 196 ms 32212 KB Output is correct
58 Correct 466 ms 32632 KB Output is correct
59 Correct 249 ms 58332 KB Output is correct