Submission #68831

# Submission time Handle Problem Language Result Execution time Memory
68831 2018-08-18T17:07:07 Z chpipis Worst Reporter 3 (JOI18_worst_reporter3) C++11
100 / 100
1345 ms 118624 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 1124 ms 18480 KB Output is correct
2 Correct 1123 ms 18556 KB Output is correct
3 Correct 1345 ms 18556 KB Output is correct
4 Correct 1183 ms 18684 KB Output is correct
5 Correct 1179 ms 18720 KB Output is correct
6 Correct 1196 ms 18720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 18720 KB Output is correct
2 Correct 3 ms 18720 KB Output is correct
3 Correct 3 ms 18720 KB Output is correct
4 Correct 3 ms 18720 KB Output is correct
5 Correct 3 ms 18720 KB Output is correct
6 Correct 4 ms 18720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1124 ms 18480 KB Output is correct
2 Correct 1123 ms 18556 KB Output is correct
3 Correct 1345 ms 18556 KB Output is correct
4 Correct 1183 ms 18684 KB Output is correct
5 Correct 1179 ms 18720 KB Output is correct
6 Correct 1196 ms 18720 KB Output is correct
7 Correct 3 ms 18720 KB Output is correct
8 Correct 3 ms 18720 KB Output is correct
9 Correct 3 ms 18720 KB Output is correct
10 Correct 3 ms 18720 KB Output is correct
11 Correct 3 ms 18720 KB Output is correct
12 Correct 4 ms 18720 KB Output is correct
13 Correct 751 ms 18720 KB Output is correct
14 Correct 759 ms 33136 KB Output is correct
15 Correct 734 ms 48384 KB Output is correct
16 Correct 660 ms 49008 KB Output is correct
17 Correct 911 ms 50460 KB Output is correct
18 Correct 940 ms 50460 KB Output is correct
19 Correct 916 ms 50460 KB Output is correct
20 Correct 882 ms 50460 KB Output is correct
21 Correct 976 ms 50460 KB Output is correct
22 Correct 914 ms 50488 KB Output is correct
23 Correct 938 ms 50488 KB Output is correct
24 Correct 880 ms 50488 KB Output is correct
25 Correct 1289 ms 50920 KB Output is correct
26 Correct 1223 ms 51020 KB Output is correct
27 Correct 990 ms 51020 KB Output is correct
28 Correct 1010 ms 51020 KB Output is correct
29 Correct 1088 ms 68488 KB Output is correct
30 Correct 960 ms 86476 KB Output is correct
31 Correct 1026 ms 104420 KB Output is correct
32 Correct 883 ms 118624 KB Output is correct
33 Correct 4 ms 118624 KB Output is correct