Submission #296789

# Submission time Handle Problem Language Result Execution time Memory
296789 2020-09-10T21:32:56 Z Plurm Worst Reporter 3 (JOI18_worst_reporter3) C++11
100 / 100
521 ms 27544 KB
#include <bits/stdc++.h>
using namespace std;
int d[500005]; // Period
long long p[500005]; // Period
const long long INF = 1e18+7ll;
vector<int> pivots;
long long intersectSegment(long long l1, long long r1, long long l2, long long r2){
	auto l = max(l1, l2);
	auto r = min(r1, r2);
	if(l > r) return 0ll;
	else return r - l + 1;
}
int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	for(int i = 1; i <= n; i++){
		scanf("%d",d+i);
		if(i == 1) p[i] = d[i];
		else if(p[i-1] == INF) p[i] = INF;
		else p[i] = 1ll * (d[i] + p[i-1] - 1ll) / p[i-1] * p[i-1];
		if(p[i] > INF) p[i] = INF;
	}
	for(int i = 1; i <= n; i++){
		if(p[i] != p[i-1]) pivots.push_back(i);
	}
	// Assume |pivots| < 32 (provable but this margin is too small to contain)
	for(int i = 0; i < q; i++){
		int t, l, r;
		scanf("%d%d%d",&t,&l,&r);
		int ans = l <= t && t <= r ? 1 : 0;
		for(int j = 0; j < pivots.size(); j++){
			int cpv = pivots[j];
			int npv = j == pivots.size()-1 ? n : pivots[j+1]-1;
			long long bckt = 1ll * t / p[cpv] * p[cpv];
			ans += intersectSegment(bckt-r, bckt-l, cpv, npv);
		}
		printf("%d\n", ans);
	}
	return 0;
}

Compilation message

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:31:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(int j = 0; j < pivots.size(); j++){
      |                  ~~^~~~~~~~~~~~~~~
worst_reporter3.cpp:33:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |    int npv = j == pivots.size()-1 ? n : pivots[j+1]-1;
      |              ~~^~~~~~~~~~~~~~~~~~
worst_reporter3.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |  scanf("%d%d",&n,&q);
      |  ~~~~~^~~~~~~~~~~~~~
worst_reporter3.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |   scanf("%d",d+i);
      |   ~~~~~^~~~~~~~~~
worst_reporter3.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |   scanf("%d%d%d",&t,&l,&r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 386 ms 24824 KB Output is correct
2 Correct 388 ms 24696 KB Output is correct
3 Correct 387 ms 24696 KB Output is correct
4 Correct 405 ms 24696 KB Output is correct
5 Correct 410 ms 24728 KB Output is correct
6 Correct 393 ms 24948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 386 ms 24824 KB Output is correct
2 Correct 388 ms 24696 KB Output is correct
3 Correct 387 ms 24696 KB Output is correct
4 Correct 405 ms 24696 KB Output is correct
5 Correct 410 ms 24728 KB Output is correct
6 Correct 393 ms 24948 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 392 ms 23240 KB Output is correct
14 Correct 398 ms 23928 KB Output is correct
15 Correct 381 ms 22392 KB Output is correct
16 Correct 399 ms 23124 KB Output is correct
17 Correct 495 ms 27256 KB Output is correct
18 Correct 493 ms 27256 KB Output is correct
19 Correct 493 ms 27384 KB Output is correct
20 Correct 495 ms 27256 KB Output is correct
21 Correct 479 ms 27384 KB Output is correct
22 Correct 481 ms 27544 KB Output is correct
23 Correct 482 ms 27324 KB Output is correct
24 Correct 485 ms 27392 KB Output is correct
25 Correct 410 ms 24760 KB Output is correct
26 Correct 389 ms 24696 KB Output is correct
27 Correct 489 ms 26872 KB Output is correct
28 Correct 521 ms 27336 KB Output is correct
29 Correct 508 ms 26756 KB Output is correct
30 Correct 506 ms 26844 KB Output is correct
31 Correct 509 ms 27256 KB Output is correct
32 Correct 367 ms 23284 KB Output is correct
33 Correct 1 ms 384 KB Output is correct