Submission #579528

# Submission time Handle Problem Language Result Execution time Memory
579528 2022-06-19T10:20:27 Z JooDdae Horses (IOI15_horses) C++17
100 / 100
1491 ms 69844 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define mid ((l+r) >> 1)
 
const ll INF = 1e9+1;
const int mod = 1e9+7;
int n, x[500500], y[500500];
ll t1[2002002], t3[2002002];
array<int, 2> t2[2002002];
set<int> s;
 
ll build1(int node = 1, int l = 0, int r = n-1){
    if(l == r) return t1[node] = x[l];
    return t1[node] = min(INF, build1(node*2, l, mid) * build1(node*2+1, mid+1, r));
}
 
array<int, 2> build2(int node = 1, int l = 0, int r = n-1){
    if(l == r) return t2[node] = {y[l], l};
    return t2[node] = max(build2(node*2, l, mid), build2(node*2+1, mid+1, r));
}
 
ll build3(int node = 1, int l = 0, int r = n-1){
    if(l == r) return t3[node] = x[l];
    return t3[node] = build3(node*2, l, mid) * build3(node*2+1, mid+1, r) % mod;
}
 
void update1(int pos, int val, int node = 1, int l = 0, int r = n-1){
    if(pos < l || r < pos) return;
    if(l == r){
        t1[node] = val;
        return;
    }
    update1(pos, val, node*2, l, mid), update1(pos, val, node*2+1, mid+1, r);
    t1[node] = min(INF, t1[node*2] * t1[node*2+1]);
}
 
void update2(int pos, int val, int node = 1, int l = 0, int r = n-1){
    if(pos < l || r < pos) return;
    if(l == r){
        t2[node][0] = val;
        return;
    }
    update2(pos, val, node*2, l, mid), update2(pos, val, node*2+1, mid+1, r);
    t2[node] = max(t2[node*2], t2[node*2+1]);
}
 
void update3(int pos, int val, int node = 1, int l = 0, int r = n-1){
    if(pos < l || r < pos) return;
    if(l == r){
        t3[node] = val;
        return;
    }
    update3(pos, val, node*2, l, mid), update3(pos, val, node*2+1, mid+1, r);
    t3[node] = t3[node*2] * t3[node*2+1] % mod;
}
 
ll find1(int nl, int nr, int node = 1, int l = 0, int r = n-1){
    if(nr < l || r < nl) return 1;
    if(nl <= l && r <= nr) return t1[node];
    return min(INF, find1(nl, nr, node*2, l, mid) * find1(nl, nr, node*2+1, mid+1, r));
}
 
array<int, 2> find2(int nl, int nr, int node = 1, int l = 0, int r = n-1){
    if(nr < l || r < nl) return {0, 0};
    if(nl <= l && r <= nr) return t2[node];
    return max(find2(nl, nr, node*2, l, mid), find2(nl, nr, node*2+1, mid+1, r));
}
 
ll find3(int nl, int nr, int node = 1, int l = 0, int r = n-1){
    if(nr < l || r < nl) return 1;
    if(nl <= l && r <= nr) return t3[node];
    return find3(nl, nr, node*2, l, mid) * find3(nl, nr, node*2+1, mid+1, r) % mod;
}
 
int find_max(int l, int r){
    if(l == r) return r;
    ll k = 1ll * x[r] * y[r];
    auto mx = find2(l, r-1);
    return k > mx[0] ? r : mx[1];
}
 
int solve(){
    auto it = s.rbegin();
    int mx = find_max(*next(it)+1, *it);
 
    for(int i=0;i<30;i++){
        if(*++it < 0) break;
        int k = find_max(*next(it)+1, *it);
        if(y[k] > find1(k+1, mx) * y[mx]) mx = k;
    }
 
    return find3(0, mx) * y[mx] % mod;
}
 
int init(int N, int X[], int Y[]) {
    n = N;
    for(int i=0;i<N;i++) x[i] = X[i], y[i] = Y[i];
 
    s.insert(-1);
    for(int i=0;i<N;i++) if(x[i] > 1) s.insert(i);
    s.insert(N-1);
 
    build1(), build2(), build3();
 
    return solve();
}
 
int updateX(int pos, int val) { 
    if(pos < n-1 && x[pos] > 1) s.erase(pos);
    x[pos] = val, update1(pos, val), update3(pos, val);
    if(pos < n-1 && x[pos] > 1) s.insert(pos);
    return solve();
}
 
int updateY(int pos, int val) {
    y[pos] = val, update2(pos, val);
    return solve();
}

Compilation message

horses.cpp: In function 'int solve()':
horses.cpp:95:33: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   95 |     return find3(0, mx) * y[mx] % mod;
      |            ~~~~~~~~~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 312 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 8 ms 316 KB Output is correct
24 Correct 4 ms 320 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 4 ms 468 KB Output is correct
27 Correct 7 ms 340 KB Output is correct
28 Correct 9 ms 484 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 6 ms 468 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 7 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 683 ms 57540 KB Output is correct
2 Correct 810 ms 57636 KB Output is correct
3 Correct 795 ms 57424 KB Output is correct
4 Correct 909 ms 57588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 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 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 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 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 10 ms 444 KB Output is correct
24 Correct 7 ms 448 KB Output is correct
25 Correct 5 ms 452 KB Output is correct
26 Correct 4 ms 468 KB Output is correct
27 Correct 7 ms 340 KB Output is correct
28 Correct 6 ms 460 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 6 ms 468 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 6 ms 436 KB Output is correct
33 Correct 252 ms 33616 KB Output is correct
34 Correct 105 ms 36900 KB Output is correct
35 Correct 265 ms 67148 KB Output is correct
36 Correct 242 ms 67164 KB Output is correct
37 Correct 193 ms 35048 KB Output is correct
38 Correct 192 ms 47836 KB Output is correct
39 Correct 55 ms 34860 KB Output is correct
40 Correct 256 ms 62196 KB Output is correct
41 Correct 77 ms 34848 KB Output is correct
42 Correct 144 ms 34936 KB Output is correct
43 Correct 189 ms 62664 KB Output is correct
44 Correct 207 ms 62576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 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 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 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 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 9 ms 440 KB Output is correct
24 Correct 5 ms 444 KB Output is correct
25 Correct 5 ms 476 KB Output is correct
26 Correct 5 ms 468 KB Output is correct
27 Correct 18 ms 320 KB Output is correct
28 Correct 6 ms 476 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 6 ms 468 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 8 ms 340 KB Output is correct
33 Correct 663 ms 59524 KB Output is correct
34 Correct 810 ms 69844 KB Output is correct
35 Correct 745 ms 61112 KB Output is correct
36 Correct 874 ms 64908 KB Output is correct
37 Correct 231 ms 37028 KB Output is correct
38 Correct 106 ms 37004 KB Output is correct
39 Correct 275 ms 67172 KB Output is correct
40 Correct 226 ms 67192 KB Output is correct
41 Correct 211 ms 35076 KB Output is correct
42 Correct 196 ms 47844 KB Output is correct
43 Correct 58 ms 34828 KB Output is correct
44 Correct 247 ms 62340 KB Output is correct
45 Correct 69 ms 34892 KB Output is correct
46 Correct 148 ms 34900 KB Output is correct
47 Correct 178 ms 62720 KB Output is correct
48 Correct 175 ms 62636 KB Output is correct
49 Correct 1491 ms 40052 KB Output is correct
50 Correct 658 ms 39888 KB Output is correct
51 Correct 843 ms 69072 KB Output is correct
52 Correct 705 ms 68572 KB Output is correct
53 Correct 1461 ms 38328 KB Output is correct
54 Correct 981 ms 51704 KB Output is correct
55 Correct 279 ms 35844 KB Output is correct
56 Correct 1148 ms 64108 KB Output is correct
57 Correct 482 ms 36484 KB Output is correct
58 Correct 1000 ms 36944 KB Output is correct
59 Correct 204 ms 62680 KB Output is correct