Submission #68831

#TimeUsernameProblemLanguageResultExecution timeMemory
68831chpipisWorst Reporter 3 (JOI18_worst_reporter3)C++11
100 / 100
1345 ms118624 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...