Submission #83445

#TimeUsernameProblemLanguageResultExecution timeMemory
83445tincamateiWorst Reporter 3 (JOI18_worst_reporter3)C++14
100 / 100
1392 ms88868 KiB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 500000;
long long d[1+MAX_N];
long long per[1+MAX_N], jump[1+MAX_N];

long long poz(int i, int t) {
	return -i + t / per[i] * jump[i];
}

int binsrc(int n, int t, int val) {
	int st = -1, dr = n + 1;
	while(dr - st > 1) {
		int mid = (st + dr) / 2;
		if(poz(mid, t) <= val)
			dr = mid;
		else
			st = mid;
	}
	return dr;
}

int main() {
#ifdef HOME
	FILE *fin = fopen("input.in", "r");
	FILE *fout = fopen("output.out", "w");
#else
	FILE *fin = stdin;
	FILE *fout = stdout;
#endif

	int n, q, t, l, r;
	fscanf(fin, "%d%d", &n, &q);
	per[0] = jump[0] = 1;
	for(int i = 1; i <= n; ++i) {
		fscanf(fin, "%d", &d[i]);
		per[i] = (d[i] + jump[i - 1] - 1) / jump[i - 1];
		jump[i] = jump[i - 1] * per[i];
		per[i] = per[i - 1] * per[i];
	}

	for(int i = 0; i < q; ++i) {
		fscanf(fin, "%d%d%d", &t, &l, &r);
		int a = binsrc(n, t, r), b = binsrc(n, t, l - 1);
		fprintf(fout, "%d\n", b - a);
	}

#ifdef HOME
	fclose(fin);
	fclose(fout);
#endif
	return 0;
}

Compilation message (stderr)

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:38:26: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
   fscanf(fin, "%d", &d[i]);
                     ~~~~~^
worst_reporter3.cpp:35:8: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  fscanf(fin, "%d%d", &n, &q);
  ~~~~~~^~~~~~~~~~~~~~~~~~~~~
worst_reporter3.cpp:38:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   fscanf(fin, "%d", &d[i]);
   ~~~~~~^~~~~~~~~~~~~~~~~~
worst_reporter3.cpp:45:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   fscanf(fin, "%d%d%d", &t, &l, &r);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...