답안 #242209

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242209 2020-06-27T05:41:03 Z dantoh000 Worst Reporter 3 (JOI18_worst_reporter3) C++14
100 / 100
705 ms 7544 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,q;
int d[500005];
int s[500005];
int POS(int id, int t){
    return (t/s[id])*s[id]-id;
}
int main(){
    scanf("%d%d",&n,&q);
    s[0] = 1;
    for (int i =1;  i <=n; i++) scanf("%d",&d[i]);
    for (int i =1;  i <=n; i++){
        int ct = (d[i]-1)/s[i-1]+1;
        //printf("after %d of prev jumps, %d jumps\n",ct,i);
        s[i] = s[i-1]*ct;
    }
    /*for (int i = 1; i <= n; i++){
        printf("%d: %d\n",i,s[i]);
    }*/
    for (int i = 1; i <= q; i++){
        int t,l,r;
        scanf("%d%d%d",&t,&l,&r);
        int Llo = 0, Lhi = n;
        int Rlo = 0, Rhi = n;
        while (Llo < Lhi){
            int mid = (Llo+Lhi+1)/2;
            if (POS(mid,t) < l){
                Lhi = mid-1;
            }
            else{
                Llo = mid;
            }
        }
        while (Rlo < Rhi){
            int mid = (Rlo+Rhi)/2;
            if (POS(mid,t) > r){
                Rlo = mid+1;
            }
            else{
                Rhi = mid;
            }
        }
        int ans = Llo-Rlo+1;
        if (Llo == 0 && Rlo == 0){
            int pos = POS(0,t);
            if (l <= pos && pos <= r) ans = 1;
            else ans = 0;
        }
        if (Llo == n && Rlo == n){
            int pos = POS(n,t);
            if (l <= pos && pos <= r) ans = 1;
            else ans = 0;
        }
        printf("%d\n",ans);
        //printf("<%d,%d> = %d\n",Llo, Rlo,ans);
    }

}

Compilation message

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&q);
     ~~~~~^~~~~~~~~~~~~~
worst_reporter3.cpp:13:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i =1;  i <=n; i++) scanf("%d",&d[i]);
                                 ~~~~~^~~~~~~~~~~~
worst_reporter3.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&t,&l,&r);
         ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 688 ms 7544 KB Output is correct
2 Correct 700 ms 7288 KB Output is correct
3 Correct 705 ms 7416 KB Output is correct
4 Correct 686 ms 7288 KB Output is correct
5 Correct 688 ms 7288 KB Output is correct
6 Correct 682 ms 7288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 688 ms 7544 KB Output is correct
2 Correct 700 ms 7288 KB Output is correct
3 Correct 705 ms 7416 KB Output is correct
4 Correct 686 ms 7288 KB Output is correct
5 Correct 688 ms 7288 KB Output is correct
6 Correct 682 ms 7288 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 478 ms 5240 KB Output is correct
14 Correct 486 ms 5240 KB Output is correct
15 Correct 468 ms 5240 KB Output is correct
16 Correct 474 ms 5368 KB Output is correct
17 Correct 564 ms 6648 KB Output is correct
18 Correct 569 ms 6652 KB Output is correct
19 Correct 564 ms 6652 KB Output is correct
20 Correct 574 ms 6648 KB Output is correct
21 Correct 566 ms 6648 KB Output is correct
22 Correct 571 ms 6784 KB Output is correct
23 Correct 568 ms 6776 KB Output is correct
24 Correct 564 ms 6776 KB Output is correct
25 Correct 686 ms 7288 KB Output is correct
26 Correct 687 ms 7288 KB Output is correct
27 Correct 611 ms 7292 KB Output is correct
28 Correct 595 ms 7160 KB Output is correct
29 Correct 595 ms 7288 KB Output is correct
30 Correct 622 ms 7160 KB Output is correct
31 Correct 619 ms 7032 KB Output is correct
32 Correct 560 ms 6904 KB Output is correct
33 Correct 5 ms 384 KB Output is correct