답안 #774926

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
774926 2023-07-06T05:54:25 Z SteGG Worst Reporter 3 (JOI18_worst_reporter3) C++17
100 / 100
1443 ms 24484 KB
#include <bits/stdc++.h>
#define int long long
 
using namespace std;
const int maxn = 5e5 + 5;
 
int n, q;
int f[maxn];
int d[maxn];
 
void open(){
    if(fopen("input.inp", "r")){
        freopen("input.inp", "r", stdin);
		
    }
}
 
signed main(){
    open();
    cin >> n >> q;
    for(int i = 1; i <= n; i++){
        cin >> d[i];
    }
 
    f[0] = 1;
    for(int i = 1; i <= n; i++){
        f[i] = ceil((double)(d[i]) / (double)(f[i - 1])) * f[i - 1];
    }
 
    auto get = [&](int pos, int t){
        return t / f[pos] * f[pos] - pos;
    };
 
    auto bin_sex = [&](int limit, int t){
        int s = 0, e = n;
        int ans = -1;
        while(s <= e){
            int mid = (s + e) >> 1;
            int pos = get(mid, t);
            // cout << t << " " << mid << " " << pos << endl;
            if(pos >= limit){
                s = mid + 1;
                ans = mid;
            }else{
                e = mid - 1;
            }
        }
        return ans + 1;
    };
 
    while(q--){
        int t, l, r;
        cin >> t >> l >> r;
        if(t <= l){
            cout << (t == l) << endl;
        }else{
            cout << bin_sex(l, t) - bin_sex(r + 1, t) << endl;
        }
    }
 
    return 0;
}

Compilation message

worst_reporter3.cpp: In function 'void open()':
worst_reporter3.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         freopen("input.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1257 ms 24300 KB Output is correct
2 Correct 1271 ms 24400 KB Output is correct
3 Correct 1274 ms 24480 KB Output is correct
4 Correct 1258 ms 24412 KB Output is correct
5 Correct 1249 ms 24484 KB Output is correct
6 Correct 1443 ms 24468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1257 ms 24300 KB Output is correct
2 Correct 1271 ms 24400 KB Output is correct
3 Correct 1274 ms 24480 KB Output is correct
4 Correct 1258 ms 24412 KB Output is correct
5 Correct 1249 ms 24484 KB Output is correct
6 Correct 1443 ms 24468 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1081 ms 22400 KB Output is correct
14 Correct 1098 ms 18904 KB Output is correct
15 Correct 1025 ms 22316 KB Output is correct
16 Correct 1073 ms 22580 KB Output is correct
17 Correct 1178 ms 11100 KB Output is correct
18 Correct 1190 ms 11120 KB Output is correct
19 Correct 1193 ms 10928 KB Output is correct
20 Correct 1184 ms 11236 KB Output is correct
21 Correct 1206 ms 10988 KB Output is correct
22 Correct 1187 ms 11004 KB Output is correct
23 Correct 1193 ms 11192 KB Output is correct
24 Correct 1186 ms 11032 KB Output is correct
25 Correct 1256 ms 24300 KB Output is correct
26 Correct 1248 ms 24480 KB Output is correct
27 Correct 1208 ms 11392 KB Output is correct
28 Correct 1194 ms 11424 KB Output is correct
29 Correct 1215 ms 11364 KB Output is correct
30 Correct 1200 ms 11580 KB Output is correct
31 Correct 1209 ms 11408 KB Output is correct
32 Correct 1131 ms 24040 KB Output is correct
33 Correct 1 ms 340 KB Output is correct