Submission #729559

# Submission time Handle Problem Language Result Execution time Memory
729559 2023-04-24T09:06:53 Z hoainiem Rice Hub (IOI11_ricehub) C++14
100 / 100
44 ms 4236 KB
#include <bits/stdc++.h>
#include "ricehub.h"
#define lc id<<1
#define rc id<<1^1
#define nmax 100008
using namespace std;
int n, mx, ans = 0, a[nmax];
long long k;
struct segtree{
    long long seg[nmax << 2];
    void build(int id = 1, int l = 1, int r = n){
        if (l == r){
            seg[id] = a[l];
            return;
        }
        int mid = (l + r) >> 1;
        build(lc, l, mid);
        build(rc, mid + 1, r);
        seg[id] = seg[lc] + seg[rc];
    }
    long long get(int u, int v, int id = 1, int l = 1, int r = n){
        if (r < u || l > v)
            return 0;
        if (u <= l && r <= v)
            return seg[id];
        int mid = (l + r) >> 1;
        return get(u, v, lc, l, mid) + get(u, v, rc, mid + 1, r);
    }
}tree;
long long cost(int l, int r){
    if (l == r)
        return 0;
    int mid = (l + r) >> 1;
    int xx = tree.get(l, mid);
    int yy = tree.get(mid + 1, r);
    return 1LL * a[mid] * (mid - l + 1) - tree.get(l, mid) + tree.get(mid + 1, r) - 1LL * a[mid] * (r - mid);
}
int besthub(int R, int L, int X[], long long B){
    n = R;
    mx = L;
    k = B;
    for (int i = 1; i <= n; i++)
        a[i] = X[i - 1];
    tree.build();
    for (int i = 1, j = 1; i <= n; i++){
        while (cost(j, i) > B)
            j++;
        ans = max(ans, i - j + 1);
    }
    return ans;
}

Compilation message

ricehub.cpp: In function 'long long int cost(int, int)':
ricehub.cpp:34:9: warning: unused variable 'xx' [-Wunused-variable]
   34 |     int xx = tree.get(l, mid);
      |         ^~
ricehub.cpp:35:9: warning: unused variable 'yy' [-Wunused-variable]
   35 |     int yy = tree.get(mid + 1, r);
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 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
# 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 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 1 ms 312 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 308 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 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 308 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 316 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 308 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 352 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 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 312 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 4 ms 468 KB Output is correct
22 Correct 3 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 3 ms 480 KB Output is correct
25 Correct 2 ms 448 KB Output is correct
26 Correct 2 ms 448 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 3 ms 488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1092 KB Output is correct
2 Correct 12 ms 1108 KB Output is correct
3 Correct 44 ms 4204 KB Output is correct
4 Correct 43 ms 4204 KB Output is correct
5 Correct 41 ms 2004 KB Output is correct
6 Correct 30 ms 2004 KB Output is correct
7 Correct 38 ms 3908 KB Output is correct
8 Correct 38 ms 3796 KB Output is correct
9 Correct 39 ms 2012 KB Output is correct
10 Correct 38 ms 2012 KB Output is correct
11 Correct 38 ms 4216 KB Output is correct
12 Correct 42 ms 4236 KB Output is correct
13 Correct 42 ms 2108 KB Output is correct
14 Correct 32 ms 2112 KB Output is correct
15 Correct 29 ms 3668 KB Output is correct
16 Correct 27 ms 3632 KB Output is correct
17 Correct 33 ms 3996 KB Output is correct
18 Correct 33 ms 3924 KB Output is correct
19 Correct 35 ms 4100 KB Output is correct
20 Correct 41 ms 4104 KB Output is correct