Submission #1261146

#TimeUsernameProblemLanguageResultExecution timeMemory
1261146minggaWorst Reporter 3 (JOI18_worst_reporter3)C++20
100 / 100
299 ms7516 KiB
// Author: caption_mingle
#include "bits/stdc++.h"

using namespace std;

#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 5e5 + 7;
int n, q, a[N];

int calc(int t, int x) {
	if(t <= x) return n + 1;
	int l = 1, r = n, ans = n + 1;
	while(l <= r) {
		int m = (l + r) >> 1;
		int pos = (t / a[m]) * a[m] - m;
		if(pos <= x) {
			ans = m;
			r = m - 1;
		} else l = m + 1;
	}
	return n - ans + 1;
}

signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	#define task ""
	if(fopen(task ".INP", "r")) {
		freopen(task ".INP", "r", stdin);
		freopen(task ".OUT", "w", stdout);
	}
	cin >> n >> q;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		if(i > 1) {
			a[i] = ((a[i] + a[i - 1] - 1) / a[i - 1]) * a[i - 1];
		}
	}
	for(int i = 1; i <= q; i++) {
		int l, r, t; cin >> t >> l >> r;
		cout << calc(t, r) - calc(t, l - 1) << ln;
	}
    cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}

Compilation message (stderr)

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:36:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |                 freopen(task ".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
worst_reporter3.cpp:37:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |                 freopen(task ".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...