Submission #1267846

#TimeUsernameProblemLanguageResultExecution timeMemory
1267846SmuggingSpunWorst Reporter 3 (JOI18_worst_reporter3)C++20
100 / 100
362 ms13228 KiB
#include<bits/stdc++.h>
#define taskname "C"
using namespace std;
typedef long long ll;
const int lim = 5e5 + 5;
int n, q, d[lim];
pair<ll, ll>period[lim];
ll f(ll r, ll t){
  int low = 0, high = n, ans = n + 1;
  while(low <= high){
    int mid = (low + high) >> 1;
    if(-mid + (t / period[mid].first) * period[mid].second <= r){
      high = (ans = mid) - 1;
    }
    else{
      low = mid + 1;
    }
  }
  return ans;
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
  cin >> n >> q;
  for(int i = 1; i <= n; i++){
    cin >> d[i];
  }
  period[0] = make_pair(1, 1);
  for(int i = 1; i <= n; i++){
    period[i].first = 1LL * ((d[i] - 1) / period[i - 1].second + 1) * period[i - 1].second;
    period[i].second = 1LL * (period[i].first / period[i - 1].first) * period[i - 1].second;
  }
  for(int _ = 0; _ < q; _++){
    int t, l, r;
    cin >> t >> l >> r;
    cout << f(l - 1, t) - f(r, t) << "\n";
  }
}

Compilation message (stderr)

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:24:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...