Submission #62919

#TimeUsernameProblemLanguageResultExecution timeMemory
62919kingpig9Worst Reporter 3 (JOI18_worst_reporter3)C++11
100 / 100
1458 ms13728 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5e5 + 10;
const ll INF = 2e9;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define fillchar(a, s) memset((a), (s), sizeof(a))

int N, Q;
ll P[MAXN];

int moo (ll t, ll x) {
	int lo = 0, hi = N + 2;	//how many are >= x?
	while (hi - lo > 1) {
		int mid = (lo + hi) / 2;
		if (P[mid - 1] * (t / P[mid - 1]) - (mid - 1) >= x) {
			lo = mid;
		} else {
			hi = mid;
		}
	}
	return lo;
}

int main() {
	scanf("%d %d", &N, &Q);
	P[0] = 1;
	for (int i = 1; i <= N; i++) {
		ll d;
		scanf("%lld", &d);
		P[i] = ((d + P[i - 1] - 1) / P[i - 1]) * P[i - 1];
	}

	for (int qi = 0; qi < Q; qi++) {
		ll t, lt, rt;
		scanf("%lld %lld %lld", &t, &lt, &rt);
		printf("%d\n", moo(t, lt) - moo(t, rt + 1));
	}
}

Compilation message (stderr)

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:34:7: 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:38:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &d);
   ~~~~~^~~~~~~~~~~~
worst_reporter3.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld %lld", &t, &lt, &rt);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...