제출 #47466

#제출 시각아이디문제언어결과실행 시간메모리
47466mirbek01Worst Reporter 3 (JOI18_worst_reporter3)C++17
100 / 100
1519 ms15500 KiB
# include <bits/stdc++.h>

using namespace std;

const int N = 5e5 + 2;

long long n, q, d[N], p[N], ti[N], inf = 2e9;

int main(){
      scanf("%lld %lld", &n, &q);

      int cn = 0;

      for(int i = 1; i <= n; i ++){
            scanf("%lld", &d[i]);
            if(d[i] == 1) cn ++;
      }

      for(int i = 1; i <= n; i ++){
            p[i] = -i;
      }

      ti[0] = 1;
      d[0] = 1;
      ti[1] = d[1];

      for(int i = 2; i <= n; i ++){
            int lo = 0, hi = 1e9;
            while(hi - lo > 1){
                  int md = (lo + hi) >> 1;
                  if((p[i - 1] + d[i - 1] * md - p[i]) > d[i])
                        hi = md;
                  else
                        lo = md;
            }
            if((p[i - 1] + d[i - 1] * lo - p[i]) > d[i]) hi = lo;
            d[i] = p[i - 1] + d[i - 1] * hi - 1 - p[i];
            ti[i] = min(hi * ti[i - 1], inf);
      }

      for(int i = 1; i <= q; i ++){
            int t, l, r;
            scanf("%d %d %d", &t, &l, &r);
            int L, R;
            int lo = 0, hi = n;
            while(hi - lo > 1){
                  int md = (lo + hi) >> 1;
                  if(t / ti[md] * d[md] + p[md] >= l)
                        lo = md;
                  else
                        hi = md;
            }

            if(t / ti[hi] * d[hi] + p[hi] >= l) lo = hi;
            if(t / ti[lo] * d[lo] + p[lo] < l) {
                  puts("0");
                  continue;
            }

            R = lo;

            lo = 0, hi = n;

            while(hi - lo > 1){
                  int md = (lo + hi) >> 1;
                  if(t / ti[md] * d[md] + p[md] <= r)
                        hi = md;
                  else
                        lo = md;
            }

            if(t / ti[lo] * d[lo] + p[lo] <= r) hi = lo;
            if(t / ti[hi] * d[hi] + p[hi] > r) {
                  puts("0");
                  continue;
            }

            L = hi;

            printf("%d\n", R - L + 1);
      }
}
/**
3 1
2
5
3
2 2 4
**/

컴파일 시 표준 에러 (stderr) 메시지

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:10:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%lld %lld", &n, &q);
       ~~~~~^~~~~~~~~~~~~~~~~~~~~
worst_reporter3.cpp:15:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld", &d[i]);
             ~~~~~^~~~~~~~~~~~~~~
worst_reporter3.cpp:43:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d %d", &t, &l, &r);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...