Submission #110140

#TimeUsernameProblemLanguageResultExecution timeMemory
110140IOrtroiiiWorst Reporter 3 (JOI18_worst_reporter3)C++14
100 / 100
687 ms27504 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 500500;

int d[N];
long long a[N];

int main() {
   int n, q; scanf("%d %d", &n, &q);
   a[0] = 1;
   for (int i = 1; i <= n; ++i) {
      scanf("%d", d + i);
      a[i] = (a[i - 1] - 1 + d[i]) / a[i - 1] * a[i - 1];
   }
   int l = 0;
   vector< pair<int, int> > segs;
   while (l <= n) {
      int r = l;
      while (r < n && a[l] == a[r + 1]) r++;
      segs.push_back({l, r});
      l = r + 1;
   }

   while (q--) {
      int t, l, r; scanf("%d %d %d", &t, &l, &r);
      int ans = 0;
      for (auto p : segs) {
         int l0 = p.second, r0 = p.first;
         int nw = t / a[l0] * a[l0];
         l0 = max(-l0, l - nw), r0 = min(-r0, r - nw);
         ans += max(0, r0 - l0 + 1);
      }
      printf("%d\n", ans);
   }
}

Compilation message (stderr)

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:11:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int n, q; scanf("%d %d", &n, &q);
              ~~~~~^~~~~~~~~~~~~~~~~
worst_reporter3.cpp:14:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", d + i);
       ~~~~~^~~~~~~~~~~~~
worst_reporter3.cpp:27:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       int t, l, r; 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...