답안 #774883

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
774883 2023-07-06T04:54:05 Z Antonn_114 Worst Reporter 3 (JOI18_worst_reporter3) C++14
100 / 100
501 ms 13404 KB
#include <bits/stdc++.h>
using namespace std;

// Write down the limits of the problem here

int main() {
	// Try to avoid cin, cout :)

	int tc = 1; // scanf("%d", &tc);
	while(tc--) {
		/// Your solution here
	    int n, q;
        scanf("%d%d", &n, &q);
        vector<int> d(n + 1);
        for (int i = 1; i <= n ; i++) scanf("%d", &d[i]);
        vector<int> f(n + 1);
        f[0] = 1;
        d[0] = 1;
        for (int i = 1; i <= n; i++){
            f[i] = int(ceil(d[i]/double(f[i - 1])))*f[i - 1];
        }
	    while(q--){
            int t, l, r;
            scanf("%d%d%d", &t, &l, &r);
            int L = 0;
            int R = n;
            while(L <= R){
                int m = (L + R) >> 1;
                int T = (t/f[m])*f[m] - m;
                if (T < l) R = m - 1;
                else L = m + 1;
            }
            int firstpos = L;
            L = 0, R = n;
            while( L <= R){
                int m  = (L + R )>> 1;
                int T = (t/f[m])*f[m] - m;
                if (T > r) L = m + 1;
                else R = m - 1;
            }
            int lastpos = R;
            printf("%d\n", max(0, firstpos - lastpos - 1));
        }
    }
	return 0;
}

/*
 * Ermm don't underestimate Div2A, pls...
 * 
 * IMPORTANT:: If there isn't a clear-cut approach for your program, DO NOT CODE YET!
 * 
 * Analyze the time complexity and space complexity even if it *seems* efficient
 *
 * Write down some notes for more complicated problems
 * 
 * Also, please, CP isn't supposed to be complicated
 * 
**/

Compilation message

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         scanf("%d%d", &n, &q);
      |         ~~~~~^~~~~~~~~~~~~~~~
worst_reporter3.cpp:15:44: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         for (int i = 1; i <= n ; i++) scanf("%d", &d[i]);
      |                                       ~~~~~^~~~~~~~~~~~~
worst_reporter3.cpp:24:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |             scanf("%d%d%d", &t, &l, &r);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 471 ms 13404 KB Output is correct
2 Correct 486 ms 13256 KB Output is correct
3 Correct 475 ms 13232 KB Output is correct
4 Correct 501 ms 13304 KB Output is correct
5 Correct 471 ms 13352 KB Output is correct
6 Correct 469 ms 13272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 471 ms 13404 KB Output is correct
2 Correct 486 ms 13256 KB Output is correct
3 Correct 475 ms 13232 KB Output is correct
4 Correct 501 ms 13304 KB Output is correct
5 Correct 471 ms 13352 KB Output is correct
6 Correct 469 ms 13272 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 329 ms 11256 KB Output is correct
14 Correct 297 ms 7892 KB Output is correct
15 Correct 295 ms 11284 KB Output is correct
16 Correct 324 ms 11300 KB Output is correct
17 Correct 387 ms 6820 KB Output is correct
18 Correct 364 ms 6888 KB Output is correct
19 Correct 344 ms 6732 KB Output is correct
20 Correct 366 ms 6812 KB Output is correct
21 Correct 342 ms 6816 KB Output is correct
22 Correct 344 ms 6904 KB Output is correct
23 Correct 342 ms 6888 KB Output is correct
24 Correct 352 ms 6936 KB Output is correct
25 Correct 463 ms 13276 KB Output is correct
26 Correct 469 ms 13284 KB Output is correct
27 Correct 377 ms 7428 KB Output is correct
28 Correct 414 ms 7128 KB Output is correct
29 Correct 372 ms 7196 KB Output is correct
30 Correct 374 ms 7328 KB Output is correct
31 Correct 377 ms 7140 KB Output is correct
32 Correct 371 ms 12928 KB Output is correct
33 Correct 1 ms 212 KB Output is correct