Submission #68829

# Submission time Handle Problem Language Result Execution time Memory
68829 2018-08-18T17:06:02 Z chpipis Worst Reporter 3 (JOI18_worst_reporter3) C++11
19 / 100
1314 ms 263168 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rep(i, s, e) for (int i = s; i < e; i++)

// START for segment tree
#define params int p, int L, int R
#define housekeep int mid = (L + R) >> 1, left = p << 1, right = left | 1
// END

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif

#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
    advance(it, -n);
    return it;
}

template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
    advance(it, n);
    return it;
}
#endif

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ldouble;

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

template<typename T>
inline T sq(T a) { return a * a; }

//#ifdef LOCAL_MACHINE
//#endif

const int MAXN = 5e5 + 5;
const int MAX_STEP = 1e9 + 200;

int d[MAXN], n;
ll step[MAXN];

int getcnt(int t, int idx) {
    int lo = 0, hi = n;
    int res = -1;
    while (lo <= hi) {
        int mid = (lo + hi) >> 1;
        int pos = (t / step[mid]) * step[mid] - mid;
        if (pos <= idx) {
            res = mid;
            hi = mid - 1;
        } else {
            lo = mid + 1;
        }
    }
    if (res == -1)
        return 0;
    return n - res + 1;
}

int main() {
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    int q;
    scanf("%d %d", &n, &q);
    for (int i = 1; i <= n; i++)
        scanf("%d", &d[i]);
    step[0] = 1;
    step[1] = d[1];
    for (int i = 2; i <= n; i++) {
        int lo = 1, hi = MAX_STEP;
        while (lo < hi) {
            int mid = (lo + hi) >> 1;
            if (mid * step[i - 1] - (i - 1) + i > ( ll )d[i])
                hi = mid;
            else
                lo = mid + 1;
        }
        step[i] = hi * step[i - 1];
    }
    while (q--) {
        int t, l, r;
        scanf("%d %d %d", &t, &l, &r);
        printf("%d\n", getcnt(t, r) - getcnt(t, l - 1));
    }
    return 0;
}



Compilation message

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:85:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~~
worst_reporter3.cpp:87:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &d[i]);
         ~~~~~^~~~~~~~~~~~~
worst_reporter3.cpp:103:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &t, &l, &r);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1314 ms 9364 KB Output is correct
2 Correct 1223 ms 9364 KB Output is correct
3 Correct 1306 ms 9468 KB Output is correct
4 Correct 1150 ms 9536 KB Output is correct
5 Correct 1092 ms 9536 KB Output is correct
6 Correct 1118 ms 9536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9536 KB Output is correct
2 Correct 4 ms 9536 KB Output is correct
3 Correct 4 ms 9536 KB Output is correct
4 Correct 5 ms 9536 KB Output is correct
5 Correct 4 ms 9536 KB Output is correct
6 Correct 3 ms 9536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1314 ms 9364 KB Output is correct
2 Correct 1223 ms 9364 KB Output is correct
3 Correct 1306 ms 9468 KB Output is correct
4 Correct 1150 ms 9536 KB Output is correct
5 Correct 1092 ms 9536 KB Output is correct
6 Correct 1118 ms 9536 KB Output is correct
7 Correct 4 ms 9536 KB Output is correct
8 Correct 4 ms 9536 KB Output is correct
9 Correct 4 ms 9536 KB Output is correct
10 Correct 5 ms 9536 KB Output is correct
11 Correct 4 ms 9536 KB Output is correct
12 Correct 3 ms 9536 KB Output is correct
13 Correct 679 ms 9536 KB Output is correct
14 Correct 817 ms 24072 KB Output is correct
15 Correct 780 ms 39376 KB Output is correct
16 Correct 798 ms 55124 KB Output is correct
17 Correct 960 ms 75060 KB Output is correct
18 Correct 912 ms 93724 KB Output is correct
19 Correct 938 ms 112372 KB Output is correct
20 Correct 949 ms 131136 KB Output is correct
21 Correct 999 ms 149772 KB Output is correct
22 Correct 965 ms 168556 KB Output is correct
23 Correct 967 ms 187196 KB Output is correct
24 Correct 895 ms 205868 KB Output is correct
25 Correct 1211 ms 221760 KB Output is correct
26 Correct 1241 ms 237304 KB Output is correct
27 Correct 1020 ms 254240 KB Output is correct
28 Runtime error 1065 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
29 Halted 0 ms 0 KB -